ma557/ma578/cs557 lecture 10
DESCRIPTION
MA557/MA578/CS557 Lecture 10. Spring 2003 Prof. Tim Warburton [email protected]. This Lecture. HW3 answers Coding time. HW3 Q1. - PowerPoint PPT PresentationTRANSCRIPT
![Page 2: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/2.jpg)
2
This Lecture
• HW3 answers
• Coding time.
![Page 3: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/3.jpg)
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
![Page 4: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/4.jpg)
4
HW3 Q1 cont
![Page 5: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/5.jpg)
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
![Page 6: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/6.jpg)
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
![Page 7: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/7.jpg)
7
HW3 Q2 cont
A2cont) The Matlab code is:
![Page 8: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/8.jpg)
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
![Page 9: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/9.jpg)
9
HW3 Q2 cont
• The form of Dhat
![Page 10: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/10.jpg)
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
![Page 11: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/11.jpg)
11
HW3 Q3 cont
![Page 12: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/12.jpg)
12
HW3 Q4
Q4) Create a function LEGvdm which returns the following matrix:
A4) 0 i,j pij j iV L x
![Page 13: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/13.jpg)
13
HW3 Q4 cont
p=0 p=1 p=2
![Page 14: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/14.jpg)
14
HW3 Q5
Q5) Test them with the following matlab routine:
![Page 15: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/15.jpg)
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.
![Page 16: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/16.jpg)
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
![Page 17: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/17.jpg)
17
HW3 Q6
Q6) Compute the condition number of the generalized Vandermonde matrix constructed with p=0,…40 and p+1 Chebychev points.
![Page 18: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/18.jpg)
18
Asymptotic Behavior cond(V) as p->infinity
![Page 19: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/19.jpg)
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
![Page 20: MA557/MA578/CS557 Lecture 10](https://reader035.vdocument.in/reader035/viewer/2022081603/56814e4b550346895dbbd72d/html5/thumbnails/20.jpg)
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…