MATLAB CODE for solving ODE with initial conditions and plotting solution
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear all
a=1; b=1; %%%% Intial conditions I have given randomly, one can
change according to the problem requirement
ode = 'D2y +4*Dy + 4*y = 4*cos(3*t)';
initial = 'y(0)=a, Dy(0)=b';
y=dsolve(ode,initial,'t')
%%%% plotting the solution for 0<x<6
for t=0:0.01:10
plot(t,exp(-2*t)*(a+20/169)+exp(-2*t)*t*(b+2*a-8/13)-20/169*cos(3*t)+48/169*sin(3*t),'.')
hold on
end
xlabel('t seconds')
ylabel('solution y')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
OUTPUT
y =exp(-2*t)*(a+20/169)+exp(-2*t)*t*(b+2*a-8/13)-20/169*cos(3*t)+48/169*sin(3*t)
Get Answers For Free
Most questions answered within 1 hours.