Ask Your Question
0

How to tabulate $(r\cos\theta,r\sin\theta)$ from $(t,r,\theta)$ obtained from solving a system of ODE using RK4?

asked 2022-03-24 13:35:03 +0100

Abby11 gravatar image

I am trying to solve a system of first-order differential equations of the following form: $$\frac{dr}{dt}=f(r,\theta), \quad\frac{d\theta}{dt}=g(r,\theta)$$ I am using desolve_system_rk4 which gives me a list of triples $(t,r,\theta)$. Now I need to plot the trajectory in the xy-plane. For this, I require to obtain the x and y coordinate using $$x=r\cos\theta, \quad y=r\sin\theta$$ and then obtain the xy-plot. How can I tabulate the pair $(r\cos\theta,r\sin\theta)$ from $(t,r,\theta)$?

edit retag flag offensive close merge delete

Comments

1

Please add your code using desolve_system_rk4, so that it's easier to give an answer.

rburing gravatar imagerburing ( 2022-03-24 13:38:03 +0100 )edit

Can a parametric plot solve your problem?

tolga gravatar imagetolga ( 2022-03-24 16:02:51 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2022-03-25 23:23:23 +0100

Emmanuel Charpentier gravatar image

Starting from the example given in the documentation that you could have bothered to read by typing desolve_system_rk4? :

sage: from sage.calculus.desolvers import desolve_system_rk4
sage: x,y,t=var('x y t')
sage: P=desolve_system_rk4([x*(1-y),-y*(1-x)],[x,y],ics=[0,0.5,2],ivar=t,end_points=20)

you can see that the solution P is a list of [t, x, y] triplets. You can display the x and y functions by :

sage: line2d([[i, j] for i, j, k in P])
sage: line2d([[i, k] for i, j, k in P])

(line2d interpolates between the points that list_plot displays, which is aesthetically more pleasing).Your phase trajectory can therefore be displayed by :

sage: line2d([[j,k] for i, j, k in P])

HTH,

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: 2022-03-24 13:35:03 +0100

Seen: 626 times

Last updated: Mar 25 '22