Sympy¶
Import¶
Basics¶
Declaring symbols
Declaring functions
Numbers
Useful Functions
Solve¶
Convert to Numerical¶
Lambdify
Substitute
expr = smp.sin(x) + smp.sin(y)
expr.subs([
(x, 10)
])
expr.subs([
(x, 10),
(y, 5)
])
expr.subs([
(x, 10),
(y, smp.sin(x))
])
Calculus¶
Differentiation¶
dfdx = smp.diff(f) ## f = function symbol, which is a function of
dfdx_sub = dfdx.sub([
(g, smp.sin(x))
])
dfdx_sub_value = dfdx_sub.doit()
Integration¶
Indefinite
Definite
Vectors¶
u1, u2, u3 = smp.symbols("u1 u2 u3")
u = smp.Matrix([u1, u2, u3])
v1, v2, v3 = smp.symbols("v1 v2 v3")
v = smp.Matrix([v1, v2, v3])
Fourier Transform (Analytic)¶
Continuous Time & Frequency¶
# symbols need to be defined with correct characteristics
t, f = smp.symbols("t, f", real=True)
k = smp.symbols("k", real=True, positive=True)
x = smp.exp(-k * t**2) * k * t
x
Continuous Time & Discrete Frequency¶
t = smp.symbols("t", real=True)
k, n, T = smp.symbols("k, n, T", real=True, positive=True)
fn = n/T
x = smp.exp(-k * t)