1 [SymPy][] is a [[Python]] library for symbolic mathematics. To give
2 you a feel for how it works, lets extrapolate the extremum location
3 for $f(x)$ given a quadratic model:
9 and three known values:
13 f(a) &= A a^2 + B a + C \\
14 f(b) &= A b^2 + B b + C \\
15 f(c) &= A c^2 + B c + C
19 Rephrase as a matrix equation:
41 So the solutions for $A$, $B$, and $C$ are:
69 Now that we've found the model parameters, we need to find the $x$
70 coordinate of the extremum.
73 \frac{\mathrm{d}f}{\mathrm{d}x} = 2 A x + B \;,
85 Here's the solution in SymPy:
87 >>> from sympy import Symbol, Matrix, factor, expand, pprint, preview
94 >>> M = Matrix([[a**2, a, 1], [b**2, b, 1], [c**2, c, 1]])
95 >>> F = Matrix([[fa],[fb],[fc]])
100 >>> x = factor(expand(x))
103 a *fb - a *fc - b *fa + b *fc + c *fa - c *fb
104 ---------------------------------------------
105 2*(a*fb - a*fc - b*fa + b*fc + c*fa - c*fb)
106 >>> preview(x, viewer='pqiv')
108 Where `pqiv` is the executable for [pqiv][], my preferred image
109 viewer. With a bit of additional factoring, that is:
112 x = \frac{a^2 [f(b)-f(c)] + b^2 [f(c) - f(a)] + c^2 [f(a) - f(b)]}
113 {2\cdot\{a [f(b) - f(c)] + b [f(c) - f(a)] + c [f(a) - f(b)]\}}
116 [SymPy]: http://sympy.org/
117 [pqiv]: http://www.pberndt.com/Programme/Linux/pqiv/
120 [[!tag tags/teaching]]