dx2/dt^2+5dx/dt+6x=f(t)
f(t)=4e(-t)u(t)
x(0)=1
x'(0)=2
so I change it to first order
dx/dt=z
dz/dt=-5z-6x+f(t)
ti=0 ;tf=5s
h or deltat=0.1 sec increment
plot x(t)
program:
A=[0 1;-6 -5];
B=[0;1];
f=inline('4*exp(-t)');
t=0;
t1=5;
x=[0;1];
h=0.1;
n=(t1-t)/h;
for i=1:n
k1=A*x+B*f(t);
k2=A*(x+h*k1/2)+B*f(t+1/2*h);
k3=A*(x+h*k2/2)+B*f(t+1/2*h);
k4=A*(x+h*k3)+B*f(t+h);
k=(k1+2*k2+2*k3+k4)/6;
t=t+h;
x=x+h*k;
end
h
x
k1
k2
k3
k4
k
t
x
plot(t,x)
this is what I have but I'm not sure if I'm doing this right and