点击查看代码
import sympy as sp
import numpy as np
import matplotlib.pyplot as plt
# 定义符号
t, x = sp.symbols('t x')
# 计算不定积分
integral = sp.integrate(sp.exp(-t) * t**(x-1), t)
# 选择一个x的值进行绘图(例如,x=2)
x_value = 2
integral_x_value = integral.subs(x, x_value)
# 使用lambdify将sympy表达式转换为numpy可处理的函数
integral_func = sp.lambdify(t, integral_x_value, 'numpy')
# 定义t的范围
t_vals = np.linspace(0, 5, 400)
# 计算对应的y值
y_vals = integral_func(t_vals)
# 绘图
plt.figure(figsize=(10, 6))
plt.plot(t_vals, y_vals, label=f'Integral of $e^{-t}t^{{{x_value-1}}}$')
plt.title('Integral of $e^{-t}t^{x-1}$ for $x={x_value}$')
plt.xlabel('t')
plt.ylabel('Integral value')
plt.grid(True)
plt.legend()
plt.show()
print("学号:2023310143004")