53 Solve homogeneous 1st order linear differential equation with constant coefficients and initial conditions

Problem: Solve

$\displaystyle 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 Matlab
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]

Image mma_e53_1

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, using ode45');
xlabel('time');
ylabel('y(t)');
grid on
set(gcf,'Position',[10,10,420,420]);

    function dydt=rhs(t,y)
        dydt = 3*y;
    end
end

Image matlab_e53_1



me 2013-01-09