Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nmm_2020_site
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Erik Strand
nmm_2020_site
Commits
e3709e73
Commit
e3709e73
authored
5 years ago
by
Erik Strand
Browse files
Options
Downloads
Patches
Plain Diff
Verify Numerical Recipes' Nelder-Mead formula
parent
15a787be
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
_code/pset_08/py/lagrange_poly.py
+30
-0
30 additions, 0 deletions
_code/pset_08/py/lagrange_poly.py
with
30 additions
and
0 deletions
_code/pset_08/py/lagrange_poly.py
0 → 100644
+
30
−
0
View file @
e3709e73
import
sympy
as
sp
# Verifying that the Nelder-Mead reflection scheme in Numerical Methods is equivalent to the
# standard presentation.
x
=
sp
.
symbols
(
"
x
"
,
real
=
True
)
x_1
,
x_2
,
x_3
=
sp
.
symbols
(
"
x_1 x_2 x_3
"
,
real
=
True
)
y_1
,
y_2
,
y_3
=
sp
.
symbols
(
"
y_1 y_2 y_3
"
,
real
=
True
)
term_1
=
y_1
*
(
x
-
x_2
)
*
(
x
-
x_3
)
/
(
x_1
-
x_2
)
/
(
x_1
-
x_3
)
term_2
=
y_2
*
(
x
-
x_1
)
*
(
x
-
x_3
)
/
(
x_2
-
x_1
)
/
(
x_2
-
x_3
)
term_3
=
y_3
*
(
x
-
x_1
)
*
(
x
-
x_2
)
/
(
x_3
-
x_1
)
/
(
x_3
-
x_2
)
poly
=
term_1
+
term_2
+
term_3
dpoly
=
sp
.
diff
(
poly
,
x
)
sol
=
sp
.
solve
(
dpoly
,
x
)
assert
(
len
(
sol
)
==
1
)
sol
=
sol
[
0
]
print
(
"
lagrange polynomial
"
)
print
(
sp
.
latex
(
poly
))
print
(
"
derivative
"
)
print
(
sp
.
latex
(
dpoly
))
print
(
"
minimum
"
)
print
(
sp
.
latex
(
sol
))
q
=
(
x_2
-
x_3
)
*
(
y_2
-
y_1
)
r
=
(
x_2
-
x_1
)
*
(
y_2
-
y_3
)
alt
=
x_2
-
((
x_2
-
x_3
)
*
q
-
(
x_2
-
x_1
)
*
r
)
/
2
/
(
q
-
r
)
print
(
sp
.
simplify
(
sol
-
alt
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment