% % w03per.m - characteristic solution (djm: 21 sept 2010) % - define initial data in w03perF1.m demo = 1; % coordinates & parameters cc = 1; dt = 1/8; dx = cc*dt; % L >= 8 xL = 8; xx = 0:dx:xL; Tf = xL*4; switch demo case{1} func = @w03perF1; % +1 = neumann, -1 = dirichlet bc0 = -1; bcL = 1; lims = [0 xL -1.1 1.1]; end figure(10); clf; for tt = 0:dt:Tf xi = mod(xx+cc*tt+2*xL,4*xL)-2*xL; et = mod(xx-cc*tt+2*xL,4*xL)-2*xL; u1 = feval(func,xi,xL,bc0,bcL,1); u2 = feval(func,et,xL,bc0,bcL,2); subplot(2,1,1) plot(xx,u1+u2,'r'); hold on plot(xx,u1+u2,'k.'); axis(lims) hold off title(['\bf u(x,t) at t = ' num2str(tt)]) xlabel('\bf finite domain with reflections') if (bcL==1) text(xL-1.4,0.9,'\bf neumann bc') else text(xL-1.3,0.9,'\bf dirichlet bc') end if (bc0==1) text(0.1,0.9,'\bf neumann bc') else text(0.1,0.9,'\bf dirichlet bc') end subplot(2,1,2) plot(xx,u1,'c'); hold on plot(xx,u2,'m'); axis(lims) hold off xlabel('\bf x-axis') drawnow pause(0.05) end