

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


n + 1
u (0, t ) = 1 " 0.5cos[ 4 t ]
% newwave.m % % Written by Dr. James D. Baeder for ENAE % UNIVERSITY OF MARYLAND % % Linear advection equation % u_t + au_x = 0 ;a> 0 % Dirichlet at left and no reflection at right % Numerical Method (with appropriate bc’s): % 1) Lax's Method % u_j^n+1 = u_j^n - 0.5cfl(u_j+1^n - u_j-1^n) % + 0.5(u_j+1^n - 2u_j^n + u_j-1^n) % Initial Solution: % u(t=0,x) = 1.5 ; x>pi/ % 0.5 ; x<=pi/ % Boundary Condition: % u(t,x=0) = 1 - 0.5cos(-4t) % Exact Solution: % Implemented in exact.m % Numerical Solution: % ?!?!?!?!?!?!?! % % Let's clear everything including graphics for figures 1 clear; figure(1); clf; % Let's get the input from the user!!!! imeth = input('Enter method (1): '); cfl = input('Enter cfl number: '); jmax = input('Enter # of mesh points (including end points): '); % Set some variables for now a = 1; tfinal = pi; xend = pi; % Calculate some variables dx = xend/(jmax-1); % mesh spacing in x dt = cfldx/a; % time step size dtdx = dt/dx; nsteps = round(tfinal/dt); % total number of time steps npart = round(nsteps/4); % intermediate time step % initialize mesh locations x = (0:jmax-1)dx; % store exact solution at a few times uparte=exact(x,a,dtnpart); uinite=exact(x,a,0); % initial data: u=uinite;