- #1
ognik
- 643
- 2
I understand Runga Kutta 4th order for use with a single ODE, but am not confident I have correctly derived how to apply RK4th to a coupled or 2nd order system. As example I have dy/dt=p; dp/dt=-4pi2y
I recognize this as SHM with w=2pi so yes, I don't need RK to solve it, but I want to use this simple situation to understand how to apply RK. The '1st part' seems logical enough taking f(tn,yn,pn)=-4pi2y and dt=h.
Then k1=h*f(t,yn,pn) - effectively f(yn); kj2=h*f(yn+k1/2); k3=hf(yn+k2/2); k4=h*f(yn+k3) and then pn+1=pn+(k1+2k2+2k3+k4)/6.
I choose the origin at t=0 and y(0) = 1 for simplicity. I integrate dp/dt=-4pi2y to give p=-4pi2yt. So at t=0, p0=0.
Thus far I am feeling comfortable - but please correct/elucidate the above as appropriate.
-----------------------
Now I have dy/dt=p and clearly pn depends on yn and tn. This is where I am not very confident. So dy=pdt and I'm thinking this must be the first 'slope' point, so dy=pn*h = j1, and I have p0=0. I want j(1,2,3,4) to find yn+1. I am still a little confident so far :-)
But what of j2=h(pn+?/2). It seems to me that I must use k1/2 and go on as j3=h(pn+k2/2) etc. with yn+1=(j1+2j2+2j3+j4)/6 - because intuitively that 'couples' y and p.
But I can also see that ji already includes p - so maybe it should be j3=h(pn+j2/2) etc. ?
I would really like to understand the above, not just get the answer please?
I recognize this as SHM with w=2pi so yes, I don't need RK to solve it, but I want to use this simple situation to understand how to apply RK. The '1st part' seems logical enough taking f(tn,yn,pn)=-4pi2y and dt=h.
Then k1=h*f(t,yn,pn) - effectively f(yn); kj2=h*f(yn+k1/2); k3=hf(yn+k2/2); k4=h*f(yn+k3) and then pn+1=pn+(k1+2k2+2k3+k4)/6.
I choose the origin at t=0 and y(0) = 1 for simplicity. I integrate dp/dt=-4pi2y to give p=-4pi2yt. So at t=0, p0=0.
Thus far I am feeling comfortable - but please correct/elucidate the above as appropriate.
-----------------------
Now I have dy/dt=p and clearly pn depends on yn and tn. This is where I am not very confident. So dy=pdt and I'm thinking this must be the first 'slope' point, so dy=pn*h = j1, and I have p0=0. I want j(1,2,3,4) to find yn+1. I am still a little confident so far :-)
But what of j2=h(pn+?/2). It seems to me that I must use k1/2 and go on as j3=h(pn+k2/2) etc. with yn+1=(j1+2j2+2j3+j4)/6 - because intuitively that 'couples' y and p.
But I can also see that ji already includes p - so maybe it should be j3=h(pn+j2/2) etc. ?
I would really like to understand the above, not just get the answer please?