% % Written by: % -- % John L. Weatherwax 2009-04-21 % % email: wax@alum.mit.edu % % Please send comments and especially bug reports to the % above email address. % %----- addpath('../../BookCode'); close all; clc; clear; % Problem EPage 118 ; Equation 6.6.1 on EPage 112? % c = 1; nx = 20; % 20 division of x hx = 1/nx; ht = 0.05; % t = 0:0.05:4.5 nt = 90; t = linspace( 0, 4.5, nt+1 ); x = 0:hx:1; init = sin( pi * x ) + 2 * sin( 2 * pi * x ); % u(x,0) = sin( pi * x ) + 2 sin( 2 pi x ) initslope = zeros( 1, nx+1 ); % u_t(0,x) = 0 lowb = 0; hib = 0; % u(t,0) = u(t,1) = 0; [X,T] = meshgrid( x, t ); u_truth = sin( pi * X ) .* cos( pi * T ) + 2 * sin( 2 * pi * X ) .* cos( 2 * pi * T ); u = fwave(nx,hx,nt,ht,init,initslope,lowb,hib,c); surf(u); xlabel('x - node number'); ylabel('time - node number'); zlabel('displacement u(x,t)'); title('approximation'); %saveas( gcf, '../../WriteUp/Graphics/Chapter6/c_6_p_7_plot.eps', 'epsc' ); figure; surf(u_truth); xlabel('x - node number'); ylabel('time - node number'); zlabel('displacement u(x,t)'); title('truth'); A = abs( u-u_truth ); max( A(:) )