Why is ManimCE plotting a different graph than the one provided?
Question:
I’m trying to create a graph for the function (1+1/x)^x.
I wrote it in python like this:
def func(x):
return pow(1+(1/x),x)
I then plotted it like this:
graph = axes.plot(lambda x: func(x), color=BLUE, stroke_width=2, x_range=[0,X_MAX])
(X_MAX is a variable that equals 1000)
but for some reason Manim is plotting something else.
When I plotted the function in Desmos I got this graph:
(I know the scales are different the main focus is the hump at the top)
Answers:
you need to use small values of dt.
class drawgraph(Scene):
def construct(self):
axes= Axes()
def func(x):
return pow(1+(1/x),x)
graph = axes.plot(lambda x: func(x),dt = 0.001, color=BLUE, stroke_width=2, x_range=[0,5])
self.add(axes, graph)
It is the default smoothing that causes these weird oscillations; basically this happens because the function changes too fast in a (relatively) small interval.
Try either passing use_smoothing=False
to your call of plot
— and/or alternatively, try refining the step size by passing a third number to the x_range
list.
I’m trying to create a graph for the function (1+1/x)^x.
I wrote it in python like this:
def func(x):
return pow(1+(1/x),x)
I then plotted it like this:
graph = axes.plot(lambda x: func(x), color=BLUE, stroke_width=2, x_range=[0,X_MAX])
(X_MAX is a variable that equals 1000)
but for some reason Manim is plotting something else.
When I plotted the function in Desmos I got this graph:
(I know the scales are different the main focus is the hump at the top)
you need to use small values of dt.
class drawgraph(Scene):
def construct(self):
axes= Axes()
def func(x):
return pow(1+(1/x),x)
graph = axes.plot(lambda x: func(x),dt = 0.001, color=BLUE, stroke_width=2, x_range=[0,5])
self.add(axes, graph)
It is the default smoothing that causes these weird oscillations; basically this happens because the function changes too fast in a (relatively) small interval.
Try either passing use_smoothing=False
to your call of plot
— and/or alternatively, try refining the step size by passing a third number to the x_range
list.