初学者提问 请回答一下吧

请解决一下这道问题吧 咱们就是对咱们来说很困难的一个状态啊 😭谢谢

img


import sympy as sy
import matplotlib.pyplot as plt
import numpy as np

x = sy.symbols('x')
f = x**4 + 3 * x**3 + x**2 + 4 * x
df = sy.diff(f, x)
ddf = sy.diff(f, x, 2)
dddf = sy.diff(f, x, 3)
# 建立空列表用来保存数据
x_value = []
f_value = []
df_value = []
ddf_value = []
dddf_value = []

for i in np.arange(-5, 5.1,0.5):
    x_value.append(i)
    f_value.append(f.subs('x', i))
    df_value.append(df.subs('x', i))
    ddf_value.append(ddf.subs('x', i))
    dddf_value.append(dddf.subs('x', i))

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

p1 = plt.figure()
a1 = p1.add_subplot(2, 2, 1)
plt.title('原函数图像')
plt.xlabel('x')
plt.ylabel('f')
plt.xlim((-5, 5))
plt.ylim((-50, 500))
plt.plot(x_value, f_value, "r")

a2 = p1.add_subplot(2, 2, 2)
plt.title('一阶导函数图像')
plt.xlabel('x')
plt.ylabel('df')
plt.xlim((-5, 5))
plt.ylim((-50, 500))
plt.plot(x_value, df_value, 'b--')

a3 = p1.add_subplot(2, 2, 3)
plt.title('二阶导函数图像')
plt.xlabel('x')
plt.ylabel('ddf')
plt.xlim((-5, 5))
plt.ylim((-50, 500))
plt.plot(x_value, ddf_value, 'go')

a4 = p1.add_subplot(2, 2, 4)
plt.title('三阶导函数图像')
plt.xlabel('x')
plt.ylabel('dddf')
plt.xlim((-5, 5))
plt.ylim((-50, 150))
plt.plot(x_value, dddf_value, 'yv')
plt.show()

img

from matplotlib import pyplot as plt
import numpy as np
import sympy #导入此库,用于求导

x = sympy.symbols('x')
fx = x**4 + 3*x**3 + x**2 + 4*x

y1 = sympy.diff(fx,x)
y2 = sympy.diff(y1,x)
y3 = sympy.diff(y2,x)
# 以上为求导过程

x = np.linspace(-5, 5, 200, endpoint=True)
Fx = eval(str(fx))
Y1 = eval(str(y1))
Y2 = eval(str(y2))
Y3 = eval(str(y3))
 
plt.figure(u'多阶导函数',figsize=(12, 8))

#设置4个子图
ax1 = plt.subplot(2,2,1)
ax2 = plt.subplot(2,2,2)
ax3 = plt.subplot(2,2,3)
ax4 = plt.subplot(2,2,4)

ax1.plot(x,Fx, color='r')
ax1.set_xlabel('x') 
ax1.set_ylabel('f(x)')
ax1.set_title('f(x) = '+str(fx))
plt.tight_layout()   

ax2.plot(x,Y1, color='b')
ax2.set_xlabel('x') 
ax2.set_ylabel("f'(x)")
ax2.set_title("f'(x) = "+str(y1))
plt.tight_layout()

ax3.plot(x,Y2, color='g')
ax3.set_xlabel('x') 
ax3.set_ylabel("f''(x)")
ax3.set_title("f''(x) = "+str(y2))
plt.tight_layout()

ax4.plot(x,Y3, color='y')
ax4.set_xlabel('x') 
ax4.set_ylabel("f'''(x)")
ax4.set_title("f'''(x) = "+str(y3))
plt.tight_layout() 

plt.show()

img