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

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 close merge delete

1

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

( 2022-03-24 13:38:03 +0200 )edit

Can a parametric plot solve your problem?

( 2022-03-24 16:02:51 +0200 )edit

Sort by » oldest newest most voted

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,

more

## Stats

Seen: 124 times

Last updated: Mar 25