鱼C论坛

 找回密码
 立即注册
查看: 50|回复: 9

[代数] 求x(x+1)(x+2)(x+3)(x+4)(x+5)的最小值

[复制链接]
回帖奖励 6 鱼币 回复本帖可获得 2 鱼币奖励! 每人限 1 次
发表于 2026-9-28 08:05:30 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
求x(x+1)(x+2)(x+3)(x+4)(x+5)的最小值
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-9-28 12:18:49 | 显示全部楼层

回帖奖励 +2 鱼币

不会
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-9-28 12:34:03 | 显示全部楼层

回帖奖励 +2 鱼币

最小值可能是负数
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2026-9-28 18:16:07 | 显示全部楼层
@FishC,请回答问题:求x(x+1)(x+2)(x+3)(x+4)(x+5)的最小值
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2026-9-29 08:09:16 | 显示全部楼层
  1. import numpy as np
  2. import matplotlib.pyplot as plt

  3. # ============ 0. 中文字体配置 ============
  4. plt.rcParams['font.sans-serif'] = ['SimHei', 'Microsoft YaHei', 'Arial Unicode MS']
  5. plt.rcParams['axes.unicode_minus'] = False

  6. # ============ 1. 定义原函数 f(x) ============
  7. def f(x):
  8.     return x * (x+1) * (x+2) * (x+3) * (x+4) * (x+5)

  9. # ============ 2. 对称换元:t = x + 2.5, u = t^2 ============
  10. def g(u):
  11.     # g(u) = (u - 6.25)(u - 2.25)(u - 0.25)
  12.     return (u - 6.25) * (u - 2.25) * (u - 0.25)

  13. # ============ 3. 精确解析解 ============
  14. # 对 g(u) 求导:g'(u) = 3u^2 - 17.5u + 16.1875 = 0
  15. # 极小值点 u = (35 + 8*sqrt(7)) / 12
  16. u_min_exact = (35 + 8*np.sqrt(7)) / 12
  17. g_min_exact = (u_min_exact - 6.25) * (u_min_exact - 2.25) * (u_min_exact - 0.25)

  18. t_min = np.sqrt(u_min_exact)
  19. x1_exact = -2.5 - t_min
  20. x2_exact = -2.5 + t_min

  21. print("=" * 55)
  22. print("【解析解】")
  23. print("=" * 55)
  24. print(f"极小值点 u* = (35 + 8√7)/12 ≈ {u_min_exact:.6f}")
  25. print(f"最小值 g(u*) = (-160 - 112√7)/27 ≈ {g_min_exact:.6f}")
  26. print(f"对应 t = ±√u* ≈ ±{t_min:.6f}")
  27. print(f"对应 x1 = -2.5 - √u* ≈ {x1_exact:.6f}")
  28. print(f"对应 x2 = -2.5 + √u* ≈ {x2_exact:.6f}")

  29. # ============ 4. 数值验证 ============
  30. print("\n" + "=" * 55)
  31. print("【数值验证】")
  32. print("=" * 55)
  33. print(f"f(x1) = {f(x1_exact):.8f}")
  34. print(f"f(x2) = {f(x2_exact):.8f}")
  35. print(f"f(-2.5) = {f(-2.5):.8f}    (对称中心,非最小值)")
  36. print(f"f(-4.66) = {f(-4.66):.8f}  (近似点)")
  37. print(f"f(-4.67) = {f(-4.67):.8f}")
  38. print(f"f(-4.65) = {f(-4.65):.8f}")

  39. # 用 scipy 数值求最小值做交叉验证
  40. try:
  41.     from scipy.optimize import minimize_scalar
  42.     res = minimize_scalar(f, bounds=(-5, 0), method='bounded')
  43.     print(f"\nscipy 数值最小值: x ≈ {res.x:.6f}, f(x) ≈ {res.fun:.8f}")
  44. except ImportError:
  45.     print("\n(未安装 scipy,跳过数值优化验证)")

  46. # ============ 5. 图形 ============
  47. fig, axes = plt.subplots(1, 2, figsize=(14, 5.5))

  48. # ---- 图1:原函数 f(x) ----
  49. x = np.linspace(-6, 1, 2000)
  50. y = f(x)

  51. ax1 = axes[0]
  52. ax1.plot(x, y, color='blue', linewidth=2, label=r'$f(x)=x(x+1)(x+2)(x+3)(x+4)(x+5)$')
  53. ax1.axhline(0, color='black', linewidth=0.8, linestyle='--')
  54. ax1.axvline(-2.5, color='gray', linewidth=0.8, linestyle=':', label='x = -2.5 (对称中心)')

  55. # 标出整数根
  56. for r in [-5, -4, -3, -2, -1, 0]:
  57.     ax1.plot(r, 0, 'ro', markersize=5)
  58.     ax1.text(r, 3, f'{r}', ha='center', color='red', fontsize=9)

  59. # 标出最小值点
  60. ax1.plot(x1_exact, g_min_exact, 'mo', markersize=10, zorder=5)
  61. ax1.annotate(f'最小值点\n({x1_exact:.3f}, {g_min_exact:.3f})',
  62.              xy=(x1_exact, g_min_exact),
  63.              xytext=(x1_exact + 0.8, g_min_exact - 6),
  64.              fontsize=10, color='purple',
  65.              arrowprops=dict(arrowstyle='->', color='purple'))

  66. ax1.plot(x2_exact, g_min_exact, 'mo', markersize=10, zorder=5)
  67. ax1.annotate(f'({x2_exact:.3f}, {g_min_exact:.3f})',
  68.              xy=(x2_exact, g_min_exact),
  69.              xytext=(x2_exact + 0.3, g_min_exact - 8),
  70.              fontsize=9, color='purple',
  71.              arrowprops=dict(arrowstyle='->', color='purple'))

  72. ax1.set_xlabel('x', fontsize=12)
  73. ax1.set_ylabel('f(x)', fontsize=12)
  74. ax1.set_title('原函数 f(x) 的图像', fontsize=13)
  75. ax1.set_ylim(-25, 15)
  76. ax1.legend(fontsize=9)
  77. ax1.grid(True, alpha=0.3)

  78. # ---- 图2:化简后的三次函数 g(u) ----
  79. u = np.linspace(0, 8, 1000)
  80. gu = g(u)

  81. ax2 = axes[1]
  82. ax2.plot(u, gu, color='darkorange', linewidth=2, label=r'$g(u)=(u-6.25)(u-2.25)(u-0.25)$')
  83. ax2.axhline(0, color='black', linewidth=0.8, linestyle='--')

  84. # 三个根
  85. for r in [0.25, 2.25, 6.25]:
  86.     ax2.plot(r, 0, 'ro', markersize=6)
  87.     ax2.text(r, 1.5, f'{r}', ha='center', color='red', fontsize=9)

  88. # 全局最小值
  89. ax2.plot(u_min_exact, g_min_exact, 'mo', markersize=10, zorder=5)
  90. ax2.annotate(f'全局最小\n(u*≈{u_min_exact:.3f}, {g_min_exact:.3f})',
  91.              xy=(u_min_exact, g_min_exact),
  92.              xytext=(u_min_exact + 0.5, g_min_exact + 3),
  93.              fontsize=10, color='purple',
  94.              arrowprops=dict(arrowstyle='->', color='purple'))

  95. # 局部极大值(数值找)
  96. mask = (u > 0.25) & (u < 2.25)
  97. idx_max = np.argmax(gu[mask])
  98. u_max = u[mask][idx_max]
  99. g_max = gu[mask][idx_max]
  100. ax2.plot(u_max, g_max, 'go', markersize=8)
  101. ax2.annotate(f'局部极大\n({u_max:.3f}, {g_max:.3f})',
  102.              xy=(u_max, g_max),
  103.              xytext=(u_max + 0.8, g_max + 2),
  104.              fontsize=9, color='green',
  105.              arrowprops=dict(arrowstyle='->', color='green'))

  106. ax2.set_xlabel('u = (x + 2.5)&#178;', fontsize=12)
  107. ax2.set_ylabel('g(u)', fontsize=12)
  108. ax2.set_title('化简后的三次函数 g(u) = (u-6.25)(u-2.25)(u-0.25)', fontsize=12)
  109. ax2.legend(fontsize=9)
  110. ax2.grid(True, alpha=0.3)

  111. plt.tight_layout()
  112. plt.savefig('min_solution.png', dpi=150)
  113. plt.show()

  114. print("\n图形已保存为 min_solution.png")
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2026-9-30 02:28:36 From FishC Mobile | 显示全部楼层

回帖奖励 +2 鱼币

0?
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-9-30 11:57:43 | 显示全部楼层

回帖奖励 +2 鱼币

柯西不等式
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2026-9-30 20:51:42 | 显示全部楼层

回帖奖励 +2 鱼币

不会
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2026-10-3 15:00:16 | 显示全部楼层

回帖奖励 +2 鱼币

0
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 6 天前 | 显示全部楼层

回帖奖励 +2 鱼币

应该是-12
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-10-11 02:47

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表