Professional Documents
Culture Documents
ES 305 Assignment 1
11.14. A Vibrating string of unit length is fixed at both ends and is subjected to the initial
conditions
u
u x, 0 x 1 x , x, 0 0, 0 x 1
/ t
Solve the governing equation
2 u 2u
, 0 x 1, t 0,
x 2 y 2
for 0 t 1 using x 0.2 and t 0.2 .
function []=solve
a = 1;
it0 = inline('x.*(1-x)','x');
i1t0 = inline('0');
bx0t = inline('0');
bxft = inline('0');
xf = 1;
dx=0.02;
dt=0.02;
M = xf/dx;
T = 1;
N = T/dt;
[u,x,t] = String(a,xf,T,it0,i1t0,bx0t,bxft,M,N,dx,dt);
figure(1), clf
mesh(t,x,u)
x = [0:M]*dx;
t = [0:N]*dt;
for i = 1:M + 1, u(i,1) = it0(x(i));
end
for k = 1:N + 1
u([1 M + 1],k) = [bx0(t(k)); bxf(t(k))];
end
r = a*(dt/dx)^ 2;
r1 = r/2;
r2 = 2*(1 - r);
u(2:M,2) = r1*u(1:M - 1,1) + (1 - r)*u(2:M,1) + r1*u(3:M + 1,1)+
dt*i1t0(x(2:M)) ;
for k = 3:N + 1
u(2:M,k) = r*u(1:M - 1,k - 1) + r2*u(2:M,k-1) + r*u(3:M + 1,k - 1)- u(2:M,k -
2) ;
end
Cresencio P. Genobiagon Jr. ES 305 Assignment 1
0.4
0.2
-0.2
-0.4
1
1
0.8
0.5 0.6
0.4
0.2
0 0
0.4
0.2
-0.2
-0.4
1
1
0.8
0.5 0.6
0.4
0.2
0 0