the symbolic computation module
All functions presented herein return a table with a so-called basic string at index 1
and a LaTeX representation of that string at index 2
.
res = symcomp.expr("1/2*x")
print(res[1]) -- "1/2*x"
print(res[2]) -- "\frac{1}{2} x"
- symcomp.evalAt
- symcomp.sub
- symcomp.solve
- symcomp.diff
- symcomp.integrate
- symcomp.identityMatrix
- symcomp.matrix
- symcomp.matrixSub
- symcomp.scalarMul
- symcomp.det
- symcomp.eigenvalues
symcomp.evalAt
can be used to evaluate the functionf(x)
atx=x0
.
res = symcomp.evalAt(f, x, x0)
f = symcomp.expr("-1/2*x**3")
res = symcomp.evalAt(f, "x", 1)
-1/2
subtracts
b
froma
wherea
,b
can be arbitrary expressions (numbers, polynomials etc.).
res = symcomp.sub(a, b)
f = symcomp.expr("2*x**4+7*x-3")
g = symcomp.expr("3*x**3-2*x+7")
res = symcomp.sub(f, g)
2*x**4-3*x**3+9*x-10
returns a collection of values of
x
wheref(x) == 0
.
res = symcomp.solve(f, x)
The return value is a collection of tables as described above, e.g. if a function has zeros -1/2
and 5/2
then the return value will be the following:
{
{ "-1/2", "-\frac{1}{2}" },
{ "5/2", "-\frac{5}{2}" },
}
f = symcomp.expr("x**2-4")
res = symcomp.solve(f, "x")
-2
2
differentiates
f
with respect tox
res = symcomp.diff(f, x)
f = symcomp.expr("-1/2*x**3")
res = symcomp.diff(f, "x")
(-3/2)*x**2
evaluates the integral of
f
froml
tou
with respect tox
.
⚠️ Warning:
As of now,f
must be a polynomial. Other types of functions can not be evaluated yet.
res = symcomp.integrate(f, x)
res = symcomp.integrate(f, x, l, u)
f = symcomp.expr("1/3*x^2")
l = 0
u = 3
symcomp.integrate(f, "x")
symcomp.integrate(f, "x", l, u)
x^3/9
3
i = symcomp.identityMatrix(s)
i3 = symcomp.identityMatrix(3)
[1, 0, 0] [0, 1, 0] [0, 0, 1]
creates a matrix object from a string representation.
⚠️ Warning:
The format of am x n
matrix is[a_11, a_12, ..., a_1n] ... [a_m1, a_m2, ..., a_mn]
. Note that every entry has to be specified in each row.
m = symcomp.matrix(str)
m = symcomp.matrix("[1, 2] [3, 4]")
[1, 2] [3, 4]
subtracts
b
froma
wherea
,b
are two matrices.
res = symcomp.matrixSub(a, b)
a = "[1, 2] [3, 4]"
b = "[0, 1] [0, 2]"
res = symcomp.matrixSub(a, b)
[1, 1] [3, 2]
multiplies the matrix
a
by a scalar valuek
.
res = symcomp.scalarMul(k, a)
a = "[1, 2] [3, 4]"
k = 4
res = symcomp.scalarMul(k, a)
[4, 8] [12, 16]
d = symcomp.det(a)
a = "[1, 2] [3, 4]"
d = symcomp.det(a)
-2
evs = symcomp.eigenvalues(a)
a = "[-5, -3] [-3, 3]"
evs = symcomp.eigenvalues(a)
-6
-4