Commit 278f11a9 by Erik Strand

parents 15a787be 8a1ae21a
 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.latex(alt)) print(sp.simplify(sol - alt))
_psets/08.md 0 → 100644

59.8 KB

60.5 KB

58.3 KB

60.3 KB

Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!