SOME INSTRUCTIONS FOR THE PROJECT
LAURI OKSANEN
Contents
1. Installation of required libraries 1
2. Documentation of the libraries 2
3. Getting started 2
4. First task 3
4.1. Solver for 1+1d wave equation with variable zeroth order term 3 5. Second task: inverse problem to determine q(x) 3
References
3
1. Installation of required libraries
It is not strictly necessary to install conda, but I recommend this since we will then be able to run codes in the same environment, and I can help you more easily.
This is what I did on my Ubuntu to install the libraries
1. Install conda1
curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
sh Miniconda3-latest-Linux-x86_64.sh
2. For convenience, create link to the conda binary
ln -s ~/miniconda3/bin/conda .local/bin
3. Prevent conda from activating the base environment by default2 conda config –set auto_activate_base false
4. Create environment called fdm (as in finite difference methods) for the project conda create -n fdm python=3.7
5. Install NumPy
Date: Compiled June 9, 2020.
1Documentation of conda is at https://docs.conda.io/projects/conda/en/latest/ user-guide/index.html
2I think that the installer also asked about this but I chose the wrong option 1
2
6. 7. 8. 9.
10.
11.
• •
L. OKSANEN
conda install -n fdm numpy
Install matplotlib for plotting
conda install -n fdm matplotlib
For running unit tests, install pytest
conda install -n fdm pytest
For convenience, install IPython shell
conda install -n fdm ipython
Activate the fdm environment3
conda activate fdm
To check that NumPy and matplotlib are working, run the code4 from Sec- tions 1.2.1–1.2.2 of [1]
python vib_12.py
or
ipython
%run vib_12.py
To check that pytest is working5 pytest -v vib_12.py
2. Documentation of the libraries https://numpy.org/doc/stable/reference/
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.html
3. Getting started
Read the following sections of [1]: 1.1–2, optionally 1.3 for more advanced plotting techniques (I tried6 only the method in 1.3.3 using Bokeh), optionally 1.4 that is more mathematical and allows you to understand the finite difference method much
3 Running this the first time I was also asked to run conda init bash
4I had to make some quite obvious modifications to the code in the book the get it running, for example, plt.hold had to be removed as this function exists no more (it has been deprecated since version 2.0, see https://matplotlib.org/api/_as_gen/matplotlib.pyplot.hold.html)
5Option -v increases verbosity. For the -s option used in [1], see https://docs.pytest.org/ en/latest/capture.html and the help pytest -h.
6I had to modify the code again a bit: removed everything related to font sizes. To install Bokeh conda install -n fdm bokeh
SOME INSTRUCTIONS FOR THE PROJECT 3
more deeply, 2.1–37 with 2.3.5–7 not that important, and briefly 2.7. You might also want to read 2.10, the analogue of 1.4 for the 1+1d wave equation.
4. First task
4.1. Solver for 1+1d wave equation with variable zeroth order term. Fol-
lowing the method in 2.1–3, and similarly to 2.7, create a solver for the equation ∂2u = ∂2u +q(x)u+f(x,t).
fdm
ary conditions are as in 2.3, that is,
u(x,0)=I(x), ∂u(x,0)=V(x), u(0,t)=0, u(L,t)=0.
∂t
4.1.1. Verification: convergence rates. Choose for example q(x) = 1 + x. Choose a suitable function u satisfying u(0, t) = 0 and u(L, t) = 0 so that the corresponding f , I and V can be computed by hand or by Mathematica8. Verify that the convergence rate 2 is obtained analogously to 2.3.4.
5. Second task: inverse problem to determine q(x) I will give more instructions on this later.
References
[1] H. P. Langtangen and S. Linge. Finite Difference Computing with PDEs – A Modern Software Approach https://hplgit.github.io/fdm-book/doc/web/.
∂t2 ∂x2
The new feature here is the variable zeroth order term q(x)u. The initial and bound-
7Code for 2.3 is at https://github.com/hplgit/fdm-book/blob/master/src/wave/wave1D/ wave1D_u0.py. I tried that the code works, with some simple modifications due to change from Python2 to Python3. I removed viz and guitar functions to keep things simple, see wave 23.py.
8See u exact.nb for an example on how to compute these using Mathematica.