Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs1-24fa
minimathematica
Commits
72ff4744
Commit
72ff4744
authored
10 months ago
by
Adam Blank
Browse files
Options
Download
Email Patches
Plain Diff
add taylor instructions
parent
42c1ad50
master
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/taylor.py
+36
-0
src/taylor.py
with
36 additions
and
0 deletions
+36
-0
src/taylor.py
View file @
72ff4744
...
...
@@ -11,20 +11,56 @@ N = 10
@
cache
def
nth_derivative
(
func
,
n
):
"""self explanatory for now..."""
return
None
@
cache
def
taylor
(
func
,
x
):
"""
Returns the taylor expansion of func as a function of x, centered at 'b'.
Since the 0th term is just the function itself (which we don't have the answer for yet),
it should be replaced with a variable 'q' instead of the actual function.
The expansion should go to N terms (see variable defined above).
"""
return
None
def
taylor_at
(
func
,
b
,
f_at_b
):
"""
Returns taylor(-), evaluated by plugging in f_at_b for 'q' and b for 'b'.
"""
return
None
def
max_error
(
func
,
a
,
x
,
n
=
N
):
"""
Calculates the maximum error of the estimate below using Taylor's Theorem
in the following way.
Taylor's Theorem says that we can upper bound the error of a taylor series with N terms
with the following expression for some a <= c <= x (or x <= c <= a, symmetrically):
error(x) = f^(N + 1)(c) * (x - a)^(N + 1)/(n+1)!
So, if we can find an upper bound for f^(N + 1)(c), then we can upper bound the error.
We consider three cases:
1) f^(N + 1) is increasing on the interval [a, x]. Then, f^(N + 1)(x) is the maximum.
2) f^(N + 1) is decreasing on the interval [a, x]. Then, f^(N + 1)(a) is the maximum.
3) There is a turning point on the interval [a, x]. Then, we need to attempt to find
the maximum in that interval. To do this, we find a zero of f^(N + 2), which indicates
a maximum in f^(N + 1). To do that, we use our newton(-) function from the previous part
on f^(N + 2) with an initial guess of x.
Then, we take the max of the absolute value of each of the 3 cases. This should give us some M,
where M >= f^(N + 1)(c).
Finally, plug M into the equation above for f^(N + 1)(c) and return that value.
zero = newton(nth_derivative(func, n + 2), x, 'x')
"""
return
None
@
cache
def
estimate
(
func
,
x
,
a
,
func_at_a
):
"""
Uses the taylor expansion centered around a to compute an estimate for func(x).
"""
return
None
PI
=
3.14159265358979323846264338327950288419716939937510582097494
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help