Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't graph trigonometric function of secx, cscx, cotx, tanx,... #694

Closed
barakasamsara opened this issue Aug 19, 2019 · 9 comments
Closed

Comments

@barakasamsara
Copy link

source code:

class PlotFunctions(GraphScene):
CONFIG = {
"x_min" : -10,
"x_max" : 10.3,
"y_min" : -1.5,
"y_max" : 1.5,
"graph_origin" : ORIGIN ,
"function_color" : RED ,
"axes_color" : GREEN,
"x_labeled_nums" :range(-10,12,2),

}
def construct(self):
    self.setup_axes(animate=True)
    func_graph=self.get_graph(self.func_to_graph,self.function_color)
    func_graph2=self.get_graph(self.func_to_graph2)
    vert_line = self.get_vertical_line_to_graph(TAU,func_graph,color=YELLOW)
    graph_lab = self.get_graph_label(func_graph, label = "\\cos(x)")
    graph_lab2=self.get_graph_label(func_graph2,label = "\\sin(x)", x_val=-10, direction=UP/2)
    two_pi = TexMobject("x = 2 \\pi")
    label_coord = self.input_to_graph_point(TAU,func_graph)
    two_pi.next_to(label_coord,RIGHT+UP)



    self.play(ShowCreation(func_graph),ShowCreation(func_graph2))
    self.play(ShowCreation(vert_line), ShowCreation(graph_lab), ShowCreation(graph_lab2),ShowCreation(two_pi))


def func_to_graph(self,x):
    #return np.cos(x)
    return np.tan(x)

def func_to_graph2(self,x):
    return np.sin(x)

I replaced "return np.cos(x)" to "return np.tan(x)"...i got this:
image

and then I replaced "return np.cos(x)" to "return np.sec(x)/cot(x)/csc(x)"...i got this:
AttributeError: module 'numpy' has no attribute 'sec'...

@zavden
Copy link
Contributor

zavden commented Aug 19, 2019

Those functions are discontinuous, you must break them into pieces to make them work, like this. Also you can import the math package of python instead numpy.

@barakasamsara
Copy link
Author

Those functions are discontinuous, you must break them into pieces to make them work, like this. Also you can import the math package of python instead numpy.

Thanks very much, but it didn't work...
i got this:
image

source code:
image

and how to import the math package of python instead numpy....
does it means i need uninstall numpy package and install the math package of python ...
or i just need to use the code:from math import ***??....

and

@zavden
Copy link
Contributor

zavden commented Aug 20, 2019

This is not a programming problem, the problem is that you do not know about trig functions. The tangent function is discontinuous in PI/2 + n*PI, so you should break it to pieces at those intervals.

No, you don't need to uninstall numpy, you just have to import math as a module.

If you want to use manim you need to have basic programming knowledge in python, so read the documentation if you don't know what you are doing.

This is one way to do it:

class TanGraph(GraphScene):
    CONFIG = {
        "y_max" : 10,
        "y_min" : -10,
        "x_max" : 5,
        "x_min" : -5,
        "graph_origin" : ORIGIN,
    }
    def construct(self):
        self.setup_axes()
        tan_function = lambda x: np.tan(x)
        tan_graph = VGroup()
        approx_factor = 0.934
        for n in range(-1,2):
            graph = self.get_graph(tan_function, 
                                    color = RED,
                                    x_min = (-PI/2)*approx_factor+n*PI,
                                    x_max = (PI/2)*approx_factor+n*PI
                                    )
            tan_graph.add(graph)
        
        self.play(
            ShowCreation(tan_graph),
        )
        self.wait()

Result:
TanGraph

@barakasamsara
Copy link
Author

barakasamsara commented Aug 20, 2019

This is not a programming problem, the problem is that you do not know about trig functions. The tangent function is discontinuous in PI/2 + n*PI, so you should break it to pieces at those intervals.

No, you don't need to uninstall numpy, you just have to import math as a module.

If you want to use manim you need to have basic programming knowledge in python, so read the documentation if you don't know what you are doing.

This is one way to do it:

class TanGraph(GraphScene):
    CONFIG = {
        "y_max" : 10,
        "y_min" : -10,
        "x_max" : 5,
        "x_min" : -5,
        "graph_origin" : ORIGIN,
    }
    def construct(self):
        self.setup_axes()
        tan_function = lambda x: np.tan(x)
        tan_graph = VGroup()
        approx_factor = 0.934
        for n in range(-1,2):
            graph = self.get_graph(tan_function, 
                                    color = RED,
                                    x_min = (-PI/2)*approx_factor+n*PI,
                                    x_max = (PI/2)*approx_factor+n*PI
                                    )
            tan_graph.add(graph)
        
        self.play(
            ShowCreation(tan_graph),
        )
        self.wait()

Result:
TanGraph

Thanks a loooooooot!!! now i can graph function of tanx , but i still can't graph the function of cotx...
image

image

neither the secx nor cscx.....

@Elteoremadebeethoven
Copy link
Contributor

Elteoremadebeethoven commented Aug 20, 2019

cot(x) = 1/tan(x)

@barakasamsara
Copy link
Author

cot(x) = 1/tan(x)

thanks a looooooot.... i think i just made a really stupid question....😂

@barakasamsara
Copy link
Author

cot(x) = 1/tan(x)

btw, if i want to replace the axis number label from "1,2,3,···"to "pi/2, pi,...." what should i do...
such as ,
from:
image

to:
image

@Elteoremadebeethoven
Copy link
Contributor

See my 2D graph tutorial in GitHub

@barakasamsara
Copy link
Author

See my 2D graph tutorial in GitHub

thanks ....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants