Moved Taylor Series to supporting notebooks.
This commit is contained in:
parent
b2a3ce2a28
commit
47cce41efb
File diff suppressed because one or more lines are too long
92
Supporting_Notebooks/Linearizing-with-Taylor-Series.ipynb
Normal file
92
Supporting_Notebooks/Linearizing-with-Taylor-Series.ipynb
Normal file
@ -0,0 +1,92 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Linearizing with Taylor Series\n",
|
||||
"\n",
|
||||
"Taylor series represents a function as an infinite sum of terms. The terms are linear, even for a nonlinear function, so we can express any arbitrary nonlinear function using linear algebra. The cost of this choice is that unless we use an infinite number of terms the value we compute will be approximate rather than exact.\n",
|
||||
"\n",
|
||||
"Before applying it to a matrix lets do the Taylor expansion of a real function since this is much easier to visualize. I choose sin(x). The Taylor series for a real or complex function f(x) at x=a is the infinite series\n",
|
||||
"\n",
|
||||
"$$f(x) = f(a) + f'(a)(x-a) + \\frac{f''(a)}{2!}(x-a)^2 + \\, ...\\, + \\frac{f^{(n)}(a)}{n!}(x-a)^n + \\, ...$$\n",
|
||||
"\n",
|
||||
"where $f^{n}$ is the nth derivative of f. To compute the Taylor series for $f(x)=sin(x)$ at $x=0$ Let's first work out the terms for f.\n",
|
||||
"\n",
|
||||
"$$\\begin{aligned}\n",
|
||||
"f^{0}(x) &= sin(x) ,\\ \\ &f^{0}(0) &= 0 \\\\\n",
|
||||
"f^{1}(x) &= cos(x),\\ \\ &f^{1}(0) &= 1 \\\\\n",
|
||||
"f^{2}(x) &= -sin(x),\\ \\ &f^{2}(0) &= 0 \\\\\n",
|
||||
"f^{3}(x) &= -cos(x),\\ \\ &f^{3}(0) &= -1 \\\\\n",
|
||||
"f^{4}(x) &= sin(x),\\ \\ &f^{4}(0) &= 0 \\\\\n",
|
||||
"f^{5}(x) &= cos(x),\\ \\ &f^{5}(0) &= 1\n",
|
||||
"\\end{aligned}\n",
|
||||
"$$\n",
|
||||
"\n",
|
||||
"Now we can substitute these values into the equation.\n",
|
||||
"\n",
|
||||
"$$\\sin(x) = \\frac{0}{0!}(x)^0 + \\frac{1}{1!}(x)^1 + \\frac{0}{2!}(x)^2 + \\frac{-1}{3!}(x)^3 + \\frac{0}{4!}(x)^4 + \\frac{-1}{5!}(x)^5 + ... $$\n",
|
||||
"\n",
|
||||
"And let's test this with some code:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 2,
|
||||
"metadata": {
|
||||
"collapsed": false
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"estimate of sin(.3) is 0.30452025\n",
|
||||
"exact value of sin(.3) is 0.295520206661\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import numpy as np\n",
|
||||
"\n",
|
||||
"x = .3\n",
|
||||
"estimate = x + x**3/6 + x**5/120\n",
|
||||
"exact = np.sin(.3)\n",
|
||||
"\n",
|
||||
"print('estimate of sin(.3) is', estimate)\n",
|
||||
"print('exact value of sin(.3) is', exact)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"This is not bad for only three terms. If you are curious, go ahead and implement this as a Python function to compute the series for an arbitrary number of terms.\n",
|
||||
"\n",
|
||||
"Now we can consider how to linearize a nonlinear "
|
||||
]
|
||||
}
|
||||
],
|
||||
"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.0"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 0
|
||||
}
|
Loading…
Reference in New Issue
Block a user