% Implict sceme for one-way wave equation close all; clear all; global c c=0.5; tfinal = 1; n = input('n =') h = 1/n; dt = h; kfinal = fix(tfinal/dt); for i=1:n+1 x(i) = (i-1)*h; u0(i) = sin(pi*x(i)); end plot(x,u0); hold d = 1 + c *dt/h; alf = - c *dt/h; t=0; for k=1:kfinal t1 = t + dt; u1(1) = uexact(0,t1); % Boundary condition for i=2:n+1, u1(i) = (u0(i) + dt*f1(x(i),t1) - alf*u1(i-1) )/d; end plot(x,u1); pause(0.0) u0 = u1; t = t + dt; end for i=1:n+1 err(i) = u1(i)- uexact(x(i),t); end figure(2); plot(x,err) format short e e2 = [norm(err,1)/n,norm(err,2)/sqrt(n),norm(err,inf)],