Created
October 6, 2019 09:45
-
-
Save hamzaavvan/876c4e443d8bafbba24a3898404f935c to your computer and use it in GitHub Desktop.
Python Derivative Code (+ Plotting)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%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