import numpy as np
import 网页链接 as plt
# 定义函数 g(x)
def g(x, a):
return x + a / x - 4
# 定义 x 的范围
x_values = np.linspace(0.1, 10, 400) # x > 0,避免除以零
# 设置不同的 a 值
a_values = [1, 4, 9] # 你可以根据需要调整 a 的值
# 绘制图像
plt.figure(figsize=(10, 6))
for a in a_values:
y_values = g(x_values, a)
plt.plot(x_values, y_values, label=f'a = {a}', color='red') # 设置颜色为红色
# 添加标题和标签
plt.title(r'Plot of $g(x) = x + \frac{a}{x} - 4$ for different values of $a$')
plt.xlabel('x')
plt.ylabel('g(x)')
plt.axhline(0, color='black', linewidth=0.5, linestyle='--') # 绘制 x 轴
plt.axvline(0, color='black', linewidth=0.5, linestyle='--') # 绘制 y 轴
plt.legend()
plt.grid(True)
# plt.xlim(0, 10) # 注释掉,让 Matplotlib 自动调整范围
# plt.ylim(-10, 10) # 注释掉,让 Matplotlib 自动调整范围
# 显示图像
plt.show()
import 网页链接 as plt
# 定义函数 g(x)
def g(x, a):
return x + a / x - 4
# 定义 x 的范围
x_values = np.linspace(0.1, 10, 400) # x > 0,避免除以零
# 设置不同的 a 值
a_values = [1, 4, 9] # 你可以根据需要调整 a 的值
# 绘制图像
plt.figure(figsize=(10, 6))
for a in a_values:
y_values = g(x_values, a)
plt.plot(x_values, y_values, label=f'a = {a}', color='red') # 设置颜色为红色
# 添加标题和标签
plt.title(r'Plot of $g(x) = x + \frac{a}{x} - 4$ for different values of $a$')
plt.xlabel('x')
plt.ylabel('g(x)')
plt.axhline(0, color='black', linewidth=0.5, linestyle='--') # 绘制 x 轴
plt.axvline(0, color='black', linewidth=0.5, linestyle='--') # 绘制 y 轴
plt.legend()
plt.grid(True)
# plt.xlim(0, 10) # 注释掉,让 Matplotlib 自动调整范围
# plt.ylim(-10, 10) # 注释掉,让 Matplotlib 自动调整范围
# 显示图像
plt.show()


