Test of SymPy package.
Language: Python
Start: 2024
I wanted to try SymPy which is a Python package for symbolic mathematics.
Check the equality of two expressions:
expr1 = sp.log(sp.exp(a) + sp.exp(b) + sp.exp(c) + 1)
expr2 = sp.log(sp.exp(b - a) + sp.exp(c - a) + 1/sp.exp(a) + 1) + a
print(sp.simplify(expr1-expr2) == 0)
True
Numeric evaluation:
expr1_num = expr1.subs({a: 700, b: 600, c: 10})
expr1_num.evalf()
700.0
Unit conversion:
expr_u = (5 * spu.cm + 3 * spu.m).simplify()
spu.convert_to(expr_u, spu.m).n()
3.05m
I wrote a code to calculate the partial derivatives for all the variables of a function. This code can be helpful to determine the gradient of a function.
Example, given the function:
where l is a constant and x1, x2, y1, y2, z1, z2 are the variables, the corresponding gradient is:
and the first of the 6 partial derivatives (x1) is:
A playlist of introductory videos.