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,

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

Leave a Reply