% % w02char.m - characteristic solution (djm: 15 sept 10) % % clear everything & set parameters clear; close all % coordinates xL = 1; xx = -xL:xL/100:xL; yL = 2; yy = -yL:yL/100:yL; % make matrices of coordinates (type "help meshgrid") [xg, yg] = meshgrid(xx,yy); % PDE solution, matrix of values ug = yg - asin(xg); % surface plot figure(1); clf surf(xx,yy,ug); shading flat xlabel('\bf x-axis') ylabel('\bf y-axis') zlabel('\bf u-axis') title('\bf surface plot of solution to s1.2, #6') colorbar % optional characteristics hold on if(1==1) for kk = [-2*yL:0.5:2*yL] yc = kk + asin(xx); list = find(yc >= -yL); yc = yc(list); list = find(yc <= yL); yc = yc(list); plot3(sin(yc-kk),yc,kk*ones(size(yc)),'k') end axis([-xL xL -yL yL -2*yL 2*yL]) end % contour plot of characteristics figure(2); clf contour(xx,yy,ug,[-2*yL:0.5:2*yL]) xlabel('\bf x-axis') ylabel('\bf y-axis') title('\bf contour plot of characteristics') colorbar