Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is my function plotting incorrectly when using sympy.plotting.plot?

I am using sympy.plotting.plot to plot my function but, it shows me a different graph then when I plot the same function in my graphic calculator.

My code is:

def S(t):
    return (10*sympy.E**(t/12)*((sympy.sin((sympy.pi*t)/24))**2))
sympy.plotting.plot(S(t), xlim=[0,24])

Also, when I just do this,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

sympy.plotting.plot(10*sympy.E**(t/12)*((sympy.sin((sympy.pi*t)/24))**2), xlim=[0,24])

it shows a different graph. In my calculator the function has a maximum at approximately t=14 while in python, the graph stops at t=10.

>Solution :

sympy plot function takes a second argument to specify the range to draw on, it’s a tuple of (symbol,min,max), while xlim is used to limit the screen after the plot is drawn, it doesn’t affect what’s being drawn, ie: you can still move the plot to override xlim.

import sympy
t = sympy.sympify('t')
sympy.plotting.plot(10*sympy.E**(t/12)*((sympy.sin((sympy.pi*t)/24))**2),(t,0,24))

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading