Menu

[r4556]: / trunk / py4science / workbook / quad_newton.tex  Maximize  Restore  History

Download this file

35 lines (24 with data), 1.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
\section{Newton's method}
\label{sec:quad_newton}
Consider the problem of solving for $t$ in\begin{equation}
\int_{o}^{t}f(s)ds=u\end{equation}
where $f(s)$ is a monotonically increasing function of $s$ and
$u>0$.
This problem can be simply solved if seen as a root finding question.
Let\begin{equation}
g(t)=\int_{o}^{t}f(s)ds-u,\end{equation}
then we just need to find the root for $g(t),$ which is guaranteed
to be unique given the conditions above.
The SciPy library includes an optimization package that contains a
Newton-Raphson solver called \texttt{scipy.optimize.newton.} This
solver can optionally take a known derivative for the function whose
roots are being sought, and in this case the derivative is simply
\begin{equation}
\frac{dg(t)}{dt}=f(t).\end{equation}
For this exercise, implement the solution for the test function\[
f(t)=t\sin^{2}(t),\]
using \[
u=\frac{1}{4}.\]
The listing~\ref{code:quad_newton} contains a skeleton that
includes for comparison the correct numerical value.
\lstinputlisting[label=code:quad_newton,caption={IGNORED}]{problems/quad_newton.py}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.