4.4 Solve homogeneous 2nd order ODE with constant coefficients

Problem: Solve \[ y^{\prime \prime }\left ( t\right ) -1.5y^{\prime }\left ( t\right ) +5y\left ( t\right ) =0 \] with initial conditions \[ y\left ( 0\right ) =1,y^{\prime }\left ( 0\right ) =0 \] To use Matlab ode45, the second order ODE is first converted to state space formulation as follows

Given \(y^{\prime \prime }\left ( t\right ) -1.5y^{\prime }\left ( t\right ) +5y\left ( t\right ) =0\) let \begin {align*} x_{1} & =y\\ x_{2} & =y^{\prime }\\ & =x_{1}^{\prime } \end {align*}

hence \[ x_{1}^{\prime }=x_{2}\] and \begin {align*} x_{2}^{\prime } & =y^{\prime \prime }\\ & =1.5y^{\prime }-5y\\ & =1.5x_{2}-5x_{1} \end {align*}

Hence we can now write \[\begin {bmatrix} x_{1}^{\prime }\\ x_{2}^{\prime }\end {bmatrix} =\begin {bmatrix} 0 & 1\\ -5 & 1.5 \end {bmatrix}\begin {bmatrix} x_{1}\\ x_{2}\end {bmatrix} \] Now Matlab ODE45 can be used.

Mathematica

Remove["Global`*"]; 
eq  = y''[t]-1.5y'[t]+5y[t]==0; 
ic  = {y'[0]==0,y[0]== 1}; 
sol = First@DSolve[{eq,ic},y[t],t]; 
y   = y[t]/.sol
 

\(1. \left (1. e^{0.75 t} \cos (2.10654 t)-0.356034 e^{0.75 t} \sin (2.10654 t)\right )\)

Plot[y,{t,0,10}, 
     FrameLabel->{{"y(t)",None}, 
         {"t","Solution"}}, 
     Frame->True, 
     GridLines->Automatic, 
     GridLinesStyle->Automatic, 
     RotateLabel->False, 
     ImageSize->300, 
     AspectRatio->1, 
     PlotRange->All, 
     PlotStyle->{Thick,Red}]
 

pict

Matlab

function e54 
 
t0 = 0; %initial time 
tf = 10; %final time 
 
%initial conditions [y(0)  y'(0)] 
ic =[1 0]'; 
 
[t,y] = ode45(@rhs, [t0 tf], ic); 
 
plot(t,y(:,1),'r') 
title('Solution using ode45'); 
xlabel('time'); 
ylabel('y(t)'); 
grid on 
set(gcf,'Position',[10,10,320,320]); 
 
    function dydt=rhs(t,y) 
        dydt=[y(2) ; 
             -5*y(1)+1.5*y(2)]; 
    end 
end
 

pict