Question 7.13: RK4 METHOD FOR SYSTEMS Reconsider Example 7.11. Using RK4 me...

RK4 METHOD FOR SYSTEMS

Reconsider Example 7.11. Using RK4 method for systems, with h = 0.1, find an estimate for y_1 = y(0.1). Confirm by executing the user-defined function RK4System.

The 'Blue Check Mark' means that either the MATLAB code/script/answer provided in the answer section has been tested by our team of experts; or the answer in general has be fact checked.

Learn more on how do we answer questions.

Recall

\textbf{u}^{′}=\textbf{f}(x,\textbf{u}), \textbf{u}=\left\{\begin{matrix} u_1 \\ u_2 \\ u_3 \end{matrix} \right\}= \left\{\begin{matrix} y \\ y^{′} \\ y^{′′} \end{matrix} \right\} , \textbf{f}(x,\textbf{u})=\left\{\begin{matrix} u_2 \\ u_3 \\ \frac{1}{3}\left[u_3+5u_2+3u_1+e^{-x/2} \right] \end{matrix} \right\},\textbf{u}_0=\left\{\begin{matrix} u_1(0) \\ u_2(0) \\ u_3(0)\end{matrix} \right\} =\left\{\begin{matrix} 0 \\ -1 \\ 1 \end{matrix} \right\}

We first need to find \textbf{u}_1=\textbf{u}_0+\frac{1}{6}h(\textbf{k}_1+2\textbf{k}_2+2\textbf{k}_3+\textbf{k}_4)

\textbf{k}_1=\textbf{f}(x_0,\textbf{u}_0)=\left\{\begin{matrix} u_2(0) \\ u_3(0) \\ \frac{1}{3}\left[u_3(0)+5u_2(0)+3u_1(0)+e^{-0.2} \right] \end{matrix} \right\} =\left\{\begin{matrix} -1 \\ 1 \\ \frac{1}{3}(1+5(-1)+3(0)+1) \end{matrix} \right\} =\left\{\begin{matrix} -1\\ 1 \\ -1 \end{matrix} \right\}

To calculate \textbf{k}_2=\textbf{f}(x_0+\frac{1}{2}h,\textbf{u}_0+\frac{1}{2}h\textbf{k}_1 ) =\textbf{f}(0.05,\textbf{u}_0+\frac{1}{2}h\textbf{k}_1 ) , we first find

\textbf{u}_0+\frac{1}{2}h\textbf{k}_1=\left\{\begin{matrix} 0 \\ -1 \\ 1 \end{matrix} \right\}+0.05\left\{\begin{matrix} -1 \\ 1 \\ -1 \end{matrix} \right\} =\left\{\begin{matrix} -0.05 \\ -0.95 \\ 0.95 \end{matrix} \right\}

Then,

\textbf{k}_2=\textbf{f}(0.05,\textbf{u}_0+\frac{1}{2}h\textbf{k}_1 )=\left\{\begin{matrix} -0.95 \\0.95 \\ \frac{1}{3}\left[0.95+5(-0.95)+3(-0.05)+e^{-0.05/2} \right] \end{matrix} \right\} =\left\{\begin{matrix}-0.95 \\ 0.95 \\ -0.9916 \end{matrix} \right\}

To calculate \textbf{k}_3=\textbf{f}(x_0+\frac{1}{2}h,\textbf{u}_0+\frac{1}{2}h\textbf{k}_2 )=\textbf{f}(0.05,u_0+\frac{1}{2}h\textbf{k}_2 ), we first find

u_0+\frac{1}{2}h\textbf{k}_2=\left\{\begin{matrix} 0 \\ -1 \\ 1 \end{matrix} \right\} +0.05\left\{\begin{matrix} -0.95 \\ 0.95 \\ -0.9916 \end{matrix} \right\} =\left\{\begin{matrix} -0.0475 \\-0.9525 \\ 0.9504 \end{matrix} \right\}

Then,

\textbf{k}_3=\textbf{f}(0.05,\textbf{u}_0+\frac{1}{2}h\textbf{k}_2 )=\left\{\begin{matrix} -0.9525 \\ 0.9504 \\ \frac{1}{3}\left[0.9504+5(-0.9525)+3(-0.0475)+e^{-0.05/2} \right] \end{matrix} \right\} =\left\{\begin{matrix} -0.9525 \\ 0.9504 \\ -0.9931 \end{matrix} \right\}

To find \textbf{k}_4=\textbf{f}(x_0+h,\textbf{u}_0+h\textbf{k}_3)=\textbf{f}(0.1,\textbf{u}_0+h\textbf{k}_3), we first calculate

\textbf{u}_0+h\textbf{k}_3=\left\{\begin{matrix} 0 \\ -1 \\ 1 \end{matrix} \right\}+0.1\left\{\begin{matrix} -0.9525\\ 0.9504 \\ -0.9931 \end{matrix} \right\} =\left\{\begin{matrix} -0.0953 \\ -0.9050 \\ 0.9007 \end{matrix} \right\}

Then,

\textbf{k}_4=\textbf{f}(0.1,\textbf{u}_0+h\textbf{k}_3)=\left\{\begin{matrix} -0.9050 \\ 0.9007 \\ \frac{1}{3}\left[0.9007+5(-0.9050)+3(-0.0953)+e^{-0.1/2} \right] \end{matrix} \right\} =\left\{\begin{matrix} -0.9050 \\ 0.9007 \\ -0.9863 \end{matrix} \right\}

Finally,

\textbf{u}_1=\textbf{u}_0+\frac{1}{6}h(\textbf{k}_1+2\textbf{k}_2+2\textbf{k}_3+\textbf{k}_4)=\left\{\begin{matrix} \boxed{-0.0952} \\ -0.9050 \\ 0.9007 \end{matrix} \right\}

Therefore, our estimate is y(0.1) = −0.0952. The result may be confirmed in MATLAB as follows:

>> f = @(x,u)([u(2);u(3);(u(3)+5*u(2)+3*u(1)+exp(-x/2))/3]);
>> x = 0:0.1:1;
>> u0 = [0;−1;1];
>> u = RK4System(f,x,u0);
>> u(1,2) % y(0.1) is the 2nd entry in the first row
ans =
[latex]\boxed{-0.0952}[/latex]

The boxed value agrees with the hand calculations.

Related Answered Questions