Contact Us!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

| Download
Project: MAT 1630
Views: 215
Kernel: Python 3 (system-wide)

Cubic Polynomial Derivatives

Let f(x)=ax3+bx2+cx+df(x)=ax^3+bx^2+cx+d be a cubic polynomial. Then the derivative of f(x)f(x) is given by f(x)=3ax2+2bx+cf'(x)=3ax^2+2bx+c. We can now use this formula and list comprehensions to plot both f(x)f(x) and f(x)f'(x) in a single plot on the inteval [10,10][-10,10] using at least 10001000 sample points.

import matplotlib.pyplot as plt def cube_deriv(a,b,c,d): x = [-10+20*i/1000 for i in range(1001)] y_f = [a*n**3+b*n**2+c*n+d for n in x] y_f_prime = [3*a*n**2+2*b*n+c for n in x] plt.scatter(x,y_f,color='blue',label="$f(x)$") plt.scatter(x,y_f_prime,color='red',label="$f'(x)$") plt.title("Plot of $f(x)$ and $f'(x)$.") plt.legend() plt.show()
cube_deriv(3,1,-2,5)
Image in a Jupyter notebook