Some help with approximation
Use the RK4 method to approx y(0.2), where y(x) is the solution to the IVP: \(\Large y''-2y+2y=e^t~ cost \), (y(0)=1 \), \(y'(0)=2 \) Use h=0.2 So far I got to \(\color{green}{y'=u}\) and \(\color{red}{u'=2u-2y+e^t*cost} \) This might be a silly question but I'm new to this.. what do you do with the t variable?
rana kutta? never played with it, i know its an averaging process but i got no idea how it works
hello, its 4th order euler's method?
all this rk stuff its all coming off the basic euler's approximation princilpes
This is review for me, so let me follow along at my own pace :) \[\begin{cases}y''-2y'+2y=e^t\cos t\\y(0)=1\\y'(0)=2\end{cases}\] So far, you've set up the system of first order ODEs using \(u=y'\), which gives \[\begin{cases}y'=u\\u'=2u-2y+e^t\cos t\end{cases}\] with initial values \(y(0)=1,u(0)=2\). First, recall we're using the following recursions: for \(n\ge0\), \[\begin{cases}y_{n+1}=y_n+\dfrac{h}{6}f\left(k_1+2k_2+2k_3+k_4\right)\\\\ t_{n+1}=t_n+h\end{cases}\] with \(h=0.2\), and \[\begin{cases}k_1=f(t_n,y_n)\\ k_2=f\left(t_n+\dfrac{h}{2},y_n+\dfrac{h}{2}k_1\right)\\ k_3=f\left(t_n+\dfrac{h}{2},y_n+\dfrac{h}{2}k_2\right)\\ k_4=f(t_n+h,y_n+hk_3)\end{cases}\] None of this is new I hope?
The setup above is what you'd use for a first-order ODE, so here's what we have to deal with when numerically solving a second-order ODE: \[\begin{cases} \begin{cases} k_1=f(t_n,y_n,u_n)\\\\ l_1=g(t_n,y_n,u_n) \end{cases}\\\\ \begin{cases} k_2=f\left(t_n+\dfrac{h}{2},y_n+\dfrac{h}{2}k_1,u_n+\dfrac{h}{2}l_1\right)\\\\ l_2=g\left(t_n+\dfrac{h}{2},y_n+\dfrac{h}{2}k_1,u_n+\dfrac{h}{2}l_1\right) \end{cases}\\\\ \begin{cases} k_3=f\left(t_n+\dfrac{h}{2},y_n+\dfrac{h}{2}k_2,u_n+\dfrac{h}{2}l_2\right)\\\\ l_3=g\left(t_n+\dfrac{h}{2},y_n+\dfrac{h}{2}k_2,u_n+\dfrac{h}{2}l_2\right) \end{cases}\\\\ \begin{cases} k_4=f(t_n+h,y_n+hk_3,u_n+hl_3)\\\\ l_4=g(t_n+h,y_n+hk_3,u_n+hl_3) \end{cases} \end{cases}\] where \[\begin{cases}y'=f(t,y,u)\\ u'=g(t,y,u)\end{cases}\] and the recursions are the same: \begin{cases} y_{n+1}=y_n+\dfrac{h}{6}f\left(k_1+2k_2+2k_3+k_4\right)\\\\ u_{n+1}=u_n+\dfrac{h}{6}g\left(k_1+2k_2+2k_3+k_4\right)\\\\ t_{n+1}=t_n+h \end{cases}
I'd start with a set of tables. I'm currently writing them up in LaTeX and verifying the computations with Mathematica. Might take a moment...
I love the way you lay things out, thanks :) But since there is a t and no x, we replace x with t in the function?
Well \(t\) is your dependent variable here. There is no \(x\). Also, slight typo: The recursion for \(u\) should be \(u_{n+1}=u_n+\dfrac{h}{6}g\left(\color{red}{l_1+2l_2+2l_3+l_4}\right)\), not \(k\).
Oh another typo, there is not \(f\) or \(g\), I misread my notes. The recursions should be \[\begin{cases} y_{n+1}=y_n+\dfrac{h}{6}\left(k_1+2k_2+2k_3+k_4\right)\\\\ u_{n+1}=u_n+\dfrac{h}{6}\left(l_1+2l_2+2l_3+l_4\right)\\\\ t_{n+1}=t_n+h \end{cases}\]
Here's what I'm getting for \(n=1\). \[\begin{matrix} \begin{array}{c|c|c|c} n&t_n&y_n&u_n\\ \hline 0&0&1&2\\ 1&\color{lightgray}{0.2}&1.46399&2.65945 \end{array} \\\\ \begin{array}{c|c|c|c} k_1&k_2&k_3&k_4\\ \hline 2&2.3&2.32996&2.65992 \end{array} \\\\ \begin{array}{c|c|c|c} l_1&l_2&l_3&l_4\\ \hline 3&3.29965&3.29958&3.5849 \end{array} \end{matrix}\] (The grayed out part isn't needed for this step, but will be for the next one.)
Here's the breakdown for the calculations. Quick disclaimer: I'm using approximations of the results in the tables. The first set of things you need to compute is \(k_1\) and \(l_1\), using \(t_0=0\), \(y_0=1\), and \(u_0=2\). \[\begin{cases} k_1=f(0,1,2)=2\\\\ l_1=g(0,1,2)=2(2)-2(1)+e^0\cos0=3 \end{cases}\] which are due to \(f(t,y,u)=u\) and \(g(t,y,u)=2u-2y+e^t\cos t\). Next, \(k_2\) and \(l_2\). \[\begin{cases} k_2=f\left(0+\dfrac{0.2}{2},1+\dfrac{0.2}{2}(2),2+\dfrac{0.2}{2}(3)\right)=f(0.1,1.2,2.3)=2.3\\\\ l_2=g\left(0+\dfrac{0.2}{2},1+\dfrac{0.2}{2}(2),2+\dfrac{0.2}{2}(3)\right)=g(0.1,1.2,2.3)\approx3.3 \end{cases}\] Next, \(k_3\) and \(l_3\). \[\begin{cases} k_3\approx f\left(0+\dfrac{0.2}{2},1+\dfrac{0.2}{2}(2.3),2+\dfrac{0.2}{2}(3.3)\right)\approx f(0.1,1.23,2.33)\approx 2.3\\\\ l_3\approx g\left(0+\dfrac{0.2}{2},1+\dfrac{0.2}{2}(2.3),2+\dfrac{0.2}{2}(3.3)\right)\approx g(0.1,1.23,2.33)\approx 3.3 \end{cases}\] Finally, \(k_4\) and \(l_4\). \[\begin{cases} k_4\approx f(0+0.2,1+0.2(2.3),2+0.2(3.3))\approx f(0.2,1.46,2.66)\approx 2.7\\\\ l_4\approx g(0+0.2,1+0.2(2.3),2+0.2(3.3))\approx g(0.2,1.46,2.66)\approx 3.6 \end{cases}\] We're not quite done yet, though, because now we have to compute \(y_1\) and \(u_1\), which are \[\begin{cases} y_1\approx 1+\dfrac{0.2}{6}\left(2+2(2.3)+2(2.3)+2.7\right)\approx 1.5\\\\ u_1\approx 2+\dfrac{0.2}{6}\left(3+2(3.3)+2(3.3)+3.6\right)\approx 2.7 \end{cases}\]
For \(n\ge1\), rinse and repeat, replacing the appropriate \(t_0,y_0,u_0\) with the newly computed \(t_1,y_1,u_1\), and compute the new \(k\)s and \(l\)s. Since the step size is \(h=0.2\), and you want to approximate the solution at \(t=2\), you're looking at \(n=10\) rounds of these computations. I highly recommend writing a script to do all the computations for you.
I see where I messed up now. And yea, I had to do this on Excel with h=0.2 and 0.1.. it can be a pain xD But now I see what to do.. thanks for all your time Siths :)
You're welcome!
Oh, to answer your initial question: you replace each successive \(t\) by the step size increment. So for the first round of calculations, \(t_0=0\), and the next would be \(t_1=t_0+h=0+0.2=0.2\), and the next would be \(t_2=t_1+h=0.2+0.2=0.4\), and so on.
Join our real-time social learning platform and learn together with your friends!