Say I have a function like this:
In [44]: eta(p)
Out[44]:
⎛ Λ⋅(-F(p) + 1) ⎞ -Λ
1 ⎝-Λ⋅(-F(p) + 1) + ℯ - 1⎠⋅ℯ
1 - ───────────────────────── + ─────────────────────────────────────────
⎛ Λ ⎞ -2⋅Λ ⎛ -Λ⎞
- ⎝-Λ + ℯ - 1⎠⋅ℯ + 1 ⎝1 - ℯ ⎠⋅(-F(p) + 1)
I would like to plot the function under some simplifying assumptions. I know that I can use subs() to replace the variables like Lambda with real numbers. That leaves me with F(p).
How can I replace the sympbolic F(p) with an actual numerical function?
You can use lambdify() and make it use numpy.
Here is a simplified example:
import sympy as sy
import numpy as np
import matplotlib.pyplot as plt
t, omega = sy.symbols('t omega')
func = sy.sin(omega * t)
func_sub = func.subs({'omega': 2 * sy.pi})
numpy_func = sy.lambdify(t, func_sub, modules='numpy')
px = np.linspace(0, 1, 1000)
plt.plot(px, numpy_func(px))
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With