Skip to content

Instantly share code, notes, and snippets.

@hamzaavvan
Created October 6, 2019 09:45
Show Gist options
  • Save hamzaavvan/876c4e443d8bafbba24a3898404f935c to your computer and use it in GitHub Desktop.
Save hamzaavvan/876c4e443d8bafbba24a3898404f935c to your computer and use it in GitHub Desktop.
Python Derivative Code (+ Plotting)
# method 1
import sympy as sp
x = sp.Symbol('x')
y = sp.diff(3*x**2+1, x)
print (y)
# method 2
from scipy.misc import derivative
def f(x):
return 3*x**2+1
print(derivative(f, 2.0))
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import sympy as sp
x=sp.Symbol('x')
y= sp.diff(3*x**2+1,x)
def f(x):
return 3*x**2+1
y = np.linspace(-3,3)
plt.plot(y, f(y))
plt.grid()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment