Question 7.18: ode45 FOR A SYSTEM Using ode45 (with step size of 0.1), solv...

ode45 FOR A SYSTEM

Using ode45 (with step size of 0.1), solve the following system:

\begin{matrix} \overset{.}{u_{1}}= u_2 \\ \overset{.}{u_2}=\frac{2}{3}(-2u_2-tu_1+cos  t) \end{matrix}  subject   to   initial   conditions  \begin{matrix} u_1(0)=1 \\ u_2(0)=-1 \end{matrix}
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.

We first express the system in vector form

\overset{.}{u} = f(t,u),   u=\left\{\begin{matrix} u_1 \\ u_2 \end{matrix} \right\},   f=\left\{\begin{matrix} u_2 \\ \frac{2}{3}(-2u_2-tu_1+ cos  t) \end{matrix} \right\},   u_0=\left\{\begin{matrix} 1 \\ -1 \end{matrix} \right\}

u0 = [1;−1]; t = 0:0.1:1;
f = @(t,u)([u(2);2*(−2*u(2)-t*u(1)+cos(t))/3]);
[t,u45] = ode45(f,t,u0)
t =
0
0.1000
0.2000
0.3000
0.4000
0.5000
0.6000
0.7000
0.8000
0.9000
1.0000
% u45 has two columns: First column is u1, second column is u2
u45 =
1.0000 −1.0000
0.9095 −0.8159
0.8359 −0.6605
0.7765 −0.5302
0.7291 −0.4219
0.6915 −0.3330

0.6619 −0.2615
0.6387 −0.2056
0.6203 −0.1639
0.6055 −0.1348
0.5930 −0.1173

Related Answered Questions