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}]
|
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
|