{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Numerical Methods 1\n", "### [Gerard Gorman](http://www.imperial.ac.uk/people/g.gorman), [Matthew Piggott](http://www.imperial.ac.uk/people/m.d.piggott), [Nicolas Barral](http://www.imperial.ac.uk/people/n.barral)" ] }, { "cell_type": "markdown", "metadata": { "collapsed": true }, "source": [ "# Revision exercises" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Question 1\n", "\n", "Below is a extract of shot data from a seismic survey.\n", "\n", "| Time (ms) | Shot |\n", "|-----|-----|\n", "| 0 | -0.021373 |\n", "| 4 | -0.024578 |\n", "| 8 | -0.023914 |\n", "| 12 | -0.018227 |\n", "| 16 | -0.00781 |\n", "| 20 | 0.005602 |\n", "| 24 | 0.019264 |\n", "| 28 | 0.030235 |\n", "| 32 | 0.036059 |\n", "| 36 | 0.035334 |\n", "\n", " 1. Calculate the Lagrange polynomial for these points. Plot both the Lagrange polynomial and the raw data points.\n", " 2. The full shot is available in the file [shot.txt](data/shot.txt) (in the data folder) - where the sample interval is 4ms as above. Note that the file only contains one column as you can calculate the time column yourself. Use cubic-polynomial splines to re-interpolate the data for a sample interval of 7.07ms. Plot both the original shot data and the interpolated time series." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Question 2\n", "\n", "1. Calculate the upper triangular form for the matrix:\n", "\\begin{align*}\n", "A = \\begin{bmatrix}\n", "−5 & 3 & 4\\\\\n", "10 & −8 & −9\\\\\n", "15 & 1 & 2\n", "\\end{bmatrix}\n", "\\end{align*}\n", "\n", "2. Consider the matrix:\n", "\\begin{align*}\n", "C = \\begin{bmatrix}\n", "−5 & 3 & 4\\\\\n", "10 & −8 & −9\\\\\n", "15 & 1 & 2\n", "\\end{bmatrix}\n", "\\end{align*}\n", "Does matrix $C$ have an inverse? If not, then why not? " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Question 3\n", "\n", "Consider the function\n", "$$f(x) = \\dfrac{1}{(x − 0.3)^2 + 0.01} - \\dfrac{1}{(x − 0.8)^2 + 0.04}$$.\n", "\n", "\n", " 1. Write a function that computes the second derivative of $f(x)$ using central differencing. The interface to your function should look like *central_diff2(f, x, h)* where $f$ is the function to be differentiated, $x$ is the position at which the derivative should be estimated, and $h (= \\Delta x)$ is the step size.\n", " 2. Use this function to compute the derivative at $x = 0.5$ for decreasing values of $\\Delta x$. Start with $\\Delta x=1.2$ and keep halving until the relative difference between solutions falls below $1.0^{-6}$ Plot the convergence of the method, i.e. plot $\\Delta x$ against the absolute difference between the analytical value and the finite difference approximation." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Question 4\n", "\n", "Consider the integral:\n", "$$\\int_0^{2\\pi} x^2\\cos(x) dx.$$\n", "\n", "Show how the absolute error between the exact solution and the numerical solution varies with the size of the integration step for the four numerical integration methods: trapezoid rule; Simpson's rule; composite Simpson's rule; and Weddle's rule. Show your result by plotting error against integration step, $dx$." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.2" } }, "nbformat": 4, "nbformat_minor": 1 }