manim icon indicating copy to clipboard operation
manim copied to clipboard

Error in Cosine Function Graph

Open mra31693 opened this issue 3 years ago • 3 comments

I am trying to create a cosine graph using Manim but it was different from the actual graph. How should I edit my code to make it the actual graph. Thanks in advance. Code:

from manim import *
from numpy import cos

class CreateGraph(GraphScene):
    def __init__(self, **kwargs):
        GraphScene.__init__(
            self,
            x_min=-5,
            x_max=5,
            y_min=-5,
            y_max=5,
            graph_origin=ORIGIN,
            axes_color=GREEN)


    def construct(self):
        # Create Graph
        self.setup_axes(animate=True)
        f1 = self.get_graph(lambda x: cos(1/x) , x_min=-4, x_max=4)
        
        # Construct the Figures
        self.play(ShowCreation(f1))
        self.wait(1)

Error: cos cos2

Environment

OS System: Windows 10 manim version: master <V.6 Community Version> python version: .3.7.0

mra31693 avatar May 22 '21 15:05 mra31693

Setting the t_range parameter to np.array([0, 1, 0.0001]) and discontinuities to [0] fixed it for me. Rendering time was increased a bit though. As you make the step size in t_range smaller and smaller, the graph will become more accurate, but rendering time will increase.

f1 = self.get_graph(lambda x: np.cos(1/x) , x_min=-4, x_max=4, t_range = np.array([0, 1, 0.0001]), discontinuities=[0]) Hope this helps! :D

image

JeroSQ avatar May 29 '21 21:05 JeroSQ

I believe proper graphing software intelligently uses different step sizes for different parts of the graph. Unfortunately, we still use a fairly naive plotting method.

Darylgolden avatar Jun 03 '21 00:06 Darylgolden

I believe this should be open until we can intelligently graph functions like these.

Darylgolden avatar Jun 19 '21 00:06 Darylgolden