Matlab
Sol/Problem1.m
% Problem 1 % Solution @ t = 600 Nx = 100; x = linspace(0,600,Nx); t = linspace(0,600,Nx); dx = 1; tmax = 1; dt = [0.0625,0.125,0.25,0.5,0.75,1,1.5,2,3,4,5,6]; % ensure stability R = round(tmax./dt); e = ones(Nx,1); c = 1/5*ones(Nx,1); p = 0.2*dt/dx; % initial data u = zeros(Nx,1); % initial condition for i=1:length(x) u(i,1)=1; end for n = 1:length(t) u(1,n)=1 - 0.1*(cos((pi/50)*t(n))*sin((pi/80)*t(n))); end index = find(t==600); plot(x,u(:,index),'-or'); xlabel('x'); ylabel('u'); title('Solution at t = 600');
Sol/Problem3.m
% Problem 1 % Solution @ t = 600 Nx = 100; x = linspace(0,600,Nx); t = linspace(0,600,Nx); dx = 1; tmax = 1; dt = [0.0625,0.125,0.25,0.5,0.75,1,1.5,2,3,4,5,6]; % ensure stability % initial data u = zeros(Nx,1); % initial condition for i=1:length(x) u(i,1)=1; end for n = 1:length(t) u(1,n)=1 - 0.1*(cos((pi/50)*t(n))*sin((pi/80)*t(n))); end index = find(t==600); plot(x,u(:,index),'b'); xlabel('x'); ylabel('u'); title('Solution at t = 600');