4.3 Solve homogeneous 1st order ODE, constant coefficients and initial conditions

Problem: Solve\[ y^{\prime }\left ( t\right ) =3y\left ( t\right ) \] with initial condition \(y\left ( 0\right ) =1\) and plot the solution for \(t=0 \cdots 2\) seconds.

Mathematica

Remove["Global`*"]; 
sol = First@DSolve[{y'[t]==3y[t], 
         y[0]==1},y[t],t]; 
y   = y[t]/.sol 
 
       Out[26]= E^(3 t) 
 
Plot[y,{t,0,2}, 
  FrameLabel->{{"y(t)",None}, 
   {"t","Solution of y'=3y, y(0)=1"}}, 
  Frame->True, 
  GridLines->Automatic, 
  GridLinesStyle->Automatic, 
  RotateLabel->False, 
  ImageSize->300, 
  AspectRatio->1]
 

pict

Matlab

function e53 
t         = 0:0.001:2;   % time 
initial_y = 1; 
 
[t,y] = ode45( @rhs, t, initial_y); 
 
plot(t,y) 
title('Solution of y''=3y , y(0)=1'); 
xlabel('time'); 
ylabel('y(t)'); 
grid on 
set(gcf,'Position',[10,10,420,420]); 
 
    function dydt=rhs(t,y) 
        dydt = 3*y; 
    end 
end
 

pict