An Introduction to Sympy

Copyright (C) 2020 Andreas Kloeckner

MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Sympy variables are created using unique string identifiers.

One can form expression from symbols. Sympy expressions are made up of numbers, symbols, and sympy functions.

Two expressions may be added together to form a new one.

One can form sympy Matrix objects.

An important Matrix function is eye(n), which forms a $n \times n$ identity matrix.

One can stuff expressions into matrices, too.

One may compute the Jacobian of vector valued functions, too.

Sympy expressions can be evaluated by passing in a Python dictionary mapping Symbol Symbols to specific values.

One can even valuate the Jacobian of functions.

To convert a Sympy Matrix into a Numpy array, one may use the following:

After evaluating an expression in Sympy, the return type is a sympy.Float. However, this is not readily usable by Numpy. Therefore, consider casting sympy.Float to a numpy.float64.

At this point, one cna do all the usual stuff one would in Numpy.

Symp's Lambdify can help increase the speed of Sympy's numerical computations.

Or if it is more convenient to have the function evaluation occur from a list of some sort, the Python * operator on lists can help.