Page 358 - MATLAB an introduction with applications
P. 358
Direct Numerical Integration Methods ——— 343
Example E6.3: Solve numerically the differential equation 4X + 2000X = F ( ) with the initial conditions
t
X = X = 0 and forcing function F(t) as shown in Fig. E6.3. Use central difference method with ∆t = 0.02
0
0
sec.
F(t)
150
0 t
0 0.10 0.20
Fig. E6.3
Solution: Here the complete MATLAB program is shown below:
% INITIAL VALUES
m=4;k=2000;c=0;dt=0.02;
x0=0;x0d=0;
F0=150;
T=1;
x0dd=inv(m)*(F0-c*x0d-k*x0);
xprev=x0-(dt*x0d)+((dt^2)*x0dd/2);
a0=1/dt^2;a1=1/(2*dt);a2=2*a0;
mbar=a0*m+a1*c;
t=0;
v(1)=x0d;a(1)=x0dd;
i=1;
for t=0:dt:T+dt
X(i)=x0;
if t<=0.1 f=F0;
else if (t>0.1 & t<=0.2) f=-(F0/0.1)*(t-0.2);
else if t>0.2 f=0;
end
end
end
fbar=f+(a2*m-k)*x0+(a1*c-a0*m)*xprev;
x=inv(mbar)*fbar;
xprev=x0;
x0=x;
i=i+1;
p=i;