% % w03refl.m - characteristic solution (djm: 21 sept 2010) % - define initial data in w03reflF1.m demo = 1; % coordinates & parameters cc = 1; dt = 1/8; dx = cc*dt; xL = 8; xx = 0:dx:xL; Tf = 12; switch demo case{1} func = @w03reflF1; BC = -1; lims = [0 xL -1.1 1.1]; case{2} func = @w03reflF1; BC = +1; lims = [0 xL -1.1 1.1]; end figure(10); clf; for tt = 0:dt:Tf u1 = feval(func,xx+cc*tt,BC,1); u2 = feval(func,xx-cc*tt,BC,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)]) if(BC==1) xlabel('\bf neumann reflection') else xlabel('\bf dirichlet reflection') 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.1) end