Polska wersja
Numerical Differential Equations
winter semester 2017-18
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)
Conference
Supercomputing Frontiers 2018,
ICM University of Warsaw, Warsaw, March 12-15, 2018. Students conference fee: 100PLN.
I am encouraging everybody to participate - specially those interested in real computations (not only of numerical problems).
Oral exam
The dates of the oral exam (II term): Mon 19, 2018 10am-1pm room 5010 (the oficial schedule) and
Wednesday Feb 21, 2018; 11am-12pm room 5010
Note the change of the room.
Exam questions
- 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 and 2D. 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.
- FEM and different boundary conditions for 2nd order elliptic boundary problem: Dirichelt, Neumann, Robin,
mixed. (it is not discussed in Lect Notes. I discussed it during a lecture but I will not ask this question
unless somebody choose it)
- Elements of abstract FEM theory: continuous FEM spaces, affine families of FEM spaces, shape regularity
etc
- 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.
- Pure Neumann boundary conditions for elliptic problems. 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 a student consent
Link to current lab
Evaluation: an oral exam.
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.
- Repeat the problem for 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.
m-file with explicit Euler scheme and a script with some tests:
eulero17.m -
explicit Euler scheme (as written on the board Oct 2, 2017)
eulerz17.m -
implicit Euler scheme - works at least for the nonlinear 2d pendulum ODE -
look at the source - there are examples of a use
(commented out)
exEuler.m -
explicit Euler scheme (in many dimensions) - old tested version
testexEul.m -
basic tests of explicit Euler scheme (in 1D and 2 D)
Lab 2 -
Function lsode() in octave and simple ODE schemes cont. (Tue Oct 23, 2017)
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.
- 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.
midpoint17.m - implementation of midpoint scheme as
in the lab this year
midpoint.m - implementation of midpoint scheme
(old one)
testmidpoint.m
- testing midpoint scheme - order of convergence and instability for long time interval
(for dx/dt=-x with x(0)=1) - using midpoint.m m-file
taylor17.m - implementation of Taylor scheme as
in the lab this year
testlte17.m - tests of the order of LTE for
Euler and midpoint schemes
Lab 3 Experimental testing the order of ODE schemes cont.
Testing starting for multistep schemes (for 2-step Adams-Bashforth).
(Oct 31, 2017)
- 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?
- Repeat the previous problem for the Taylor(2nd order) Heun and modified Eulera schemes for
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 Adams x_a1 computed by explicit Euler) 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 Banch
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
- 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.
adamsb2s17.m
- explicit Adams-Bashforth scheme (of order 2)
testadamsb2s17.m
- tests of explicit Adams-Bashforth scheme (of order 2)
Taylor.m
- explicit onestep Taylor scheme (of order 2)
modEuler.m
- explicit onestep modified Euler - Runge-Kutta scheme of order 2
testAB2start.m
- tests starting value (x^h_1) for explicit Adams-Bashforth
scheme (of order 2)
testmodEul.m
- tests for modified Euler scheme (explicit Runge-Kutta scheme of order 2)
LTEtests.m
- tests for order of local truncation error for some schems e.g. explicit/implicit Euler
Lab 4 (Nov 14 and 21, 2017)- Finite difference method (FDM) 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
- 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 shooting method for y''-d(x)y'- c(x)y=f(x), y(a)=ya; y(b)=yb, a, b, ya,yb given,
c,f given functions on [a,b]
(2 s shoots with y'(a) equal to s_1=0 and s_2=1i.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 z y(0)=1; y(b)=1 for b=1,4,10,15,20. Draw graphs. Compute errors |y(b;s)-yb|.
- Solve using the shootin method:
- -y''+y=f z y(0)=0; y(b)=0 for f=2*sin(x) and b=\pi (we know the solution).
- -y''+y=-2+(1-x*x); y(-1)=0; y(1)=0. (we know the solution).
- -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+t*t)y=sin(x)+ (1+x*x)*sin(x) with y(0)=0 and y(1)=sin(1) (we
know the solution y(x)=sin(x)).
Plot the graphs. Compute |y(b;s)-yb|.
- (homework) Implement the shooting method for y''=F(t,y,y'), y(a)=ya; y(b)=yb.
Use lsode() and fsolve()
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.
linshoot17.m
-m-file with a function linshoot17() solving the linear
boundary value ODE problem: -y''+p(x)y+q(x)y=f(x); y(a)=alpha y(b)=beta
using shooting method
linshoot16.m
-m-file with a function linshoot16() solving the linear
boundary value ODE problem: -y''+p(x)y+q(x)y=f(x); y(a)=alpha y(b)=beta
using shooting method (old version)
testshoot.m
-shooting method for linear
boundary value ODE problem: -y''+c(x)y=0; y(0)=1 y(b)=1 (b=1 - shooting
works fine, b=20 - shooting does not work at all - why?)
shootexample16.m
-script with a function solving the
boundary value ODE problem: y''=y^2; y(0)=1 y(1)=-4 using shooting method
(fsolve() as a nonlinear solver) - note that there are 2 different solutions!
shooting.m
-m-file with a function shooting() solving the
boundary value ODE problem: y''=F(x,y,y'); y(a)=ya y(b)=yb using shooting method
lap1d17.m
-m-file with a function solving the
boundary value ODE problem: -y''+c*y=f in (a,b); y(a)=ya y(b)=yb using FDM method
(equidistant mesh); c constant
fdmdir16.m
function solving -u''+c*u=f(t) with Dirichlet bnd cond : u(a)=alpha u(b)=beta by FDM method (order two), c - nonnegative constant, (old version 2016/17)
fdmdirtest16.m
function testing the order of discrete convergence in discrete L2 and max
norms of FDM schemes for -u''+c*u=f(t) with Dirichlet bnd cond : u(a)=alpha u(b)=beta; c - nonnegative constant, (for
known solution only - using fdmdir16.m function - old version 2016/17)
Lab 6 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 [-1,1] , u=0 on the boundary for the known solution u(x)=\sin(\pi*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,l=-N-1,...,N+1 but for h=0.9/(N+1) and introduce discrete zero bnd conditions for k\in\{0,N+1\}
-
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...
lap1mix17.m
-m-file with a function solving the
boundary value ODE problem: -y''+c*y=f in (a,b); with Dirichlet or mixed bnd
cond. using FDM method
(equidistant mesh); c constant
testsfdmlap1dmix17d.m
- tests of FDM method for -u''=f in (a,b) with mixed bnd (Dirichlet at a and neumann bnd
at b)
- FDM is of order one (Neumann bnd aprox. by backward difference at b)
fdmix16.m
- function solving -u''+c*u=f in (a,b) u'(a)=al u(b)=be
by FDM of order one (Neumann bnd aproox. by forward differnce) or of order two (increased order by using
PDE at left end)
fdmixtest16.m
- function testing order of discrete convergence of FDM solver for -u''+c*u=f in (a,b) u'(a)=al u(b)=be
- solver uses FDM of order one (Neumann bnd aproox. by forward differnce) or of order two (increased order by using
PDE at left end)
fddirng16.m
- function solving -u''+c*u=f in (a,b) u'(a)=al u(b)=be
by FDM with mesh such that right endpoint is x_N < b (b=x_N+0.5*h) -
Dirichlet bnd is approximated straightforwardly u_N=be or by Collatz approximation i.e.
the last FDM equation equals l(b)=be with l(t) linear polynomial st. l(x_k)=u_k for k=N,N-1
fdmdirngtest16.m
- function testing order of discrete convergence of FDM solver for -u''+c*u=f in (a,b) u'(a)=al u'(b)=be
- solver as in fdmdirng16.m
fdmdir2D16.m
- function solving -Laplacian u+c*u=f in (a,b)x(a,b) with zero Dirichelt bnd
by FDM of order two - equidistant mesh with the same step in the both directions
EXAMPLE with u solution = sin(x_1)*sin(x_2), (then f=2*u)
Lab 7 - FEM in 1d
Finite element method (FDM) for -u'' +cu=f on [a,b] with Dirichlet bnd
condition. In 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; 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}
- (extra problem)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.
FEM1dDirSol16.m
- linear 1D FEM solver for -au''+cu=f with Dirichlet bc
- any grid
test1dfem16.m
- some tests of linear 1D FEM solver for -au''+cu=f with Dirichlet bc
Lab 8 -- FD method for parabolic equations in 1D i.e. we discretized
equation u_t-u_{xx}=f by FDM with respect to x - and apply octave ODE
solver (lsode()) to the resulting ODEs system
-
Run the scripts - i.e. solve u_t=u_{xx} for discontinuous u0
- Change the script in order to solve 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 the Dirichelt bnd to Neumann (or mixed Neumann at a and Dirichlet at b)
- 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)
FD1dtest16.m
- octave script with code testing convergence order for FDM
discretization of u_t-u_{xx}=f(t,x) u(a)=al(t) u(b)=be(t) 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)
FDM1DParab17.m
-solver FDM for u_t-u_{xx}=f u(t,a)=uL(t) u(t,b)=uP(t) u(0,x)=u0(x)
FEM1dtest.m
- octave script with code testing convergence order for linear FEM
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 -one can use any
1D traingulation - please test a few different (the ODE solver is lsode() - octave
black box for ODEs)
FDstep.m
- octave script with code testing diffusion in u_t-u_{xx}=0 u(0)=u(pi)=0 u(0,x)= indicator function of [1,2.5]
and tests with same u0 but with force term f<>0 i.e. u_t-u_{xx}=f
nrr15-parab1d.tgz
- octave scripts and functions with code testing the order of convergence 3 basic schemes (ex/imlicit Euler,
Crank-Nicholson)
for u_t-u_{xx}=0 u(a)=ae u(b)=be u(0,x)= u0(x)
with FDM or FEM space discretizations; please read README file in the archive
Lab 9 Finish writing solutions of
old problems or just run my scripts and see what happens.
Solve elliptic problem with the pure Neumann condition.
- Write a function with a FEM (standard P1 element i.e.continuous piecewise
linear) solver for -u''=f in (a,b) u'(a)=g1 u'(b)=g2 for any 1D mesh. Check
discrete compability condition i.e. we approximate \int_a^bf\phi_k \approx
0.5f(x_k)(x_(k+1)-x(k-1))=F_k assuming x_(-1)=x_0 and x_(N+1)=x_N and then we have to
have: \sum_k F_k +g2-g1=0
- Write similar solver but for FDM on equidistant mesh - derivative at the bnd
approximated by 2point stencil, i.e. backward (at b) or forward (at a) FD
FEM1DPureNeu17.m
-tests FEM in 1D for -u''=f in (a,b) u'(a)=g1 u'(b)=g2
(any mesh - please test different e.g. x=0.5*(a+b)-0.5*(b-a)*cos(pi*(linspace(a,b,N+1)-a)/(b-a))
Octave scripts with solution of some problems from our labs
nrrbasic.m - a simple octave script
with basic operations like matrices multiplications etc
eulero17.m -
explicit Euler scheme (as written on the board Oct 2, 2017)
eulerz17.m -
implicit Euler scheme - works at least for the nonlinear 2d pendulum ODE -
look at the source - there are examples of a use
(commented out)
exEuler.m -
explicit Euler scheme (in many dimensions) - old tested version
testexEul.m -
basic tests of explicit Euler scheme (in 1D and 2 D)
midpoint17.m - implementation of midpoint scheme as
in the lab this year
midpoint.m - implementation of midpoint scheme
(old one)
testmidpoint.m
- testing midpoint scheme - order of convergence and instability for long time interval
(for dx/dt=-x with x(0)=1) - using midpoint.m m-file
taylor17.m - implementation of Taylor scheme as
in the lab this year
testlte17.m - tests of the order of LTE for
Euler and midpoint schemes
adamsb2s17.m
- explicit Adams-Bashforth scheme (of order 2)
testadamsb2s17.m
- tests of explicit Adams-Bashforth scheme (of order 2)
AdamsB2step.m
- explicit Adams-Bashforth scheme (of order 2)
Taylor.m
- explicit onestep Taylor scheme (of order 2)
modEuler.m
- explicit onestep modified Euler - Runge-Kutta scheme of order 2
testAB2start.m
- tests starting value (x^h_1) for explicit Adams-Bashforth
scheme (of order 2)
testmodEul.m
- tests for modified Euler scheme (explicit Runge-Kutta scheme of order 2)
EulerLTEtest.m
- tests for order of local truncation error for explicit/implicit Euler
linshoot17.m
-m-file with a function linshoot17() solving the linear
boundary value ODE problem: -y''+p(x)y+q(x)y=f(x); y(a)=alpha y(b)=beta
using shooting method
linshoot16.m
-m-file with a function linshoot16() solving the linear
boundary value ODE problem: -y''+p(x)y+q(x)y=f(x); y(a)=alpha y(b)=beta
using shooting method (old version)
testshoot.m
-shooting method for linear
boundary value ODE problem: -y''+c(x)y=0; y(0)=1 y(b)=1 (b=1 - shooting
works fine, b=20 - shooting doees not work at all - why?)
shootexample16.m
-script with a function solving the
boundary value ODE problem: y''=y^2; y(0)=1 y(1)=-4 using shooting method
(fsolve() as a nonlinear solver) - note that there are 2 different solutions!
shooting.m
-m-file with a function shooting() solving the
boundary value ODE problem: y''=F(x,y,y'); y(a)=ya y(b)=yb using shooting method
lap1d17.m
-m-file with a function solving the
boundary value ODE problem: -y''+c*y=f in (a,b); y(a)=ya y(b)=yb using FDM method
(equidistant mesh); c constant
fdmdir16.m
function solving -u''+c*u=f(t) with Dirichlet bnd cond : u(a)=alpha u(b)=beta by FDM method (order two), c - nonnegative constant, (old version 2016/17)
fdmdirtest16.m
function testing the order of discrete convergence in discrete L2 and max
norms of FDM schemes for -u''+c*u=f(t) with Dirichlet bnd cond : u(a)=alpha u(b)=beta; c - nonnegative constant, (for
known solution only - using fdmdir16.m function - old version 2016/17)
lap1mix17.m
-m-file with a function solving the
boundary value ODE problem: -y''+c*y=f in (a,b); with Dirichlet or mixed bnd
cond. using FDM method
(equidistant mesh); c constant
testsfdmlap1dmix17d.m
- tests of FDM method for -u''=f in (a,b) with mixed bnd (Dirichlet at a and neumann bnd
at b)
- FDM is of order one (Neumann bnd aprox. by backward difference at b)
My home page
Last update: Feb 1, 2018