Week 3 - Newton Fix Main Activity
Week 3 - Newton Fix Main Activity
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Part I. Root-finding. Newton's iteration."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Write a function which performs Newton's iteration for a given function
$f(x)$ with known derivative $f'(x)$. Your function should find the root of
$f(x)$ with a predefined absolute accuracy $\\epsilon$. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def newton_iteration(f, fder, x0, eps=1e-5, maxiter=1000):\n",
" \"\"\"Find a root of $f(x) = 0$ via Newton's iteration starting from
x0.\n",
" \n",
" Parameters\n",
" ----------\n",
" f : callable\n",
" The function to find a root of.\n",
" fder : callable\n",
" The derivative of `f`.\n",
" x0 : float\n",
" Initial value for the Newton's iteration.\n",
" eps : float\n",
" The target accuracy. \n",
" The iteration stops when the distance between successive iterates
is below `eps`.\n",
" Default is 1e-5.\n",
" maxiter : int\n",
" The maximum number of iterations (default is 1000.)\n",
" Iterations terminate if the number of iterations exceeds
`maxiter`.\n",
" This parameter is only needed to avoid infinite loops if
iterations wander off.\n",
" \n",
" Returns\n",
" -------\n",
" x : float\n",
" The estimate for the root.\n",
" niter : int\n",
" The number of iterations.\n",
" \"\"\"\n",
" # ... ENTER YOUR CODE HERE ..."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Test I.1 \n",
"\n",
"Test your implementation on a simple example, $f(x) = x^2 - 1$ or
similar. (20% of the total grade)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# ... ENTER YOUR CODE HERE ..."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Test I.2\n",
"\n",
"Now consider a function which has a multiple root. Take $f(x) = (x^2 -
1)^2$ as an example. Implement a modified Newton's iteraion,\n",
"\n",
"$$\n",
"x_{n+1} = x_{n} - m \\frac{f(x_n)}{f'(x_n)}\n",
"$$\n",
"\n",
"and vary $m= 1, 2, 3, 4, 5$. Check the number of iterations required for
convergence within a fixed $\\epsilon$. Are your observations consistent with
the expectation that the convergence is quadratic is $m$ equals the
multiplicity of the root, and is linear otherwise? (40% of the total grade)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# ... ENTER YOUR CODE HERE ..."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Part II. Fixed-point iteration"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Consider the following equation:\n",
"\n",
"$$\n",
"\\sqrt{x} = \\cos{x}\n",
"$$\n",
"\n",
"Plot the left-hand side and right-hand side of this equation, and
localize the root graphically. Estimate the location of the root by visual
inspection of the plot.\n",
"\n",
"Write a function which finds the solution using fixed-point iteration up
to a predefined accuracy $\\epsilon$. Compare the result to an estimate from a
visual inspection.\n",
"\n",
"Next, rewrite the fixed-point problem in the form\n",
"\n",
"$$\n",
"x = x - \\alpha f(x)\n",
"$$\n",
"\n",
"where $\\alpha$ is the free parameter. Check the dependence of the number
of iterations required for a given $\\epsilon$ on $\\alpha$. Compare your
results to an expectation that the optimal value of $\\alpha$ is given by \n",
"\n",
"$$\n",
"\\alpha = \\frac{2}{m + M}\n",
"$$\n",
"\n",
"where $0 < m < |f'(x)| < M$ over the localization interval. (40% of the
total grade)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# ... ENTER YOUR CODE HERE ..."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Part III. Newton's fractal.\n",
"\n",
"(Not graded). \n",
"\n",
"Consider the equation\n",
"\n",
"$$\n",
"x^3 = 1\n",
"$$\n",
"\n",
"It has three solutions in the complex plane, $x_k = \\exp(i\\, 2\\pi k/
3)$, $k = 0, 1, 2$.\n",
"\n",
"The Newton's iterations converge to one of these solutions, depending on
the starting point in the complex plane (to converge to a complex-valued
solution, the iteration needs a complex-valued starting point).\n",
"\n",
"Plot the \\emph{basins of attraction} of these roots on the complex plane
of $x$ (i.e., on the plane $\\mathrm{Re}x$ -- $\\mathrm{Im}x$). To this end,
make a series of calculations, varying the initial conditions on a grid of
points. \n",
"Color the grid in three colors, according to the root, to which
iterations converged."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"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.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
There are many problems with traffic and transportation, such as major injuries and fatalities,
environmental impacts, traffic movement and congestion, parking difficulties, public trans est
problems mentioned is traffic congestion, a severe real-time transportation problem in countries.
Assessing and resolving this issue involv ronmental es using effective intelligent transportation
solutions, which have been introduced and proven to be beneficia lities, environmental impacts,
traffic movement and congestion, parking difficulties, public transport crowding, the inadequacy
of the public, and so-forth. One of the biggest problems mentioned l to some extent in recent
years (Olayode et al., 2020). The existing transportation infrastructure, based on a traditional
traffic control system, frequently fails to function effectively (Boukerche et al., 2020).port
crowding, the inadequacy of the public, and so-forth. One of the biggest problems mentioned is
traffic congestion, a severe real-time transportation problem in countries. Assessing and
resolving this issue involves using effective est problems mentioned is traffic congestion, a
severe real-time transportation problem in countries. Assessing and resolving this issue involves
using effective intelligent transportation solutions, which have been introduced and proven to be
beneficial to some extent in recent years (Olayode et al., 2020). The existing transportation
infrastructure, based on a traditional traffic control system, frequently fails to function effectively
(Boukerche et al., 2020).intelligent transportation solutions, which have been introduced and
proven to be beneficial to some extent in recent years (Olayode et al., 2020). The existing
transportation infrastructure, based on a traditional traffic control system, frequently fails to
function effectively (Boukerche et al., 2020).
There are many problems with traffic and transportation, such as major injuries and fatalities,
environmental impacts, traffic movement and congestion, parking difficulties, public transport
crowding, the inadequacy of the public, and so-forth. One of the biggest problems mentioned is
traffic congestion, a severe real-time transportation problem in countries. Assessing and
resolving this issue involves using effective intelligent transportation solutions, which have been
introduced and proven to be beneficial to some extent in recent years (Olayode et al., 2020). The
existing transportation infrastructure, based on a traditional traffic control system, frequently
fails to function effectively (Boukerche et al., 2020).