#!/usr/bin/env python
# coding: utf-8
# # Calculate derivatives in Python
# In[9]:
import sympy as sym
# In[11]:
x = sym.Symbol('x') # Symbolize X
func= x**4+4*x**2+5*x-6 # Function
sym.Derivative(func, x) # Derivative expression
# In[12]:
sym.Derivative(func, x, evaluate=True) # Calculate derivative of func
# In[13]:
func.diff(x) # Or use this for the same
# In[14]:
# Create functions with lambdify
expr= sym.lambdify(x, func)
expr_der=sym.lambdify(x, func.diff(x))
# In[15]:
print(f'value of func at x=5: {expr(5)}')
print(f'derivative of func at x=5: {expr_der(5)}')
0 Comments:
Post a Comment