- \n",
"
- To reinforce what you have learnt in lectures and lab classes this semester.\n", "

- \n",
"
- Complete the notebook below, as follows. Click on a question, then from the menu select Insert -> Insert Cell Below. From the dropdown box (next to the \"stop\" symbol) choose whether you wish to insert 'Code' or 'Markdown' (i.e. text with HTML and LaTeX capabilities). Save regularly! \n", " \n", "
- Press Shift-Enter to execute the code in a cell.\n", "\n", "
- Submit via http://somas-uploads.shef.ac.uk/mas212 by midnight on Sunday 10th Dec.
*If you are off-campus, you will need to use a VPN to submit.*\n", "\n", " - This is an open-book test, which means you
**may**consult books, notes and internet resources.**Do not discuss or share your test with anyone**. Copy-and-pasting is**not permitted**, except from the MAS212 code files specified in the questions.*Please give answers in your own words.*\n", " \n", " - This test is worth $5\\%$ of the module mark. Please
**don't**spend an excessive amount of time on it. \n", " \n", " - All submissions will be automatically checked for excessive similarities. Where there is sufficient circumstantial evidence of excessive similarities, a mark of zero can be awarded for this test.\n", "

- \n",
"
- Lecture materials and links on course web page: http://sam-dolan.staff.shef.ac.uk/mas212/\n", "

\n", "

\n", "Define the spectral radius $\\rho(R)$, where $R$ is a square matrix." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

(i) Define the

\n", "(ii) Find the condition number of the matrix below. Is $Ax = b$ well-conditioned or ill-conditioned, in this case?\n", "$$\n", "A = \\begin{bmatrix} 1 & 1/2 & 1/3 \\\\ 1/2 & 1/3 & 1/4 \\\\ 1/3 & 1/4 & 1/5 \\end{bmatrix}\n", "$$\n", "(iii) In your own words, briefly describe the key lesson of Wilkinson's polynomial (Lec. 9). " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

\n", "(b) Approximately, what is the maximum step size $h_{max}$ needed to avoid this problem with the forward Euler method?

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

\n", "

\n", "Apply row operations (as in Lab Class 9) to find the inverse matrix $A^{-1}$ and the solution $x$ in the linear system $A x = b$\n", "where\n", "$$\n", "A = \\begin{pmatrix} 1 & 2 & -3 \\\\ 0 & -1 & 3 \\\\ 2 & 1 & 2 \\end{pmatrix}, \\quad \\quad\n", "b = \\begin{pmatrix} -1 \\\\ 4 \\\\ 9 \\end{pmatrix}\n", "$$\n", "(You may use and adapt the code in

`gauss-jordan1.py`

only from Lab Class 9). "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n", "Use the

\n", "The logistic map is \n", "$$\n", "x_{n+1} = r x_n (1 - x_n) \n", "$$\n", "where $r$ is a real parameter.

\n", "(i) Compute sequences $[x_0, x_1, \\ldots x_{40}]$ with $x_0 = 1/2$, for three parameter choices:

$r = 2.5$, $r = 3.5$ and $r = 3.8$.

\n", "(ii) Plot the three sequences $(n,x_n)$ on the same graph. (Your plot should look something like this.) Briefly comment on what you see." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

For the data set below, find the line of best fit $y = mx + c$, using linear regression.

\n", "(i) Calculate $m$ and $c$ using the formulae in Lecture 8 and print to screen to six decimal places.

\n", "(ii) Plot the data set with the line of best fit.

" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "xs = np.array([ 0.38209254, -0.63095558, -0.27098983, -1.77894635, 0.89872936,\n", " 1.72859985, 1.05801651, 1.8002796 , -0.48903099, -0.86228466,\n", " 0.81095674])\n", "ys = np.array([-0.48265341, -2.13554737, -0.60375244, -1.86415841, 1.27816274,\n", " 2.15335151, 0.7339228 , 1.87013722, 0.33664746, -0.47411395,\n", " 0.81644587])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

\n", "Use

`matplotlib.animation.FuncAnimation()`

to create an animation with 200 frames, showing a standing wave on a string, described by:\n",
"$$\n",
"y(x,t) = \\sin(x) \\sin(t) + 0.2 \\sin(2 x) \\cos(2 t) + 0.1 \\sin(3 x) \\sin(3 t)\n",
"$$\n",
"Each frame of the animation should show $y$ vs $x$ on the domain $x \\in [0, \\pi]$. The frames should be linearly-spaced across $t \\in [0, 4 \\pi]$.\n", "(You may adapt the code in

`sinwave.py`

, as in Lab Class 7, Q2).)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%matplotlib notebook"
]
}
],
"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.1"
}
},
"nbformat": 4,
"nbformat_minor": 1
}