Polska wersja
Numerical Differential Equations
winter semester 2018-19
Time: Tuesday lecture 1415-1545 room 1780 and classes/lab 1605-1735 room 1780 or computer lab 3044 (MIMUW bdg.,
Banacha 2 - entrance - Pasteura Street)
Oral exam
The dates of the oral exam (II term) by an appointment (made preferable by e-mail);
I may be tentatively on Thu Feb 21st, 2019 after 10am in my room 5010. Check this page on Wed Feb 20th,
2019
in the evening.
Exam questions
I will ask 2 questions from the list below - the 1st one may be selected by You, the second by myself.
- One step schemes. Examples and convergence theory.
- Multistep schemes . Examples including Adams schemes.
Convergence theory.
- Stiffness. Definition. Examples of ODEs. Idea of adaptive step control.
- Finite difference method for elliptic equation in 1D. 1D Example: - u''+u=f u(a)=u(b)=0
and detailed convergence analysis of this problem in a discrete maximum norm
- Finite difference method for elliptic equations. 2D Example: -Laplacian u=f , u=0 on boundary.
Abstract convergence analysis: the order of local truncation error and stability. Discrete convergence -
definition and Lax theorem.
- Idea of Finite Element Method. Analysis of convergence of linear finite element in 1D for -u''=f,
u(a)=u(b)=0.
- Elements of abstract FEM theory: Lax Milgram theorem. Cea Lemma. Application to 2d elliptic
boundary problem with homogeneous Dirichlet boundary element.
- Elements of abstract FEM theory: continuous FEM spaces, affine families of FEM spaces, shape regularity
etc
- FEM and different boundary conditions for 2nd order elliptic boundary problem: non-zero Dirichlet, Neumann, Robin,
mixed. (optional; it is not discussed in Lect Notes. I discussed it during a lecture but I will not ask this question
unless somebody choose it)
- Schemes for parabolic differential equations: FDM and FEM in 1D or 2D - an idea, some properties - no proofs
(as in the lecture notes or as was presented in the lecture)
- Basic explicit finite difference schemes for hyperbolic PDEs. Stability and consistency. (if I manage to present it in the last lecture)
- Pure Neumann boundary conditions for -Laplacian u=f. How to solve it using FEM? How to solve the singular linear problem arising there? (optional)
optional - means that this question may be asked only with the student consent
Link to current lab
Evaluation: an oral exam. Two questions from the list of approx. 10-12. One is chosen by me the other by the student.
Syllabus
Numerical methods for
- ordinary differential equations (ODEs)
- elliptic partial differential equations (PDEs)
- evolutionary PDEs (parabolic and hyperbolic of first order)
the following classes of methods are going to be discussed
- one-step and linear multi-step schemes for initial ODEs problems
- finite difference method
- finite element method
There are some computer labs (instead of standard "blackboard" classes)
The course is elementary - it is required to know the basics of liner algebra, mathematical
analysis and theory of ODEs.
It is not necessary to have any knowledge from PDEs theory
all necessary facts will be given during our course
There are lecture notes for this course in Polish.
Lecture notes
(In Polish)
Leszek Marcinkowski, Numeryczne równania różniczkowe, 2010.
Published on-line:
WWW page
(there is a link to pdf file with the lecture notes).
Pdf file with the newest version of the notes.
Please, send me an e-mail with comments if you find any errors, typos etc,
References
Text books
-
Deuflhard, Peter, Bornemann, Folkmar, Scientific Computing with Ordinary Differential Equations,
Series: Texts in Applied Mathematics, Vol. 42, Springer-Verlag, New York, 2002.
(theory of ODEs, ODE schemes, Boundary Value Problems in 1D)
One can download a pdf file from MIMUW computers (valid Dec 2014):
Springer link
-
David F. Griffiths, Desmond J. Higham,
Numerical Methods for Ordinary Differential Equations,
Springer-Verlag, 1st Edition, London, 2010. An elementary textbook on ODE schemes.
One can download a pdf file from MIMUW computers (valid Dec 2014):
Springer link
- Claes Johnson, Numerical solution of partial differential equations by the finite element method,
Cambridge University Press, Cambridge, 1987.
- Randall J. LeVeque, Finite difference methods for ordinary and partial differential
equations, Society for Industrial and Applied Mathematics (SIAM), Philadelphia,
PA, 2007, Steady-state and time-dependent problems.
(numerical schemes for ODES, finite difference methods for elliptic and parabolic PDEs)
- Alfio Quarteroni, Riccardo Sacco, and Fausto Saleri, Numerical mathematics, Texts
in Applied Mathematics, vol. 37, Springer-Verlag, New York, 2000.
(numerical schemes for ODEs and some PDES - hyperbolic nad parabolic)
One can download a pdf file from MIMUW computers (valid Dec 2014):
Springer Link
- John C. Strikwerda, Finite difference schemes and partial
differential equations, second ed., Society for Industrial and Applied
Mathematics (SIAM), Philadelphia, PA,
2004. (FD schemes for PDEs - all types)
Monographs or advanced text books
-
Dietrich Braess, Finite elements, third ed., Cambridge University Press, Cambridge,
2007, Theory, fast solvers, and applications in elasticity theory, Translated from the
German by Larry L. Schumaker. (advanced text book)
- Susanne C. Brenner and L. Ridgway Scott, The mathematical theory of finite element
methods, third ed., Texts in Applied Mathematics, vol. 15, Springer, New York, 2008.
- J. C. Butcher, Numerical methods for ordinary differential equations, second ed.,
John Wiley and Sons Ltd., Chichester, 2008.
-
P. G. Ciarlet and J.-L. Lions (eds.), Handbook of numerical analysis. Vol. II,
Handbook of Numerical Analysis, II, North-Holland, Amsterdam, 1991, Finite element
methods. Part 1.
- Philippe G. Ciarlet, The finite element method for elliptic problems, Classics in
Applied Mathematics, vol. 40, Society for Industrial and Applied Mathematics (SIAM),
Philadelphia, PA, 2002, Reprint of the 1978 original [North-Holland, Amsterdam].
-
E. Hairer, S. P. Norsett, and G. Wanner, Solving ordinary differential equations. I,
second ed., Springer Series in Computational Mathematics, vol. 8, Springer-Verlag,
Berlin, 1993, Nonstiff problems.
- E. Hairer and G. Wanner, Solving ordinary differential equations. II, second ed.,
Springer Series in Computational Mathematics, vol. 14, Springer-Verlag, Berlin,
1996, Stiff and differential-algebraic problems.
-
Bosko S. Jovanovich, Endre Suelli, Analysis of Finite Difference Schemes
For Linear Partial Differential Equations with Generalized Solutions, Springer Series in Computationam
Mathematics, volume 46, Springer , 2014.
Springer link (not available on MIMUW
servers)
- Alfio Quarteroni and Alberto Valli, Numerical approximation of partial differential
equations, Springer Series in Computational Mathematics, vol. 23, Springer-Verlag,
Berlin, 1994.
(FD schemes and FE for PDEs)
One can download a pdf file from MIMUW computers (valid Dec 2014):
Springer Link
- J. W. Thomas, Numerical Partial Differential Equations, Finite Difference
Methods, Texts in Applied Mathmematics, volume 22, Springer, 1995.
Springer link (valid Nov 2016)
LAB
link to Octave (one can download linux
or windows version of octave)
octave-forge - octave extension
octave manual in html
Lab 1 (1st two weeks of classes) Introduction to octave.
Euler's schemes
- Read the code in nrrbasic.m
- Create any matrices 3x4 A i 3x5 B - and then a matrix 3x8 C whose first 3 columns are A and next B.
Extract from C a block D from C(1,1) to C(3,3). Flip colums of D. Write D to a file.
(binary or ASCII) - change D(1,1) to -100 in the ascii-file and read the new matrix to octave'a.
Compute norms of D e.g. 1st, 2nd, Frobenius ones etc.
- Compute discrete max norm of (sin(x))^2 on [0,1] (without using loops).
- Write Euler's schemes for y'=ay y(0)=1, a=1,10,100,-1,-10,-100 on [0,T] - write graphs
for T=1,10,100, compute errors: ae(T;h)=|y(T)-y_h(T)| and ce(T;h)=ae(T;h)/y(T) and
ae(h;h)=|y(h)-y_h(h)| i ce(h,h)=ae(h;h)/y(h).
Print ae(t;h) i ce(t;h) for t\in[0,T] on the display.
m-file with explicit Euler scheme and a script with some tests:
testodelin18.m
- a script with some
tests of the explicit Euler scheme for dx/dt=ax x(t0)=x0 (as written on the board Oct 2, 2018)
Lab 2 - continuation...
Function lsode() in octave and simple ODE schemes cont.
In multistep ODE schemes take x_1,x_2 etc as exact solutions if not take x_k k=1,..,p-
p-1 computed by using some explicite 1-step method of the same order e.g. Taylor scheme for midpoint one.
- Write a function with an implementation of the explicit Euler scheme working for any 1st order ODEs. The INPUT parameters - a handle to the vector field, the ends of the interval, an initial value, no of discrete time points plus one. OUTPUT the vectors of discrete times and the approximations of the discrete solution.
Test the scheme for y'=ay y(0)=1 on [0,T] with a=-1,1,10,-10,100,-100 and T=1,10,100 and h=0.1,0.01,1e-3.
Plot the graphs of the approximation and exact solutions
and compute errors: ae(T;h)=|y(T)-y_h(T)| and ce(T;h)=ae(T;h)/y(T).
Print ae(t;h) i ce(t;h) for t\in[0,T] on the display.
- Repeat the problem for the linear penduulum model: y''=-y z y(0)=0;y'(0)=1 - draw the computed orbits (y,y'). Are they
contained in a circle or periodical?
- Do the same but for y'=1+y; y(0)=0 on [0,T) for T=0.5,1,1.5.
Compute error t=0.5,1.5 for h=0.5,1/4,1/8 etc.
- read help for lsode - draw solutions for y'=-0.1y y(0)=1 on [0,20]using lsode().
Do the same for y'=(cos(x))^2 z y(0)=0 on [0,T] for T=1,10,20 or y'=1+y*y, y(0)=0.
- Draw graphs of solution and its derivative and of orbit (y(t),y'(t)) for y''=-y y(0)=0 y'(0)=1.
Check if (y(T)^2+(y'(T)^2==1 for large T and different h.
- Implement midpoint and Taylor schemes of order 2
for y'=ay, y(0)=1, a=1,10,100,-1,-10,-100 on [0,T] draw the graphs
for T=1,10,100, compute errors for different T etc
Compare the graphs and errors with the results for explicit Euler scheme
- Do the same for
y''=-y, y(0)=0;y'(0)=1 - draw the orbit (y,y'). Are orbits periodical?
Repeat the problem for y''=-sin(y), y(0)=0,y'(0)=1. Are computed solutions periodical?
Compare with lsode() solutions.
- Test error of midpoint for y'=-y, y(0)=1 on [0,T] for growing T with h=0.1,1e-2,1e-3 etc Draw graphs.
- Test experimentally the order of local truncation error of Taylor or midpoint scheme
for all IVP with known solutions: :
y'=ay,y(0)=1; a=-100,-10,-1,1,10,100 for t=1,10,100 (if there is no fl overflow)
do same for y''=y y(0)=0 y'(0)=1; y'=cos^2(y) y(0)=0 for t=1 i 100 itd
Do same for the pendulum eq: y''=-sin(y) y(0)=0 y'(0)=1 taking the lsode() solution as the exact one.
exEuler18.m - implementation of expicit Euler scheme
testexEuler18.m - test of explicit Euler in 1 and 2D
midpoint18.m - implementation of midpoint scheme
taylor18.m - implementation of Taylor scheme
Lab 3 Experimental testing the order of ODE schemes cont.
Testing starting for multistep schemes (for 2-step Adams-Bashforth).
- Plot the solutions of y'=ay y(0)=1 using Taylor or midpoint schemes (e.g. N=20 T=4).
Test the convergence order od Taylor and midpoint scheme for this problem (one can use the scripts from this page...)
- Explicit two-step Adams-Bashforth scheme x.
x(n+1)=x(n)+(h/2)*[3*f(n)-f(n-1)] with f(n)=f(t(n),x(n))
Draw graphs of solutions: y'=-y, y(0)=1 or y''=-y y(0)=0;y'(0)=1
itp (y_1 take as a solution or compute by Heun method).
- Test the order of local truncation error of explicit 2-step Adams-Bashford scheme on
y'=ay, y(0)=1, : a=1,-1.
- Test the convergence order of explicit 2-step Adams-Bashford scheme on
y'=ay, y(0)=1, x_1=exp(ah) : a=1,-1.,1
for T=0.1,1,10,100. (using the method of halving the step i.e.
compute e(T,h)/e(T,h/2) for e(t,h)=||x(T,h)-sol(T)||; x(t,h) approximation
of the soultion sol(T) computed by the scheme using the step h)
Take different x_1: e.g. x_1=exp(ah), x_1 computed by Heun or explicit Euler: x_1=x_0+h*f(t_0,x_0).
Do you see any difference?
- Test the convergence order for Taylor(2nd order), Heun
y(n+1)=y(n)+ 0.5h*(f(n)+f(t(n+1),y(n)+hf(n))
and modified Eulera schemes
y(n+1)=y(n)+ h*f(t(n)+0.5h,y(n)+0.5hf(n))
on the IVP:
y'=ay, y(0)=1, x_1=exp(ah) for a=1,-1 and t=0.1,1,10,100.
- Test the order of convergence of Heun,, implicit two-step Adams and modified Eulera schemes on
y'=1+y^2, y(0)=0 for t=0.1,1,1.5, 1.54. What happens close to pi/2?
- Test the order of convergence of Heuna and modified Eulera schemes on
for y''=-y'', y(0)=0 y'(0)=1 for t=0.1,1,10,100,1000.
Are the computed orbits periodical?
Repeat the problem on y'=-sin(y), y(0)=0, y'(0)=1.
- Write predictor corrector scheme -for explicit and implicit Euler schemes nonlinear system is solved by Banach
iterations: x^{k+1}=x(n)+h*f(x^k,t^k+h) (if x^{k+1}=x^k then x^k=x_(n+1)) for x^0=x(n)+hf(n) (predictor ex. Euler) -
no of nonlinear iterations M should be a parameter - test for M=1,2,3 -It can be written with a stopping criteria
like |x^{k+1}-x(n)-h*f(x^k,t^k+h)|<= h or <= x(n)*h or preset no of iterations e.g. one or two or three.
- Implement 2step Adams-Moulton scheme
x(n+1)=x(n)+(h/12)*(5*f(n+1)+8*f(n)-f(n-1)) with f(n)=f(t(n),x(n))
and test the order of convergence - use 1step
Heun scheme for computing x(1).
- Implement 2step predictor - corrector scheme: take 2step Adams-Bashford as a
predictor and 2-step Adams-Moulton as a corrector. Test the order of convergence
- Repeat tests for explicit 3step Adams-Bashford scheme::
x(n+1)=x(n)+(h/12)*[23*f(n)-16*f(n-1)+5*f(n-2)] with f(n)=f(t(n),x(n))
x(1),x(2) may be computed by Heun scheme (order 2) - or substitute x(t0+h) x(t0+2h) with x(t) the solution of IVP.
testmidpoint18.m - test of midpoint in 1D
AdamsB218.m
- explicit Adams-Bashforth scheme (of order 2)
testAdamsB218.m
- tests of explicit Adams-Bashforth scheme (of order 2)
Heun18.m
- explicit Heun scheme (a Runge-Kutta scheme of order 2)
Lab 4. Stiffness. Shooting method for -u''+bu'+ cu=f with Dirichlet bnd
cond : u(a)=alpha u(b)=beta and for mixed bnf conditions:
u'(a)=alpha u(b)=beta
- Solve some simple problems using lsode() - plot the graphs of the solution or trajectories in 2D cases e.g.
y'=ay y(0)=1; (penduulum equations) y''=-y (linear) or y''=-sin(y) with y(0)=1 y'(0)=0.
- Compare computation times of X(T) for X the solution of dX/dt=AX with X(0)=[1;2]
for the matrix [-1,-10;-1,-11] and T=10,100,1000,1000 etc once using
lsode() with stiff solvers and once with non-stiff (lsode_options("integration
method","non-stiff")). To get real time use: (tic;lsode(..);toc)
- Implement a predictor-corrector scheme based on Heun method (predictor) and trapezoid method (corrector) i.e.
for a known x(n) compute y(n) by the Heun method
y(n+1)=x(n)+ 0.5h*(f(n)+f(t(n+1),x(n)+hf(n))
and then substitute y(n) into (replacing x(n+1) in the rhs of the trapezoid scheme i.e. we get
x(n+1)=x(n)+0.5 h(f(n)+f(t(n+1),y(n+1)). Then test the convergence order for y'=ay a=1,-1, y(0)=1 on [0,1] and [0,10]
- starting with N=20.
- (homework)
One an also change the p-c scheme correcting twice i.e. computing y(n) by Heun method, then
z(k+1)=x(n)+0.5 h(f(n)+f(t(n+1),z(k)) k=0,1 and z(0)=y(n+1) obtaining z(1) which is taken a new approximation of
x(n+1).
We can actually correct many times e.g. p-times i.e. taking k =0,..,p-1 or as many times as long
||z(k+1)-x(n)-0.5 h(f(n)+f(t(n+1),z(k))||>TOL taking e.g. TOL=Ch^2 for some constant C. This is equivalent to solving the equation in one step of the implicit trapezoid method by a version of the Banach iterative method.
(in trapezoid method x(n+1) is a fix point of the function G(y)=x(n)+h*f(t(n+1),y) and our iteration is z(k+1)=G(z(k))).
Implement the p-c scheme which use Heun as the predictor and correct twice (corrector - trapezoid method)
and test the convergence order as before.
predcorr18.m
- predictor-corrector with Heun as the predictor and the trapezoid as the corrector
Lab 5. Shooting method and finite difference method (FDM) for -u''+d(x)u' c(x)u=f with Dirichlet bnd
cond : u(a)=alpha u(b)=beta and for mixed bnf conditions:
u'(a)=alpha u(b)=beta
-
Implement shooting method for y''-d(x)y'- c(x)y=f(x), y(a)=ya; y(b)=yb, a, b, ya,yb given,
d,c,f given functions on [a,b]
(2 shoots with y'(a) equal to s_1=0 and s_2=1 i.e. we solve the equation with
y(a)=ya; y'(a)=s_k - get two solutions for t=b
: y(b;s_k) k=1,2 and hence we compute s such that the solution with y(a)=ya; y'(a)=s_k is such that y(b)=tb).
- Solve by the shooting method:
-y''+y=0; y(0)=1; y(b)=1 for b=1,4,10,15,20. Draw graphs. Compute errors |y(b;s)-yb|.
- Solve using the shooting method:
- -y''+y=f z y(0)=0; y(b)=0 for f=2*sin(x) and b=\pi (the solution can be computed).
- -y''+y=-2+(1-x*x); y(-1)=0; y(1)=0. (the solution can be computed).
- -y''+exp(-x) y =cos(x); y(-1)=0; y(1)=0.
- -y''+ay'+ y =cos(x); y(-1)=0; y(1)=0 for a=0,1,10,100,-1,-10,-100.
- -y''+(1+x*x)*y=sin(x)+ (1+x*x)*sin(x) with y(0)=0 and y(1)=sin(1) (the solution can be computed) y(x)=sin(x)).
Plot the graphs. Compute |y(b;s)-yb|.
- Implement the shooting method for y''=F(t,y,y'), y(a)=ya; y(b)=yb.
Use lsode() and fsolve() or fzero() (or implement your own nonlinear solver e.g. the bisection method)
Test for F(t,y,y')=sin(y), y(0)=1, y(1)=2.
-
Form a tridiagonal symmetric matrix with two on main diagonal and minus one on
sub and superdiagonals: using a loop and the octave function diag()
Form this matrix in a sparse format using the octave function sparse() without using
diag() or forming any full format matrix.
-
Solve the FDM problem -u''+u=0 , u(0)=u(T)=1 on [0,T] for the known solution u(x) (you should copmute
it...) for T=1,5,10,15,20 for N=100 and 1000. Compare with the shooting method.
- Compute the order of local truncation error of standard FDM for -u''=\sin(x) , u(0)=u(\pi)=0
-
Solve the FDM problem -u''=f , u(0)=u(\pi)=0 on [0,\pi] for the known solution u(x)=\sin(x)
on the mesh of 10,20,40,80 points. Compute the discrete error in max and discrete L^2 norms.
- Compute the order of local truncation error of standard FDM for -u''=\sin(x) , u(0)=u(\pi)=0
in L^2 and max discrete norms.
-
Compute the order of error of standard FDM for -u''=\sin(x) , u(0)=u(\pi)=0
in L^2 and max discrete norms by the halving the mesh size method. I.e we compute the error
e_h and e_{h/2} and then check the ratio: e_h/e_{h/2} .
Repeat for discrete H1 norm (discrete L2 norm of difference of u_h) i.e. ||u||_{1,h}^2=\sum_{k=0}^{N-1} h*|D_hu(x_k)|^2
with D_h a forward difference.
testshoot18.m
-shooting method for linear
boundary value ODE problem: -y''+y=0; y(0)=1 y(b)=1 (b=1 - shooting
works fine, b=20 - shooting does not work at all - why?)
testfdmsex18.m
-the simplest FDM method for linear
boundary value ODE problem: -y''+y=0; y(0)=1 y(b)=1 works well for b=1 and 20
(or even larger b)
linshoot18.m
-m-file with a function linshoot18() solving the linear
boundary value ODE problem: -y''+p(x)y+q(x)y=f(x); y(a)=alpha y(b)=beta
Lab 6 and 7. FDM for Poisson equation in 1D cont and in 2D
-
Form the matrix and the right hand side vector for the FDM discretiation of the problem -u''=f on [0,1],
u'(0)=\alpha;u(1)=\beta
picking f , \alpha,\beta for a known solution e.g., u(x)=\sin(x+1) (We would like to avoid sitution that u^{(k)}(\alpha)=0 for any k
which could artificially increase the order of convergence or of the local truncation error).
The Neumann condition at the left end of the interval we approximate by the forward difference. Compute the FDM solution - plot the FDM solution - plot the error - compute the
discrete norms of the error. Check experimentally the order of the error. Compute the error of the local truncation error.
-
Compute the order of error of standard FDM for - u''=f in [0,1] , u=sin(x) on the boundary for the known solution u(x)=\sin(x)
in L^2 and max discrete norms but on NO mesh which is ON THE BOUNDARY e.g. take the mesh (h*k) for k=0,...,N but for h < 1/N and introduce discrete zero bnd conditions for k=0,N.
One can use the old scripts e.g. taking the old mesh but be=sol(1+0.5h) so in fact we solve -u''=f on (0,1+h/2) u(0)=0 u(1+h/2)=sin(1+h/2)
-
Collatz approximation - test on - u''=f in [0,1] , u=0 on the boundary for the known solution u^*(x)=sin(x) or (1-x*x)sin(x), pick the mesh such that x_0=0 but x_N < 1 as in the previous problem
THE FDM scheme: u_0=0, (-u_{k-1}+2u_k-u_{k+1})/(h*h)=f(x_k) k=1,..,N-1. The last equation - Collatz approximation: l1(1)=0=u^*(1) with l1 linear interpolant s.t. l1(x_k)=u_k k=N-1,N.
We have l1(t)=u_{k-1}(t-x_k)/(-h)+u_k(t-x_{k-1})/h.
-
Test the fdm scheme for - u''=f in [-1,1] , u(-1)=0 u'(1)=a for the known solution u^*(x)=(x+1)\sin(x) - standard equidistant mesh, standard 3point stencil inside interval, but increase the order of the scheme at the right end. We add an extra so called ghost point x_{N+1]=1+h
and approximate u'(b) by the central difference getting the equation (u_{N+1}-u_{N-1})/(2h)=a. Test the convergence error in the discrete max norm (and L^2). THis scheme has sense if we can extend the solution outside the interval i.e. if the solution is regular enough up to the boundary.
-
Test the fdm scheme for - u''+cu =f in [a,b] , u(a)=al u'(b)=be for the known solution e.g. u^*(x)=(x+1)\sin(x) - standard equidistant mesh, standard 3point stencil inside interval, but increase the order of the scheme at the right end. We add an extra Taylor expansion term i.e [u(b)-u(b-h)]/h=u'(b)-0.5hu''(b)+O(h^2) i.e. we approximate u'(b)=be by [u(b)-u(b-h)]/h+0.5hu''(b)=be but -u''(b)=f(b)-c*u(b) (assuming that the diff. equation is also valid at x=b) thus our last equation:
by [u(N)-u(N-1)]/h+0.5hc*u(N)=be + 0.5*h*f(b).
Test the convergence error in the discrete max norm (and L^2). This scheme has sense if the solution is regular enough up to the boundary.
-
Form a 5-diagonal symmetric matrix - a FDM discretization of 2D Laplacian on a regular mesh on a square.
-
Solve the FDM problem -Laplacian u=f in [0,1]^2 , u=0 on the boundary for the known solution u(x)=\sin(\pi*x)\sin(\pi*y)
on the mesh of 10,20,40,80 points in each direction. Compute the discrete error in max and discrete L^2 norms.
Plot the error and the FDM solutions.
- (homework) Compute the order of local truncation error of standard FDM for -Laplacian u=f in [0,1]^2 ,
u=0 on the boundary for the known solution u(x)=\sin(\pi*x)\sin(\pi*y)
in L^2 and max discrete norms.
-
Compute the order of error of standard FDM for -Laplacian u=f in [0,1]^2 , u=0 on the boundary for the known solution
u(x)=\sin(\pi*x)\sin(\pi*y)
in L^2 and max discrete norms by the halving the mesh size method. I.e we compute the error
e_h and e_{h/2} and then check the ratio: e_h/e_{h/2} .
-
Compute the order of error of standard FDM for -Laplacian u +c(x,y)u=f in [-1,1]^2 ,
u=0 on the boundary for c(x) nonnegative and discontinuous e.g. c(x,y)=1 for x<0 ; c(x,y)=0 otherwise for
the known solution u(x)=\sin(\pi*x)\sin(\pi*y)
in L^2 and max discrete norms.
-
Compute the order of error of standard FDM for -Laplacian u=f in [-1,1]^2 , u=0 on the boundary
for the known solution u(x) which is of low regularity e.g. C^2 or C^3
- take u(x,y)=\sin(\pi*x)*f(y) with f(x) a function which is a piecewise cubic polynomial on [-1,0]
and [0,1] such that f(-1)=f(1)=0 and f,f',f'' continuous at x=0 . (Hermite interpolation).
Consider the mesh such that there mesh points on the line y=0 and without meshpoints on this line.
- consider a mixed bnd - i.e .on the lower edge put \partial_n u = g_1 and the remaining u=g
- modify the code - test the order of convergence for a known solution (just take the matrix from Dirichlet problem and add
N-1 rows/column (first if bottom edge nodes are forst or lst if bottom edge nodes are numbered at the end)
-
Compute the order of error of standard FDM for -Laplacian u=f in [-1,1]^2 , u=0 on the boundary
for the known solution u(x)=\sin(\pi*x)\sin(\pi*y)
in L^2 and max discrete norms but on NO mesh which is ON THE BOUNDARY e.g. take the mesh (h*k,l*h) for k,l=-N-1,...,N+1
but for h=0.9/(N+1) and introduce discrete zero bnd conditions for k,l\in\{0,N+1\}
- Stability . Compute the matrix norms
L^1_h, L^2_h max - A+cI and her inverse for some c (A FDM matrix of 2D Laplacian
on a square - equidistant mesh) for N=10,20,40,80,160.- Attention!
I can be done using the octave's function norm(). Formally we should put Dirichlet bnd into the matrix...
testlap1d18.m
-tests of the simplest FDM method for linear
boundary value ODE problem: -y''=sin(x); y(0)=0 y(1)=sin(1) (or in the last tests y'(1)=cos(1) )
-consistent mesh. incosisten, inconsistent with Collatz approximation, consistent mesh with the right Neumann bnd - approximated by the backward difference, cetral difference using an extra ghost point, bakcward diff. + extra Taylor expansion term obtained from the differential equation.
lap1d18.m
-solver of the simplest FDM method for linear
boundary value ODE problem: -y''=f; y(a)=al y(b)=be - mesh equidistant with h=(b-a)/N
-3point stencil -the order of the scheme 2
testlap2d18.m
-tests of the simplest FDM method for linear
boundary value PDE problem: -Laplacian u''+c*u=f(x) in (0,pi)^2; u(s)=0 on boundary
-consistent mesh. - 5 point stencil - testing the order in discrete norms for a known solution u(x,y)=sin(x)sin(y)
Lab 8 and 9 - FEM in 1d
Finite element method (FDM) for -u'' +cu=f on [a,b] with Dirichlet bnd
condition. In almost all problems we use linear continuous finite element method i.e conforming P_1 FEM on any mesh (x_0,...,x_N)
with x_0=a and x_n=b.
Weak form: find u\in V_h s.t. \int_a^b u'v' + c*u*v dx =\int_a^b f v dx \forall v \in V_h - in nodal basis
we get the system (A+cB)u=F with A, B (or their submatrices...) obtained from the script below, the rhs for linear FEM we can approximate
by composite trapezoidal rule i.e. F=(f_i)_i with f_i=\int_a^b f\phi_i dx \approx 0.5*f(x_i)(x_{i-1}-x_{i+1}) i=1,...,N-1
(note that in case of equidistant mesh x_k=a+k*h we get f_i=h*f(x_i) as in FDM method...).
The H^1 seminorm and L^2 norm may be computed for u\inV_h as |u|_1^2=u^TAu and ||u||_0^2=u^TMu
- u vector of coefficients in nodal basis.
We computed during classes the stiffness and mass matrices for FEM on the following mesh:
a=x_01;
(1/3)*(|x_k-x_{k+1}|+|x_k-x_{k-1}|) for k=l ;
(1/6)*|x_k-x_l| for |k-l|=1;
assuming x_{-1}=x_0,x_{N+1}=x_N.
\int_a^b phi_k'phi_l'dx=0 for |k-l|>1;
(|x_k-x_{k+1}|^{-1}+|x_k-x_{k-1}|^{-1}) for k=l;
-|x_k-x_l|^{-1} for |k-l|=1
taking $|x_0-x_{-1}|^{-1}=|x_N-x_{N+1}|^{-1}=0$.
- FEM linear 1D; regular grid; Dirichlet homogeneous bnd conditions
Find FEM P_1 spproximation of -u'' +cu=f on [a,b] on a regular grid (x_k=a+k*h h=(b-a)/N) for u=\sin(\pi*x)
and a=0;b=\pi using the trapezoidal rule for rhs for N=10,20,40,80,160 .
Compute the L^2 , discrete \infty and H^1 norms of u_h-I_h u. Check the order by
the halving method. Compare with FDM method.
- FEM linear 1D; simple irregular grid; Dirichlet homogeneous bnd conditions
Find FEM P_1 spproximation of -u'' +cu=f u(a)=0=u(b) on [a,b] on [0,2\pi] for u=x^3*\sin(x)
on a simple irregular grid with
the 2h mesh on [0,\pi] and h mesh on [\pi,2\pi] .
Compute the L^2 , discrete \infty and H^1 norms of u_h-I_h u . Check the order by
the halving step method starting with h0=2\pi/40 .
-
FEM linear 1D; simple irregular grid; Dirichlet homogeneous bnd conditions
Find FEM P_1 spproximation of -u'' +cu=f u(a)=0=u(b) on [0,2\pi] for u=x^3*\sin(x) on the following irregular grid:
take grid getting denser closer to the right end :
take \{x_{n+1}\}\cup\{b\} for x_{n+1}=x_n+h_n\leq b with h_n=(b-a)/(sqrt(n)*N) and x_0=a ,
Compute the L^2 , discrete \infty and H^1 norms of u_h-I_h u . Check the order by
doubling N and computing the ratio of the error for N and 2N .
-
FEM linear 1D; any irregular grid; Dirichlet homogeneous bnd conditions
Find FEM P_1 spproximation of -u'' +cu=f u(a)=0=u(b) on [0,2\pi]
for u=x^3*\sin(x)
Then generate an initial grid as follows:
take any increasing function f such that f(0)=0 f(1)=1 and generate the
initial grid x(k)=a+f(k/N0)*(b-a) k=0,..,N0 obtaining T_0. Knowing grid T_k
generate T_{k+1} as follows - take all grid points of T_k plus midpoints between
grid points f T_k, i.e.add (x(j)+x(j+1))/2 for x(j) a grid point of T_k.
Let u_k be a linear FEM solution for the mesh T_k.
Compute the L^2 , discrete \infty and H^1 norms of u_k-I_k u.
Check the order by
computing the ratio of the respective error for T_k and T_{k+1} .
- FEM linear 1D; regular grid; mixed homogeneous bnd conditions}
Find FEM P_1 spproximation of -u''+cu=f u(0)=0; u'(b)=0
on equaidistant mesh. Compute the rhs using trapezoidal composite quadrature rule. on a regular
grid for u=sin(x) and a=0;b=1 using the trapezoidal rule for rhs for N=10,20,40,80,160 .
Compute the L^2 , discrete \infty and H^1 norms of u_h-I_h u . Check the order by
the halving step method. Compare with FDM methods.
Note that we must take larger submatrices i.e. our FEM space is spanned by (\phi_i)_{i=1}^N (\phi_N is this extra function)
- (extra problem)FEM linear 1D; general elliptic operator regular grid; Dirichlet homogeneous bnd conditions
Find FEM P_1 approximation of -(a(t)u')'+c(t)u=f(t) u(le)=u(re)=0
on equaidistant mesh. Compute the stifness matrix and the rhs vector using trapezoidal
composite quadrature rule. Test the convergence order for the known solution u=\sin(t) , a=1+t^2 , c=0
on [0,\pi] . Repeat the problem taking c(t)=1+t . Weak formulation is
find u \in V_h \int_le^re a(t)u'v' + c(t)uv dx=\int_le^re fvdx forall v \in V_h.
i.e. we get the system Au=F with A=(\int_le^re a(t)\phi_i'\phi_j' + c(t)\phi_i \phi_j)_{i,j}
- real H^1 error - it is easy to compute |u_h-I_hu|_1 (| |_s the H^s nseminorm; u_h discrete solution, I_h u - nodal interpolant of u the real solution (knon)) but to compute an approximation of |u - u_h|_1 (or |u-u_h|_0)
we need a quadrature using not only the nodal points but also the values inside - so we need a function which computes the value of v_j a FEM function at any x and then we can apply some quadrature rule e.g.
octave's integration blackbox: quad().
Write a function which for a real function u (e.g. sin(x)) and v_h a linear fem function i.e.
piecewise linear continuous computes |v_h-u|_s s=0,1. Then repeat the tests of convergence order of 1st few problems using this function.
- FEM linear 1D; regular grid; Dirichlet homogeneous bnd conditions; higher order quadrature rule for
RHS
Find FEM P_1 spproximation of -u'' +cu=f on [a,b] on a regular grid for u=\sin(\pi*x) and
a=0;b=\pi using the Simpson rule for rhs for N=10,20,40,80,160 .
Compute the L^2 , discrete \infty and H^1 norms of u_h-I_h u . Check the order by
the halving method. Compare with the results where the RHS was computed by the trapezoidal rule.
FEM1Dmats.m -
- function creates linear 1D linear FEM matrices for -au''+cu=f i.e.
A=(\int_a^b \phi_k'\phi_l')_{k,l=0}^N and B=(\int_a^b \phi_k\phi_l)_{k,l=0}^N
for \phi_k nodal basis - piecewise linear
- any grid - to get matrix for zero Dirichlet bnd - take submatrices of A and B
The returned matrices are for the nodal basis (\phi_i)_{i=0}^N i.e. includes
the basis functions related to bnd poits, in case of Dirichlet bnd we have to take
submatrices obtained by removing first and last rows/cols.
nodes2pp.m
- converts a linear spline represented in the nodal basis to
the octave representation of piecewise polynomial functions (using mkpp())
- then we can use ppval() to evaluate the value of the spline at any point
testfem18.m
- linear 1D FEM solver for -au''+cu=f with Dirichlet bc
- any grid - we give initial grid and a known solution and
we test discrete errors
testfemNbc18.m
- linear 1D FEM solver for -au''+cu=f with Neumnn bc - works ONLY for c>0!!! -
- any grid - we give initial grid and a known solution and
we test discrete errors
Lab 10 FD method for parabolic equations in 1D i.e. we discretized
equation u_t-u_{xx}=f u(t,a)=ga(t) u(t,b)=gb(t) u(0,x)=u0(x) by FDM with respect to x - and apply octave ODE
solver (lsode()) to the resulting ODEs system
-
solve u_t=u_{xx} x\in(0,pi), t\in(0,T] u(t,0)=u(t,pi)=0, u0(x)=sin(x), for known solution u(t,x)=exp(-t)sin(x).
Use lsode() for ODE solver for FDm semi-discrete problem: U'=-T U where T FDM discretization of
- 2nd derivative i.e. 3diagonal matrix (N-1)x(N-1) with 2/h^2 on the main diagonal, and -1/h^2 od sub and super diagonals, here h=(b-a)/N, U=(u(1),..,u(N-1))^T vector of values at discrete points.
- Compute the error u_h-r_h u for given t_n in a discrete max and L^2 norms. Test the
order of convergence i.e. let e(N)=||u_h-r_h u||_h then compute e(N)/e(2N).
Compute the global discrete error e.g. E_h=max_n ||u_h(t_n,*)-u(t_n,*)|_h
and then the E_h/E_{h/2}.
- Solve u_t=u_{xx} u(t,a)=u(t,b)=0 with discontinuus u0 e.g.on [0,2] u0=0 on [0,1] and
u0(x)=1 on [1,2]. Plot the FDM solution for t=10,1,1e-1,1e-2 for
h=1/10,1/100,1/1000.
- Solve general problem: u_t-u_{xx}=f u(t,a)=ga(t) u(t,b)=gb(t) u(0,x)=u0(x) for any functions
f, ga,gb,u0.
- Using the function from the previous problem solve u_t-u_{xx}=0 with zero bnd and u0 being a peak e.g.
u0(x)=1e10 on t0+[-1e-7,1e7] (t0 given point) and zero otherwise
- change u0 to a unit function of [-1,1] for a=-2, b=2
- Change the Dirichelt bnd to Neumann (or mixed Neumann at a and Dirichlet at b) - test if it works and test convergence order with space step (i.e. takie initial h0 and repeat compution halving the step)
- Implement explicit, implicit Eulers and Crank-Nicholson FDM schemes for u_t-u_{xx}=f u(t,a)=ga(a) u(t,b)=gb(b) u(0,x)=u0(x)
Test them for different valuers of parameters taking f=0 and ga=gb=0. Take different u0 (sin(x), sin(10x), 'a peak' etc)
Test the order of convergence in discrete max norm by the halving steps methos with respecrt to \tau and h. (for a known solution e.g.
u(t)=exp(-t)sin(x) a=0, b=\pi)
FD1dtest.m
- octave script with code testing convergence order for FDM
discretization of u_t-u_{xx}=0 u(0)=u(pi)=0 u(0,x)=sin(x) -
u(t,x)=exp(-t)sin(x) is the solution (the ODE solver is lsode() - octave
black box for ODEs)
FDM1DParab18.m
-solver FDM for u_t-u_{xx}=f u(t,a)=uL(t) u(t,b)=uP(t) u(0,x)=u0(x)
FDM1DParab18DN.m
-solver FDM for u_t-u_{xx}=f u(t,a)=uL(t)(left Dirichlet bc) u'(t,b)=uP(t) (right Neumann bc)
u(0,x)=u0(x)
FDMparabtest18.m
-convergence order tests for semidiscretized (FDM) equation
u_t-u_{xx}=f u(t,a)=0 u(t,b)=0 a=0,b=pi (or Neumann right bc with b=1.5*pi) u'(b,t)=0) u(0,x)=sin(x)
with respect to h (u(t,x)=exp(-t)sin(x) )
FDMparabu0disc18.m
-tests for discontinuous u0
u_t-u_{xx}=f u(t,0)=0 u(t,2)=0 u0 a unit function of [0.6,1.8] or a approx. of Delta Dirac at zero, a=-1,b=1
Octave scripts with solution of some problems from our labs
nrrbasic.m - a simple octave script
with basic operations like matrices multiplications etc
ODE schemes - simple implementations and tests
exEuler18.m - implementation of expicit Euler scheme
testexEuler18.m - test of explicit Euler in 1 and 2D
midpoint18.m - implementation of midpoint scheme
taylor18.m - implementation of Taylor scheme
testmidpoint18.m - test of midpoint in 1D
AdamsB218.m
- explicit Adams-Bashforth scheme (of order 2)
testAdamsB218.m
- tests of explicit Adams-Bashforth scheme (of order 2)
Heun18.m
- explicit Heun scheme (a Runge-Kutta scheme of order 2)
predcorr18.m
- explicit predictor (1 step of Heun scheme) + corrector (1 step of trapezoid scheme)
(is this scheme of order 2?)
testshoot18.m
-shooting method for linear
boundary value ODE problem: -y''+y=0; y(0)=1 y(b)=1 (b=1 - shooting
works fine, b=20 - shooting does not work at all - why?)
linshoot18.m
-m-file with a function linshoot18() solving the linear
boundary value ODE problem: -y''+p(x)y+q(x)y=f(x); y(a)=alpha y(b)=beta
FDM schemes - simple implementations and tests
testfdmsex18.m
-the simplest FDM method for linear
boundary value ODE problem: -y''+y=0; y(0)=1 y(b)=1 works well for b=1 and 20
(or even larger b)
testlap1d18.m
-tests of the simplest FDM method for linear
boundary value ODE problem: -y''=sin(x); y(0)=0 y(1)=sin(1) (or in the last tests y'(1)=cos(1) )
-consistent mesh. incosisten, inconsistent with Collatz approximation, consistent mesh with the right Neumann bnd - approximated by the backward difference, cetral difference using an extra ghost point, bakcward diff. + extra Taylor expansion term obtained from the differential equation.
lap1d18.m
-solver of the simplest FDM method for linear
boundary value ODE problem: -y''=f; y(a)=al y(b)=be - mesh equidistant with h=(b-a)/N
-3point stencil -the order of the scheme 2
testlap2d18.m
-tests of the simplest FDM method for linear
boundary value PDE problem: -Laplacian u''+c*u=f(x) in (0,pi)^2; u(s)=0 on boundary
-consistent mesh. - 5 point stencil - testing the order in discrete norms for a known solution u(x,y)=sin(x)sin(y)
FEM 1D tests
FEM1Dmats.m -
- function creates linear 1D linear FEM matrices for -au''+cu=f i.e.
A=(\int_a^b \phi_k'\phi_l')_{k,l=0}^N and B=(\int_a^b \phi_k\phi_l)_{k,l=0}^N
for \phi_k nodal basis - piecewise linear
- any grid - to get matrix for zero Dirichlet bnd - take submatrices of A and B
The returned matrices are for the nodal basis (\phi_i)_{i=0}^N i.e. includes
the basis functions related to bnd poits, in case of Dirichlet bnd we have to take
submatrices obtained by removing first and last rows/cols.
testfem18.m
- linear 1D FEM solver for -au''+cu=f with Dirichlet bc
- any grid - we give initial grid and a known solution (zero on bnd) and
we get discrete errors - not real!
FDM 1D tests of parabolic solver
FD1dtest.m
- octave script with code testing convergence order for FDM
discretization of u_t-u_{xx}=0 u(0)=u(pi)=0 u(0,x)=sin(x) -
u(t,x)=exp(-t)sin(x) is the solution (the ODE solver is lsode() - octave
black box for ODEs)
FDM1DParab18.m
-solver FDM for u_t-u_{xx}=f u(t,a)=uL(t) u(t,b)=uP(t) u(0,x)=u0(x)
FDM1DParabDN18.m
-solver FDM for u_t-u_{xx}=f u(t,a)=uL(t)(left Dirichlet bc) u'(t,b)=uP(t) (right Neumann bc)
u(0,x)=u0(x)
FDMparabtest18.m
-convergence order tests for semidiscretized (FDM) equation
u_t-u_{xx}=f u(t,a)=0 u(t,b)=0 a=0,b=pi (or Neumann right bc with b=1.5*pi) u'(b,t)=0) u(0,x)=sin(x)
with respect to h (u(t,x)=exp(-t)sin(x) )
FDMparabu0disc18.m
-tests for discontinuous u0
u_t-u_{xx}=f u(t,0)=0 u(t,2)=0 u0 a unit function of [0.6,1.8] or a approx. of Delta Dirac at zero, a=-1,b=1
My home page
Last update: February 19, 2019.