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:

And Manim gave me this one:

(I know the scales are different the main focus is the hump at the top)

Asked By: Rohan

||

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)
Answered By: Amit Kumar

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.

Answered By: Benjamin Hackl
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.