Post on 19-Jan-2016
description
transcript
1
Spring 2003
Prof. Tim Warburtontimwar@math.unm.edu
MA557/MA578/CS557Lecture 10
2
This Lecture
• HW3 answers
• Coding time.
3
HW3 Q1
Q1) Code up a function (LEGENDRE) which takes a vector x and m as arguments and computes the m’th order Legendre polynomial at x using the stable recurrence relation.
A1) We use the following recurrence relationship:
0
1
1 1
1
2 1, 0,1,...
1 1m m m
L x
L x x
m mL x xL x L x m
m m
4
HW3 Q1 cont
5
HW3 Q1 cont• Let’s plot those Legendre polynomials and see how
they behave over the interval [-1,1]
p=0p=1
p=2
p=3 p=4
p=4
6
HW3 Q2
Q2) Create a function (LEGdiff) which takes p as argument and returns the coefficient differentiation matrix D
A2) The differentiation matrix which maps the Legendre coefficients to the Legendre coefficients of the derivative of the function:
(2 1) if j>m and j+m oddˆ 0 otherwise mj
mD
7
HW3 Q2 cont
A2cont) The Matlab code is:
8
HW3 Q2 cont
• Let’s test the output for p=5:
(2 1) if j>m and j+m oddˆ 0 otherwise mj
mD
Spot on!.
Note that there are onlyp + (p-2) + (p-4).. Non-zero entries
9
HW3 Q2 cont
• The form of Dhat
10
HW 3 Q3
Q3) Create a function (LEGmass) which takes p as argument and returns the mass matrix M
A3) Definition of the mass matrix:
1 2 n=m
2 2 10 (n m)
i i
nm
x xM n
11
HW3 Q3 cont
12
HW3 Q4
Q4) Create a function LEGvdm which returns the following matrix:
A4) 0 i,j pij j iV L x
13
HW3 Q4 cont
p=0 p=1 p=2
14
HW3 Q5
Q5) Test them with the following matlab routine:
15
HW3 Q5 cont• Note that x^m is exactly interpolated for m<=p when we use p+1 points
and up to p’th order polynomials. x^(p+1) is only approximately interpolated – and hence the derivative is only approximate.
16
Note on Q5
• If we were to repeat this on an interval
• We would need to use:
1,n nx x
1
2 ˆn n
d
dx x x
1FVD V F
17
HW3 Q6
Q6) Compute the condition number of the generalized Vandermonde matrix constructed with p=0,…40 and p+1 Chebychev points.
18
Asymptotic Behavior cond(V) as p->infinity
19
1, ,
0
, ,
% initial condition
for i=N-1:1
for m=0:p
0
end
end
% start time stepping
for tstep=1:Ntsteps
% initiate sigma
for i=N-1:1
for n=0:p
j p
i m i jmjj
i n i n
t V q x
, , , 1,0 01
end
end
% start Runge-Kutta loop
for rk=3:-1:1
for i=N-1:2
for n=0:p
2 1 1 1
end
m p m pn m n
i n i n nm i m i mm mi i
dt nu D u
rk x x
1, 1, 1,02 1
, ,
end
for n=0:p
2 1 1
end
end % end RK loop
for i=N-1:1
for n=0:p
n=0,..,p
en
m pn m
n n nm mm
i n i n
dt nu D
rk x x
1, ,
0
d
end
end
% finish by evaluating solution at cheby nodes
for i=N-1:1
for j=0:p
,
end
end
m p
i j i mjmm
t T x V
Cliff note version of DG advection
equation
20
Workshop Code
• Using your own routines or those on the web site code up the DG advection equation solver by Wednesday end of class.
• Spare time this class for coding…