Ask Your Question
1

How to plot stream lines of an ODE with one single variable?

asked 2023-05-09 18:05:24 +0100

toni gravatar image

updated 2023-05-09 20:33:30 +0100

I want to see the stream line plot for y' = -sin(x).

The solution of this ODE is coded as:

x = var('x')
y = function('y')(x)
de = diff(y,x) == -sin(x)
h = desolve(de,y)
solution = h.function(x)
show(solution)

I can produce the desired slope field ad hoc like this:

f(x,y)= - sin(x)
streamline_plot(f(x,y),(x,-10,10),(y,-5,5))

However, I am not able to get the right expression in the code for the stream line plot using the functions already defined above: h, solution or y

What would be the more natural expression for the general (and a particular solution) plots?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-05-10 04:57:31 +0100

achrzesz gravatar image

You don't need to know the solution to use streamline_plot (I'm using cos(x) to show that your calculations are OK)

var('y')
s=streamline_plot(-sin(x),(x,-10,10),(y,-3,3),plot_points=100)
p=plot(cos(x),(x,-10,10),color='red')
s+p

Or

var('y')
pts = [(0,s) for s in srange(-3,3,0.5)]
s=streamline_plot(-sin(x),(x,-10,10),(y,-3,3),
                  start_points=pts, density=4,plot_points=100)
p=plot(cos(x),(x,-10,10),color='red') 
s+p

If you know the solution you can:

s=contour_plot(y-cos(x),(x,-10,10),(y,-5,5),fill=False,contours=20,linewidths=2)
p=plot(cos(x),(x,-10,10),ymax=5,ymin=-5,color='red')
s+p
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2023-05-09 18:05:24 +0100

Seen: 209 times

Last updated: May 10 '23