20260109_quadratic_vertex_max-工具opencode模型GLM47
This commit is contained in:
BIN
20260109_quadratic_vertex_max-工具opencode模型GLM47/figure.png
Normal file
BIN
20260109_quadratic_vertex_max-工具opencode模型GLM47/figure.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 68 KiB |
72
20260109_quadratic_vertex_max-工具opencode模型GLM47/plot.py
Normal file
72
20260109_quadratic_vertex_max-工具opencode模型GLM47/plot.py
Normal file
@@ -0,0 +1,72 @@
|
||||
# /// script
|
||||
# requires-python = ">=3.11"
|
||||
# dependencies = ["numpy", "matplotlib"]
|
||||
# ///
|
||||
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# 设置中文字体
|
||||
plt.rcParams["font.sans-serif"] = [
|
||||
"WenQuanYi Micro Hei",
|
||||
"Noto Sans CJK SC",
|
||||
"Microsoft YaHei",
|
||||
"SimHei",
|
||||
"SimSun",
|
||||
"DejaVu Sans",
|
||||
]
|
||||
plt.rcParams["axes.unicode_minus"] = False
|
||||
|
||||
|
||||
# 定义函数
|
||||
def f(x):
|
||||
return -2 * x**2 + 8 * x - 3
|
||||
|
||||
|
||||
# 顶点坐标
|
||||
x_vertex = 2
|
||||
y_vertex = 5
|
||||
|
||||
# 生成 x 值(根据顶点位置合理设置范围)
|
||||
x = np.linspace(0.5, 3.5, 400)
|
||||
y = f(x)
|
||||
|
||||
# 绘图
|
||||
plt.figure(figsize=(10, 7), dpi=150)
|
||||
|
||||
# 绘制函数曲线
|
||||
plt.plot(x, y, "b-", linewidth=2, label="y = -2x² + 8x - 3")
|
||||
|
||||
# 标记顶点
|
||||
plt.plot(
|
||||
x_vertex, y_vertex, "ro", markersize=10, label=f"顶点 ({x_vertex}, {y_vertex})"
|
||||
)
|
||||
|
||||
# 添加顶点坐标标注
|
||||
plt.annotate(
|
||||
f"最大值\n({x_vertex}, {y_vertex})",
|
||||
xy=(x_vertex, y_vertex),
|
||||
xytext=(2.5, 3),
|
||||
arrowprops=dict(arrowstyle="->", color="red", lw=1.5),
|
||||
fontsize=10,
|
||||
color="red",
|
||||
)
|
||||
|
||||
# 添加坐标轴标签和标题
|
||||
plt.xlabel("x", fontsize=12)
|
||||
plt.ylabel("y", fontsize=12)
|
||||
plt.title("二次函数 y = -2x² + 8x - 3 的图像", fontsize=14, pad=15)
|
||||
|
||||
# 设置坐标轴范围
|
||||
plt.xlim(0.5, 3.5)
|
||||
plt.ylim(0, 6)
|
||||
|
||||
# 显示网格
|
||||
plt.grid(True, alpha=0.3, linestyle="--")
|
||||
|
||||
# 添加图例
|
||||
plt.legend(loc="upper right", fontsize=10)
|
||||
|
||||
# 保存图像
|
||||
plt.savefig("figure.png", bbox_inches="tight")
|
||||
print("图像已保存: figure.png")
|
||||
121
20260109_quadratic_vertex_max-工具opencode模型GLM47/report.md
Normal file
121
20260109_quadratic_vertex_max-工具opencode模型GLM47/report.md
Normal file
@@ -0,0 +1,121 @@
|
||||
# 二次函数 $y=-2x^2+8x-3$ 求解报告
|
||||
|
||||
## 1. 🎯 问题描述
|
||||
|
||||
已知二次函数 $y = -2x^2 + 8x - 3$,求:
|
||||
1. 函数的顶点坐标
|
||||
2. 函数的最大值
|
||||
|
||||
## 2. ✅ 最终结论
|
||||
|
||||
这个二次函数的开口向下(因为 $a = -2 < 0$),所以它有一个最高点。通过顶点公式计算,顶点坐标为 $(2, 5)$,这也是函数的最大值点。也就是说,当 $x = 2$ 时,函数取得最大值 $y = 5$。
|
||||
|
||||
## 3. 📈 可视化
|
||||
|
||||

|
||||
|
||||
**图表说明**:
|
||||
|
||||
- 蓝色曲线:函数 $y = -2x^2 + 8x - 3$ 的图像
|
||||
- 红色圆点:函数的顶点 $(2, 5)$,即最大值点
|
||||
|
||||
从图像中可以清晰地看到,抛物线开口向下,在 $x = 2$ 处达到最高点,对应 $y = 5$。
|
||||
|
||||
## 4. 🧠 数学建模与解题过程
|
||||
|
||||
<details>
|
||||
<summary><strong>点击展开</strong></summary>
|
||||
|
||||
### 问题分析
|
||||
|
||||
这是一个关于二次函数性质的问题。对于一般形式的二次函数 $y = ax^2 + bx + c$,其图像是一条抛物线。我们需要:
|
||||
1. 找到抛物线的顶点坐标
|
||||
2. 确定函数的最大值(如果存在)
|
||||
|
||||
### 方法选择
|
||||
|
||||
本题可以采用两种方法求解:
|
||||
|
||||
**方法一:顶点公式法**
|
||||
|
||||
二次函数 $y = ax^2 + bx + c$ 的顶点坐标为:
|
||||
$$x = -\frac{b}{2a}, \quad y = f\left(-\frac{b}{2a}\right)$$
|
||||
|
||||
**方法二:求导法**
|
||||
|
||||
对函数 $y = ax^2 + bx + c$ 求导:
|
||||
$$y' = 2ax + b$$
|
||||
|
||||
令 $y' = 0$,解得临界点:
|
||||
$$x = -\frac{b}{2a}$$
|
||||
|
||||
再通过二阶导数 $y'' = 2a$ 判断极值性质:
|
||||
- 当 $a > 0$ 时,$y'' > 0$,为极小值点
|
||||
- 当 $a < 0$ 时,$y'' < 0$,为极大值点
|
||||
|
||||
### 推导过程
|
||||
|
||||
**使用顶点公式法**:
|
||||
|
||||
已知 $a = -2$,$b = 8$,$c = -3$
|
||||
|
||||
1. 顶点的 x 坐标:
|
||||
$$x = -\frac{b}{2a} = -\frac{8}{2 \times (-2)} = -\frac{8}{-4} = 2$$
|
||||
|
||||
2. 顶点的 y 坐标(将 $x = 2$ 代入原函数):
|
||||
$$y = -2 \times 2^2 + 8 \times 2 - 3 = -2 \times 4 + 16 - 3 = -8 + 16 - 3 = 5$$
|
||||
|
||||
因此,顶点坐标为 $(2, 5)$。
|
||||
|
||||
**使用求导法验证**:
|
||||
|
||||
1. 求一阶导数:
|
||||
$$y' = \frac{d}{dx}(-2x^2 + 8x - 3) = -4x + 8$$
|
||||
|
||||
2. 令 $y' = 0$,解得临界点:
|
||||
$$-4x + 8 = 0 \Rightarrow x = 2$$
|
||||
|
||||
3. 求二阶导数:
|
||||
$$y'' = \frac{d}{dx}(-4x + 8) = -4$$
|
||||
|
||||
4. 由于 $y'' = -4 < 0$,所以 $x = 2$ 是极大值点。
|
||||
|
||||
5. 将 $x = 2$ 代入原函数:
|
||||
$$y = -2 \times 2^2 + 8 \times 2 - 3 = 5$$
|
||||
|
||||
两种方法得到相同的结果。
|
||||
|
||||
### 最大值分析
|
||||
|
||||
因为 $a = -2 < 0$,抛物线开口向下,所以顶点处的 y 值就是函数的最大值。
|
||||
|
||||
$$y_{\text{max}} = 5$$
|
||||
|
||||
</details>
|
||||
|
||||
## 5. 📊 运行结果
|
||||
|
||||
<details>
|
||||
<summary><strong>点击展开</strong></summary>
|
||||
|
||||
```
|
||||
==================================================
|
||||
二次函数:y = -2x² + 8x - 3
|
||||
==================================================
|
||||
|
||||
【方法1:顶点公式】
|
||||
顶点坐标:(2.0, 5.0)
|
||||
|
||||
【方法2:求导法】
|
||||
导数:y' = 8 - 4*x
|
||||
二阶导数:y'' = -4
|
||||
临界点:x = 2
|
||||
代入原函数:y = 5
|
||||
二阶导数:-4 < 0,故为极大值点
|
||||
|
||||
【结论】
|
||||
1. 顶点坐标:(2.0, 5.0)
|
||||
2. 函数最大值:5.0
|
||||
```
|
||||
|
||||
</details>
|
||||
44
20260109_quadratic_vertex_max-工具opencode模型GLM47/solve.py
Normal file
44
20260109_quadratic_vertex_max-工具opencode模型GLM47/solve.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# /// script
|
||||
# requires-python = ">=3.11"
|
||||
# dependencies = ["sympy"]
|
||||
# ///
|
||||
|
||||
import sympy as sp
|
||||
|
||||
# 定义符号(实数)
|
||||
x = sp.symbols("x", real=True)
|
||||
|
||||
# 定义函数
|
||||
y = -2 * x**2 + 8 * x - 3
|
||||
|
||||
# 方法1:通过顶点公式求解
|
||||
# 二次函数 y = ax^2 + bx + c 的顶点公式:x = -b/(2a)
|
||||
a = -2
|
||||
b = 8
|
||||
c = -3
|
||||
|
||||
x_vertex = -b / (2 * a)
|
||||
y_vertex = a * x_vertex**2 + b * x_vertex + c
|
||||
|
||||
# 方法2:通过求导验证
|
||||
dy_dx = sp.diff(y, x)
|
||||
critical_points = sp.solve(dy_dx, x)
|
||||
d2y_dx2 = sp.diff(dy_dx, x)
|
||||
|
||||
print("=" * 50)
|
||||
print("二次函数:y = -2x² + 8x - 3")
|
||||
print("=" * 50)
|
||||
|
||||
print("\n【方法1:顶点公式】")
|
||||
print(f"顶点坐标:({x_vertex}, {y_vertex})")
|
||||
|
||||
print("\n【方法2:求导法】")
|
||||
print(f"导数:y' = {dy_dx}")
|
||||
print(f"二阶导数:y'' = {d2y_dx2}")
|
||||
print(f"临界点:x = {critical_points[0]}")
|
||||
print(f"代入原函数:y = {y.subs(x, critical_points[0])}")
|
||||
print(f"二阶导数:{d2y_dx2} < 0,故为极大值点")
|
||||
|
||||
print("\n【结论】")
|
||||
print(f"1. 顶点坐标:({x_vertex}, {y_vertex})")
|
||||
print(f"2. 函数最大值:{y_vertex}")
|
||||
Reference in New Issue
Block a user