Skip to content
On this page

python 计算函数导数(derivative)

python
import sympy as sym

x = sym.Symbol('x')

func = x**4+4*x**2+5*x-6

sym.Derivative(func, x)

sym.Derivative(func, x, evaluate=True) # 或者使用 func.diff(x)

# create funcitons with lambdify

expr = sym.lambdify(x, func)

expr_der = sym.lambdify(x, func.diff(x))

print(f'value of func at x=5: {expr(5)}')
print(f'value of func derivative at x=5: {expr_der(5)}')

python 计算函数积分(integration)

python
import sympy as sym

# Define the symbol and function
x = sym.Symbol('x')
func = x**2 + 3*x + 2

# calculate the integral
F = sym.integrate(func, x)

print(f'Integral of {func} is {F}')

Released under the MIT License.