CoCalc Public Filesprojects_F20 / deriv_Proj7 / Deriv.ipynbOpen with one click!
Author: Julia Burnside
Views : 31
Compute Environment: Ubuntu 20.04 (Default)

Cubic Polynomial Derivatives

The function cubic_derivcubic\_deriv defines two sets of data points to plot:

[x,y][x,y] represents the cubic function f(x)=ax3+bx2+cx+df(x)=ax^3+bx^2+cx+d

[x,z][x,z], represents the above cubic function's first derivative, f(x)=3ax2+2bx+cf'(x)=3ax^2+2bx+c

In [27]:
import matplotlib.pyplot as plt import numpy as np def cube_deriv(a, b, c, d): x=np.linspace(-10, 10, 1000) y=a*x**3+b*x**2+c*x+d z=3*a*x**2+2*b*x+c plt.plot(x,y,color='blue', label='f (x)') plt.plot(x,z, color='red', label='f \' (x)') plt.xlabel('x') plt.ylabel('y') plt.title('Plot of f (x) and f \' (x)') plt.legend() plt.show()
In [28]:
cube_deriv(3,-2,0,5)
In [ ]: