260109-test

This commit is contained in:
严浩
2026-01-09 17:01:17 +08:00
parent 888a6d5a24
commit 97154d4b5b
26 changed files with 0 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

View File

@@ -0,0 +1,90 @@
# /// 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
# 创建图形
fig, ax = plt.subplots(figsize=(10, 8), dpi=150)
# 定义函数
def f(x):
return -2*x**2 + 8*x - 3
# 生成 x 数据(根据顶点位置设置合理范围)
x = np.linspace(-1, 5, 500)
y = f(x)
# 绘制函数曲线
ax.plot(x, y, 'b-', linewidth=2.5, label=r'$y = -2x^2 + 8x - 3$')
# 标记顶点
vertex_x, vertex_y = 2, 5
ax.scatter([vertex_x], [vertex_y], color='red', s=120, zorder=5, edgecolors='darkred', linewidths=2)
ax.annotate(f'顶点 ({vertex_x}, {vertex_y})\n最大值',
xy=(vertex_x, vertex_y),
xytext=(vertex_x + 0.8, vertex_y + 0.5),
fontsize=12,
ha='left',
arrowprops=dict(arrowstyle='->', color='red', lw=1.5),
bbox=dict(boxstyle='round,pad=0.3', facecolor='lightyellow', edgecolor='orange'))
# 标记与 x 轴的交点(求根)
# -2x² + 8x - 3 = 0 → x = (8 ± √(64-24))/(-4) = (8 ± √40)/(-4)
discriminant = 64 - 24
x1 = (8 - np.sqrt(discriminant)) / 4
x2 = (8 + np.sqrt(discriminant)) / 4
ax.scatter([x1, x2], [0, 0], color='green', s=100, zorder=5, marker='s', edgecolors='darkgreen', linewidths=2)
ax.annotate(f'x ≈ {x1:.2f}', xy=(x1, 0), xytext=(x1 - 0.3, -1.5), fontsize=10, ha='center',
arrowprops=dict(arrowstyle='->', color='green', lw=1))
ax.annotate(f'x ≈ {x2:.2f}', xy=(x2, 0), xytext=(x2 + 0.3, -1.5), fontsize=10, ha='center',
arrowprops=dict(arrowstyle='->', color='green', lw=1))
# 绘制对称轴
ax.axvline(x=vertex_x, color='purple', linestyle='--', linewidth=1.5, alpha=0.7, label=f'对称轴 x = {vertex_x}')
# 绘制参考线
ax.axhline(y=0, color='gray', linestyle='-', linewidth=0.8, alpha=0.5)
ax.axhline(y=vertex_y, color='orange', linestyle=':', linewidth=1.5, alpha=0.7, label=f'最大值 y = {vertex_y}')
# 填充顶点到 x 轴的区域(可视化最大值)
x_fill = np.linspace(x1, x2, 100)
y_fill = f(x_fill)
ax.fill_between(x_fill, y_fill, 0, alpha=0.15, color='blue', label='函数值 > 0 的区域')
# 设置坐标轴
ax.set_xlim(-1, 5)
ax.set_ylim(-4, 7)
ax.set_xlabel('x', fontsize=14)
ax.set_ylabel('y', fontsize=14)
ax.set_title(r'二次函数 $y = -2x^2 + 8x - 3$ 图像', fontsize=16, fontweight='bold')
# 添加网格
ax.grid(True, linestyle='--', alpha=0.4)
# 添加图例
ax.legend(loc='lower right', fontsize=11, framealpha=0.9)
# 添加说明文字框
textstr = '\n'.join([
'关键信息:',
f'• 顶点坐标: ({vertex_x}, {vertex_y})',
f'• 最大值: {vertex_y}',
f'• 开口方向: 向下 (a < 0)',
f'• 对称轴: x = {vertex_x}'
])
props = dict(boxstyle='round', facecolor='white', edgecolor='gray', alpha=0.9)
ax.text(0.02, 0.98, textstr, transform=ax.transAxes, fontsize=11,
verticalalignment='top', bbox=props)
plt.tight_layout()
plt.savefig('figure.png', bbox_inches='tight', facecolor='white')
plt.close()
print("图像已保存: figure.png")

View File

@@ -0,0 +1,116 @@
# 二次函数 $y = -2x^2 + 8x - 3$ 顶点与最值 - 求解报告
## 1. 🎯 问题描述
已知二次函数 $y = -2x^2 + 8x - 3$,求:
1. 函数的顶点坐标
2. 函数的最大值
## 2. ✅ 最终结论
对于二次函数 $y = -2x^2 + 8x - 3$
**顶点坐标为 $(2, 5)$**。由于二次项系数 $a = -2 < 0$,抛物线开口向下,因此函数在顶点处取得**最大值 $y_{max} = 5$**,此时 $x = 2$。
换句话说,当 $x = 2$ 时,函数值达到最大,为 $5$;当 $x$ 偏离 $2$ 时(无论向左还是向右),函数值都会减小。
## 3. 📈 可视化
![函数图像](figure.png)
**图表说明**
- **蓝色曲线**:二次函数 $y = -2x^2 + 8x - 3$ 的图像
- **红色圆点**:顶点 $(2, 5)$,即函数的最高点
- **绿色方块**:函数与 $x$ 轴的两个交点(零点)
- **紫色虚线**:对称轴 $x = 2$
- **橙色点线**:最大值参考线 $y = 5$
- **浅蓝色区域**:函数值大于零的区域
## 4. 🧠 数学建模与解题过程
<details>
<summary><strong>点击展开</strong></summary>
**问题分析**:这是一个关于二次函数顶点和最值的基本问题。对于一般形式的二次函数 $y = ax^2 + bx + c$,其图像是一条抛物线,顶点坐标和最值可以通过多种方法求解。
**方法选择**:本题采用三种方法相互验证:
### 方法一:顶点公式
对于 $y = ax^2 + bx + c$,顶点坐标为:
$$\left( -\frac{b}{2a}, \frac{4ac - b^2}{4a} \right)$$
本题中 $a = -2$$b = 8$$c = -3$,代入得:
$$x_{顶点} = -\frac{8}{2 \times (-2)} = -\frac{8}{-4} = 2$$
$$y_{顶点} = \frac{4 \times (-2) \times (-3) - 8^2}{4 \times (-2)} = \frac{24 - 64}{-8} = \frac{-40}{-8} = 5$$
### 方法二:求导法
对函数求导:
$$y' = \frac{d}{dx}(-2x^2 + 8x - 3) = -4x + 8$$
令 $y' = 0$,解得 $x = 2$。
将 $x = 2$ 代入原函数:$y = -2(2)^2 + 8(2) - 3 = -8 + 16 - 3 = 5$
### 方法三:配方法
$$y = -2x^2 + 8x - 3$$
$$= -2(x^2 - 4x) - 3$$
$$= -2(x^2 - 4x + 4 - 4) - 3$$
$$= -2(x - 2)^2 + 8 - 3$$
$$= -2(x - 2)^2 + 5$$
顶点式为 $y = -2(x - 2)^2 + 5$,直接读出顶点 $(2, 5)$。
**结论**:三种方法结果一致,顶点为 $(2, 5)$。由于 $a = -2 < 0$,抛物线开口向下,函数在 $x = 2$ 处取得最大值 $5$。
</details>
## 5. 📊 运行结果
<details>
<summary><strong>点击展开</strong></summary>
```
==================================================
二次函数 y = -2x² + 8x - 3 求解
==================================================
【方法1顶点公式】
a = -2, b = 8, c = -3
顶点横坐标 x = -b/(2a) = -8/(2×-2) = 2.0
顶点纵坐标 y = (4ac-b²)/(4a) = 5.0
【方法2SymPy 求导验证】
y' = 8 - 4*x
令 y' = 0解得 x = [2]
将 x = 2 代入原函数y = 5
【方法3配方法】
y = -2x² + 8x - 3
= -2(x² - 4x) - 3
= -2(x² - 4x + 4 - 4) - 3
= -2(x - 2)² + 8 - 3
= -2(x - 2)² + 5
顶点形式y = -2(x - 2)² + 5
==================================================
【最终结果】
==================================================
顶点坐标:(2, 5)
由于 a = -2 < 0抛物线开口向下
函数最大值y_max = 5在 x = 2 处取得)
```
</details>

View File

@@ -0,0 +1,61 @@
# /// script
# requires-python = ">=3.11"
# dependencies = ["sympy"]
# ///
import sympy as sp
# 定义符号变量
x = sp.symbols('x', real=True)
# 定义二次函数
y = -2*x**2 + 8*x - 3
print("=" * 50)
print("二次函数 y = -2x² + 8x - 3 求解")
print("=" * 50)
# 方法1使用配方法/顶点公式
# 对于 y = ax² + bx + c顶点为 (-b/(2a), (4ac-b²)/(4a))
a, b, c = -2, 8, -3
# 顶点横坐标
x_vertex = -b / (2*a)
# 顶点纵坐标(最值)
y_vertex = (4*a*c - b**2) / (4*a)
print(f"\n【方法1顶点公式】")
print(f"a = {a}, b = {b}, c = {c}")
print(f"顶点横坐标 x = -b/(2a) = -{b}/(2×{a}) = {x_vertex}")
print(f"顶点纵坐标 y = (4ac-b²)/(4a) = {y_vertex}")
# 方法2使用 SymPy 求导
print(f"\n【方法2SymPy 求导验证】")
dy = sp.diff(y, x)
print(f"y' = {dy}")
# 令导数为0求驻点
critical_points = sp.solve(dy, x)
print(f"令 y' = 0解得 x = {critical_points}")
if critical_points:
x_val = critical_points[0]
y_val = y.subs(x, x_val)
print(f"将 x = {x_val} 代入原函数y = {y_val}")
# 方法3配方法展示
print(f"\n【方法3配方法】")
print("y = -2x² + 8x - 3")
print(" = -2(x² - 4x) - 3")
print(" = -2(x² - 4x + 4 - 4) - 3")
print(" = -2(x - 2)² + 8 - 3")
print(" = -2(x - 2)² + 5")
print("顶点形式y = -2(x - 2)² + 5")
# 最终结果
print("\n" + "=" * 50)
print("【最终结果】")
print("=" * 50)
print(f"顶点坐标:({int(x_vertex)}, {int(y_vertex)})")
print(f"由于 a = {a} < 0抛物线开口向下")
print(f"函数最大值y_max = {int(y_vertex)}(在 x = {int(x_vertex)} 处取得)")

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

View File

@@ -0,0 +1,66 @@
# /// 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",
"DejaVu Sans",
]
plt.rcParams["axes.unicode_minus"] = False
fig, ax = plt.subplots(figsize=(10, 7), dpi=150)
x = np.linspace(-1, 5, 500)
y = -2 * x**2 + 8 * x - 3
ax.plot(x, y, "b-", linewidth=2, label="$y = -2x^2 + 8x - 3$")
vertex_x, vertex_y = 2, 5
ax.scatter(
[vertex_x],
[vertex_y],
color="red",
s=150,
zorder=5,
label=f"顶点 ({vertex_x}, {vertex_y})",
)
ax.annotate(
f"顶点 ({vertex_x}, {vertex_y})\n最大值: y = {vertex_y}",
xy=(vertex_x, vertex_y),
xytext=(vertex_x + 0.8, vertex_y + 1.5),
fontsize=11,
ha="left",
arrowprops=dict(arrowstyle="->", color="red", lw=1.5),
bbox=dict(boxstyle="round,pad=0.3", facecolor="yellow", alpha=0.7),
)
ax.axhline(y=0, color="gray", linestyle="--", linewidth=1, alpha=0.7)
ax.axvline(x=0, color="gray", linestyle="--", linewidth=1, alpha=0.7)
ax.axvline(
x=vertex_x,
color="green",
linestyle=":",
linewidth=1.5,
alpha=0.7,
label=f"对称轴 x = {vertex_x}",
)
ax.set_xlabel("x", fontsize=12)
ax.set_ylabel("y", fontsize=12)
ax.set_title("二次函数 $y = -2x^2 + 8x - 3$ 的图像", fontsize=14, fontweight="bold")
ax.legend(loc="upper right", fontsize=10)
ax.grid(True, alpha=0.3)
ax.set_xlim(-0.5, 5.5)
ax.set_ylim(-6, 8)
plt.tight_layout()
plt.savefig("figure.png", bbox_inches="tight", dpi=150)
plt.close()
print("图像已保存: figure.png")

View File

@@ -0,0 +1,80 @@
# 二次函数 $y=-2x^2+8x-3$ 求解报告
## 1. 🎯 问题描述
已知二次函数 $y = -2x^2 + 8x - 3$,求:
1. 函数的顶点坐标
2. 函数的最大值
## 2. ✅ 最终结论
二次函数 $y = -2x^2 + 8x - 3$ 的顶点坐标为 $(2, 5)$,由于抛物线开口向下,该顶点即为函数的最大值点,因此函数的最大值为 $y = 5$。
## 3. 📈 可视化
![函数图像](figure.png)
**图表说明**
- 蓝色曲线:函数 $y = -2x^2 + 8x - 3$ 的图像
- 红色圆点:顶点位置 $(2, 5)$,也是函数的最大值点
- 绿色虚线:对称轴 $x = 2$
- 灰色虚线:坐标轴参考线
## 4. 🧠 数学建模与解题过程
<details>
<summary><strong>点击展开</strong></summary>
**问题分析**:这是一个标准的一元二次函数 $y = ax^2 + bx + c$ 的求极值问题。
**方法选择**:使用顶点公式法。对于二次函数 $y = ax^2 + bx + c$,其顶点横坐标为 $x = -\frac{b}{2a}$,顶点纵坐标为函数在该点的函数值。
**推导过程**
已知函数:
$$y = -2x^2 + 8x - 3$$
其中 $a = -2$$b = 8$$c = -3$。
**步骤 1求顶点横坐标**
$$x_{vertex} = -\frac{b}{2a} = -\frac{8}{2 \times (-2)} = -\frac{8}{-4} = 2$$
**步骤 2求顶点纵坐标**
将 $x = 2$ 代入原函数:
$$y_{vertex} = -2(2)^2 + 8(2) - 3 = -2 \times 4 + 16 - 3 = -8 + 16 - 3 = 5$$
**步骤 3判断极值类型**
由于二次项系数 $a = -2 < 0$,抛物线开口向下,因此顶点为最高点,即函数的最大值点。
**结论**
- 顶点坐标:$(2, 5)$
- 函数最大值:$y = 5$
</details>
## 5. 📊 运行结果
<details>
<summary><strong>点击展开</strong></summary>
```
==================================================
二次函数 y = -2x² + 8x - 3 求解结果
==================================================
1. 顶点坐标: (2, 5)
即: x = 2.0, y = 5.0
2. 函数最大值: y = 5.0
由于 a = -2 < 0抛物线开口向下
顶点为最高点,即为最大值点。
3. 对称轴: x = 2.0
==================================================
```
</details>

View File

@@ -0,0 +1,26 @@
# /// script
# requires-python = ">=3.11"
# dependencies = ["sympy"]
# ///
import sympy as sp
x = sp.symbols("x", real=True)
a, b, c = -2, 8, -3
y = a * x**2 + b * x + c
vertex_x = -b / (2 * a)
vertex_y = a * vertex_x**2 + b * vertex_x + c
print("=" * 50)
print("二次函数 y = -2x² + 8x - 3 求解结果")
print("=" * 50)
print(f"\n1. 顶点坐标: ({sp.nsimplify(vertex_x)}, {sp.nsimplify(vertex_y)})")
print(f" 即: x = {vertex_x}, y = {vertex_y}")
print(f"\n2. 函数最大值: y = {vertex_y}")
print(f" 由于 a = -2 < 0抛物线开口向下")
print(f" 顶点为最高点,即为最大值点。")
print(f"\n3. 对称轴: x = {vertex_x}")
print("=" * 50)

View File

@@ -0,0 +1,97 @@
# /// 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
# 创建图形
fig, ax = plt.subplots(figsize=(10, 8), dpi=150)
# 定义函数 y = -2x² + 8x - 3
def f(x):
return -2*x**2 + 8*x - 3
# 顶点坐标
x_vertex = 2
y_vertex = 5
# 生成 x 值范围(以顶点为中心,左右各延伸适当距离)
x = np.linspace(-1, 5, 500)
y = f(x)
# 绘制抛物线
ax.plot(x, y, 'b-', linewidth=2.5, label=r'$y = -2x^2 + 8x - 3$')
# 标注顶点
ax.plot(x_vertex, y_vertex, 'ro', markersize=12, zorder=5, label=f'顶点 ({x_vertex}, {y_vertex})')
ax.annotate(f'顶点\n({x_vertex}, {y_vertex})',
xy=(x_vertex, y_vertex),
xytext=(x_vertex + 0.8, y_vertex + 0.5),
fontsize=12,
ha='left',
arrowprops=dict(arrowstyle='->', color='red', lw=1.5))
# 绘制对称轴
ax.axvline(x=x_vertex, color='green', linestyle='--', linewidth=1.5, alpha=0.7, label=f'对称轴 x = {x_vertex}')
# 绘制最大值水平线
ax.axhline(y=y_vertex, color='orange', linestyle=':', linewidth=1.5, alpha=0.7, label=f'最大值 y = {y_vertex}')
# 绘制坐标轴
ax.axhline(y=0, color='gray', linewidth=0.8)
ax.axvline(x=0, color='gray', linewidth=0.8)
# 求与 x 轴的交点(如果有)
# -2x² + 8x - 3 = 0
# x = (8 ± √(64-24)) / (-4) = (8 ± √40) / (-4)
discriminant = 64 - 24 # b² - 4ac = 64 - 24 = 40
x1 = (8 - np.sqrt(discriminant)) / 4
x2 = (8 + np.sqrt(discriminant)) / 4
ax.plot([x1, x2], [0, 0], 'g^', markersize=10, label=f'与x轴交点')
ax.annotate(f'({x1:.2f}, 0)', xy=(x1, 0), xytext=(x1-0.3, -1.5), fontsize=10, ha='center')
ax.annotate(f'({x2:.2f}, 0)', xy=(x2, 0), xytext=(x2+0.3, -1.5), fontsize=10, ha='center')
# 与 y 轴的交点
y_intercept = f(0)
ax.plot(0, y_intercept, 'ms', markersize=10, label=f'与y轴交点 (0, {y_intercept})')
# 设置坐标轴范围
ax.set_xlim(-1.5, 5.5)
ax.set_ylim(-5, 7)
# 设置网格
ax.grid(True, linestyle='--', alpha=0.5)
# 设置标签和标题
ax.set_xlabel('x', fontsize=14)
ax.set_ylabel('y', fontsize=14)
ax.set_title(r'二次函数 $y = -2x^2 + 8x - 3$ 的图像', fontsize=16, fontweight='bold')
# 添加图例
ax.legend(loc='lower right', fontsize=11)
# 添加关键信息文本框
textstr = '\n'.join([
r'$y = -2x^2 + 8x - 3$',
r'$= -2(x-2)^2 + 5$',
'',
f'顶点: (2, 5)',
f'最大值: 5',
f'对称轴: x = 2'
])
props = dict(boxstyle='round', facecolor='wheat', alpha=0.8)
ax.text(0.02, 0.98, textstr, transform=ax.transAxes, fontsize=11,
verticalalignment='top', bbox=props)
# 保存图像
plt.tight_layout()
plt.savefig('figure.png', bbox_inches='tight', dpi=150)
plt.close()
print("图像已保存: figure.png")

View File

@@ -0,0 +1,134 @@
# 二次函数 $y = -2x^2 + 8x - 3$ 求解报告
## 1. 🎯 问题描述
已知二次函数 $y = -2x^2 + 8x - 3$,求:
1. 函数的顶点坐标
2. 函数的最大值
## 2. ✅ 最终结论
这是一个开口向下的抛物线(因为二次项系数 $a = -2 < 0$),通过配方可以将其化为顶点式 $y = -2(x-2)^2 + 5$。
**顶点坐标为 $(2, 5)$**,这意味着抛物线的对称轴是直线 $x = 2$。
由于抛物线开口向下,函数在顶点处取得**最大值 $y_{\max} = 5$**,此时 $x = 2$。
## 3. 📈 可视化
![函数图像](figure.png)
**图表说明**
- **蓝色曲线**:二次函数 $y = -2x^2 + 8x - 3$ 的图像
- **红色圆点**:顶点 $(2, 5)$,即函数取得最大值的位置
- **绿色虚线**:对称轴 $x = 2$
- **橙色点线**:最大值水平线 $y = 5$
- **绿色三角**:与 $x$ 轴的两个交点
- **紫色方块**:与 $y$ 轴的交点 $(0, -3)$
## 4. 🧠 数学建模与解题过程
<details>
<summary><strong>点击展开</strong></summary>
### 问题分析
这是一个标准的二次函数求顶点问题。二次函数的一般形式为 $y = ax^2 + bx + c$,其中:
- $a = -2$(决定开口方向和宽窄)
- $b = 8$
- $c = -3$
### 方法一:配方法
将二次函数化为顶点式 $y = a(x-h)^2 + k$
$$
\begin{aligned}
y &= -2x^2 + 8x - 3 \\
&= -2(x^2 - 4x) - 3 \\
&= -2(x^2 - 4x + 4 - 4) - 3 \\
&= -2(x - 2)^2 + 8 - 3 \\
&= -2(x - 2)^2 + 5
\end{aligned}
$$
从顶点式可直接读出:顶点坐标为 $(2, 5)$。
### 方法二:公式法
对于二次函数 $y = ax^2 + bx + c$,顶点坐标公式为:
$$
x_{\text{顶点}} = -\frac{b}{2a} = -\frac{8}{2 \times (-2)} = -\frac{8}{-4} = 2
$$
将 $x = 2$ 代入原函数:
$$
y_{\text{顶点}} = -2 \times 2^2 + 8 \times 2 - 3 = -8 + 16 - 3 = 5
$$
### 方法三:求导法(微积分验证)
对函数求导:
$$
y' = \frac{d}{dx}(-2x^2 + 8x - 3) = -4x + 8
$$
令 $y' = 0$,解得 $x = 2$。
二阶导数 $y'' = -4 < 0$,确认 $x = 2$ 处为极大值点。
### 最大值判断
由于 $a = -2 < 0$,抛物线开口向下,函数在顶点处取得最大值:
$$
y_{\max} = 5 \quad (\text{当 } x = 2 \text{ 时})
$$
</details>
## 5. 📊 运行结果
<details>
<summary><strong>点击展开</strong></summary>
```
==================================================
二次函数 y = -2x² + 8x - 3 求解
==================================================
1. 顶点坐标
使用公式 x = -b/(2a) = -8/(2×-2) = 2.0
代入求 y = -2×2.0² + 8×2.0 + (-3) = 5.0
顶点坐标: (2, 5)
2. 函数最大值
由于 a = -2 < 0抛物线开口向下
函数在顶点处取得最大值
最大值: y_max = 5
==================================================
SymPy 符号计算验证
==================================================
导数: y' = 8 - 4*x
令 y' = 0解得 x = [2]
二阶导数: y'' = -4 < 0确认为最大值点
顶点坐标: (2, 5)
最大值: 5
==================================================
配方形式验证
==================================================
配方形式: y = -2(x - 2)² + 5
展开验证: -2*x**2 + 8*x - 3
与原式相等: True
```
</details>

View File

@@ -0,0 +1,71 @@
# /// script
# requires-python = ">=3.11"
# dependencies = ["sympy"]
# ///
import sympy as sp
# 定义符号变量
x = sp.symbols('x', real=True)
# 定义二次函数
y = -2*x**2 + 8*x - 3
print("=" * 50)
print("二次函数 y = -2x² + 8x - 3 求解")
print("=" * 50)
# 方法1配方法求顶点
# y = -2(x² - 4x) - 3
# y = -2(x² - 4x + 4 - 4) - 3
# y = -2(x - 2)² + 8 - 3
# y = -2(x - 2)² + 5
# 方法2使用公式 x_vertex = -b/(2a)
a = -2
b = 8
c = -3
x_vertex = -b / (2*a)
y_vertex = a * x_vertex**2 + b * x_vertex + c
print(f"\n1. 顶点坐标")
print(f" 使用公式 x = -b/(2a) = -{b}/(2×{a}) = {x_vertex}")
print(f" 代入求 y = {a}×{x_vertex}² + {b}×{x_vertex} + ({c}) = {y_vertex}")
print(f" 顶点坐标: ({int(x_vertex)}, {int(y_vertex)})")
print(f"\n2. 函数最大值")
print(f" 由于 a = {a} < 0抛物线开口向下")
print(f" 函数在顶点处取得最大值")
print(f" 最大值: y_max = {int(y_vertex)}")
# 使用 SymPy 验证
print("\n" + "=" * 50)
print("SymPy 符号计算验证")
print("=" * 50)
# 求导数找极值点
dy = sp.diff(y, x)
critical_points = sp.solve(dy, x)
print(f"\n导数: y' = {dy}")
print(f"令 y' = 0解得 x = {critical_points}")
# 验证是最大值(二阶导数 < 0
d2y = sp.diff(dy, x)
print(f"二阶导数: y'' = {d2y} < 0确认为最大值点")
# 计算顶点处的函数值
x_v = critical_points[0]
y_v = y.subs(x, x_v)
print(f"\n顶点坐标: ({x_v}, {y_v})")
print(f"最大值: {y_v}")
# 配方形式
print("\n" + "=" * 50)
print("配方形式验证")
print("=" * 50)
vertex_form = -2*(x - 2)**2 + 5
expanded = sp.expand(vertex_form)
print(f"配方形式: y = -2(x - 2)² + 5")
print(f"展开验证: {expanded}")
print(f"与原式相等: {sp.simplify(expanded - y) == 0}")

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

View File

@@ -0,0 +1,9 @@
← sh(255) → node(264) → node(478) → zsh(pid=50427)
 args: /bin/zsh -i
🔍 找到真实二进制文件: /usr/local/bin/uv
→ exec /usr/local/bin/uv
Critical points (x): [2]
Vertex: (2, 5)
Second derivative: -4
The vertex is a maximum.
Maximum value: 5

View File

@@ -0,0 +1,46 @@
# /// 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
# 绑定图像尺寸和 DPI
plt.figure(figsize=(8, 6), dpi=150)
# 定义函数
def f(x):
return -2 * x**2 + 8 * x - 3
# 生成 x 值
x = np.linspace(-1, 5, 400)
y = f(x)
# 绘制函数曲线
plt.plot(x, y, label=r'$y = -2x^2 + 8x - 3$', color='blue')
# 标记顶点 (2, 5)
vertex_x = 2
vertex_y = 5
plt.plot(vertex_x, vertex_y, 'ro', label='顶点 (2, 5)')
plt.annotate(f'({vertex_x}, {vertex_y})', xy=(vertex_x, vertex_y), xytext=(vertex_x + 0.5, vertex_y),
arrowprops=dict(facecolor='black', shrink=0.05))
# 添加坐标轴标签和标题
plt.xlabel('x')
plt.ylabel('y')
plt.title('二次函数 $y = -2x^2 + 8x - 3$ 图像')
plt.axhline(0, color='black',linewidth=0.5)
plt.axvline(0, color='black',linewidth=0.5)
plt.grid(True, linestyle='--', alpha=0.7)
plt.legend()
# 保存图像
plt.savefig('figure.png', bbox_inches='tight')
plt.close()
print("图像已保存: figure.png")

View File

@@ -0,0 +1,5 @@
← sh(255) → node(264) → node(478) → zsh(pid=50427)
 args: /bin/zsh -i
🔍 找到真实二进制文件: /usr/local/bin/uv
→ exec /usr/local/bin/uv
图像已保存: figure.png

View File

@@ -0,0 +1,72 @@
# 二次函数 $y=-2x^2+8x-3$ 求解报告
## 1. 🎯 问题描述
已知二次函数 $y=-2x^2+8x-3$,求:
1. 函数的顶点坐标
2. 函数的最大值
## 2. ✅ 最终结论
该二次函数的顶点坐标为 $(2, 5)$。
由于二次项系数 $-2 < 0$,抛物线开口向下,函数在顶点处取得最大值,最大值为 $5$。
## 3. 📈 可视化
![函数图像](figure.png)
**图表说明**
- 蓝色曲线:二次函数 $y = -2x^2 + 8x - 3$ 的图像
- 红色圆点:函数的顶点 $(2, 5)$,也是函数的最高点
## 4. 🧠 数学建模与解题过程
<details>
<summary><strong>点击展开</strong></summary>
**问题分析**
这是一个标准的二次函数性质分析问题。二次函数的一般形式为 $y = ax^2 + bx + c$。
本题中,$a = -2, b = 8, c = -3$。
**方法选择**
可以通过配方法将一般式转化为顶点式 $y = a(x-h)^2 + k$,从而直接读出顶点 $(h, k)$ 和最值。
也可以利用导数法求极值点。
这里我们使用 SymPy 进行符号计算,通过求导数的方法来确定顶点和最值。
**推导过程**
1. **求导数**
对 $y = -2x^2 + 8x - 3$ 关于 $x$ 求导:
$$ \frac{dy}{dx} = -4x + 8 $$
2. **求驻点**
令导数为 0解方程
$$ -4x + 8 = 0 \implies x = 2 $$
3. **求顶点坐标**
将 $x = 2$ 代入原函数求 $y$
$$ y = -2(2)^2 + 8(2) - 3 = -8 + 16 - 3 = 5 $$
所以顶点坐标为 $(2, 5)$。
4. **判断最值**
计算二阶导数:
$$ \frac{d^2y}{dx^2} = -4 $$
因为二阶导数小于 0说明该驻点是极大值点。
对于二次函数,极大值即为全局最大值。
</details>
## 5. 📊 运行结果
<details>
<summary><strong>点击展开</strong></summary>
```
Critical points (x): [2]
Vertex: (2, 5)
Second derivative: -4
The vertex is a maximum.
Maximum value: 5
```
</details>

View File

@@ -0,0 +1,41 @@
# /// script
# requires-python = ">=3.11"
# dependencies = ["sympy"]
# ///
import sympy as sp
def solve():
x = sp.symbols('x', real=True)
y = -2*x**2 + 8*x - 3
# Find derivative to find critical points
dy_dx = sp.diff(y, x)
critical_points = sp.solve(dy_dx, x)
print(f"Critical points (x): {critical_points}")
if not critical_points:
print("No critical points found.")
return
vertex_x = critical_points[0]
vertex_y = y.subs(x, vertex_x)
print(f"Vertex: ({vertex_x}, {vertex_y})")
# Check second derivative to confirm maximum
d2y_dx2 = sp.diff(dy_dx, x)
print(f"Second derivative: {d2y_dx2}")
if d2y_dx2 < 0:
print("The vertex is a maximum.")
max_val = vertex_y
else:
print("The vertex is a minimum.")
max_val = vertex_y
print(f"Maximum value: {max_val}")
if __name__ == "__main__":
solve()

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

View File

@@ -0,0 +1,58 @@
# /// script
# requires-python = ">=3.11"
# dependencies = ["numpy", "matplotlib"]
# ///
import numpy as np
import matplotlib.pyplot as plt
# 设置字体优先使用中文字体DejaVu Sans 作为 fallback
plt.rcParams['font.sans-serif'] = ['WenQuanYi Micro Hei', 'Noto Sans CJK SC', 'Microsoft YaHei', 'SimHei', 'SimSun', 'DejaVu Sans']
plt.rcParams['axes.unicode_minus'] = False
# 绑定图像尺寸和 DPI
plt.figure(figsize=(8, 6), dpi=150)
# 定义二次函数 y = -2x^2 + 8x - 3
def quadratic_func(x):
return -2*x**2 + 8*x - 3
# 生成x值覆盖关键区域
x = np.linspace(-1, 5, 400)
y = quadratic_func(x)
# 绘制函数曲线
plt.plot(x, y, label=r'$y = -2x^2 + 8x - 3$', color='blue', linewidth=2)
# 标出顶点 (2, 5)
vertex_x, vertex_y = 2, 5
plt.plot(vertex_x, vertex_y, 'ro', markersize=8, label=f'顶点 ({vertex_x}, {vertex_y})')
# 添加网格
plt.grid(True, linestyle='--', alpha=0.6)
# 设置坐标轴标签和标题
plt.xlabel('x', fontsize=12)
plt.ylabel('y', fontsize=12)
plt.title('二次函数 $y = -2x^2 + 8x - 3$ 的图像', fontsize=14)
# 设置坐标轴范围
plt.xlim(-1, 5)
plt.ylim(-5, 7)
# 添加图例
plt.legend()
# 在顶点处添加注释
plt.annotate(f'顶点\n({vertex_x}, {vertex_y})',
xy=(vertex_x, vertex_y),
xytext=(vertex_x + 1.2, vertex_y - 1),
arrowprops=dict(arrowstyle='->', color='red', lw=1.5),
fontsize=12,
color='red',
ha='center')
# 保存图像
plt.savefig('figure.png', bbox_inches='tight')
plt.close()
print("图像已保存: figure.png")

View File

@@ -0,0 +1,84 @@
# 二次函数 $y = -2x^2 + 8x - 3$ 求解报告
## 1. 🎯 问题描述
已知二次函数 $y = -2x^2 + 8x - 3$,求:
1. 函数的顶点坐标
2. 函数的最大值
需要绘图。
## 2. ✅ 最终结论
对于二次函数 $y = -2x^2 + 8x - 3$
1. 顶点坐标为 (2, 5)
2. 由于函数开口向下($a = -2 < 0$),顶点是函数的最大值点,因此函数的最大值为 5
## 3. 📈 可视化
![函数图像](figure.png)
**图表说明**
- 蓝色曲线:函数 $y = -2x^2 + 8x - 3$
- 红色圆点:顶点 (2, 5)
- 从图中可以清楚地看到函数开口向下,顶点为最高点
## 4. 🧠 数学建模与解题过程
<details>
<summary><strong>点击展开</strong></summary>
**问题分析**:这是一个标准的二次函数求顶点和最值问题。给定函数 $y = -2x^2 + 8x - 3$ 是一个开口向下的抛物线(因为二次项系数 $a = -2 < 0$),所以存在最大值。
**方法选择**:可以使用导数方法或顶点公式方法求解。
**推导过程**
1. **使用导数方法**
- 对函数 $y = -2x^2 + 8x - 3$ 求导:$y' = -4x + 8$
- 令导数为0$-4x + 8 = 0$
- 解得 $x = 2$
2. **求顶点的y坐标**
- 将 $x = 2$ 代入原函数:$y = -2(2)^2 + 8(2) - 3 = -8 + 16 - 3 = 5$
- 所以顶点坐标为 (2, 5)
3. **验证函数开口方向**
- 二次项系数 $a = -2 < 0$,所以函数开口向下
- 因此顶点是函数的最大值点
4. **使用顶点公式验证**
- 对于二次函数 $y = ax^2 + bx + c$,顶点坐标为 $(-\frac{b}{2a}, f(-\frac{b}{2a}))$
- 其中 $a = -2$, $b = 8$, $c = -3$
- $x = -\frac{8}{2 \times (-2)} = -\frac{8}{-4} = 2$
- $y = -2(2)^2 + 8(2) - 3 = 5$
- 验证结果一致
</details>
## 5. 📊 运行结果
<details>
<summary><strong>点击展开</strong></summary>
```
给定二次函数: y = -2*x**2 + 8*x - 3
函数的一阶导数: 8 - 4*x
导数为0的点: [2]
顶点坐标: (2, 5)
函数的二阶导数: -4
由于二次项系数为负数,函数开口向下,顶点为最大值点
函数的最大值: 5
使用顶点公式验证:
顶点x坐标: x = -b/(2a) = -8/(2*-2) = 2.0
顶点y坐标: y = -2*(2.0)^2 + 8*(2.0) + -3 = 5.0
========================================
最终答案:
1. 函数的顶点坐标: (2, 5)
2. 函数的最大值: 5
========================================
```
</details>

View File

@@ -0,0 +1,63 @@
# /// script
# requires-python = ">=3.11"
# dependencies = ["sympy", "numpy", "matplotlib"]
# ///
import sympy as sp
import numpy as np
# 定义变量
x = sp.symbols('x', real=True)
# 定义二次函数 y = -2x^2 + 8x - 3
func = -2*x**2 + 8*x - 3
print("给定二次函数: y =", func)
# 方法1: 使用导数求顶点
# 顶点的x坐标是导数为0的点
derivative = sp.diff(func, x)
print("函数的一阶导数:", derivative)
# 求导数为0的点
critical_points = sp.solve(derivative, x)
print("导数为0的点:", critical_points)
# 顶点的x坐标
vertex_x = critical_points[0]
vertex_y = func.subs(x, vertex_x)
print(f"顶点坐标: ({vertex_x}, {vertex_y})")
# 判断最大值还是最小值
second_derivative = sp.diff(derivative, x)
print("函数的二阶导数:", second_derivative)
if second_derivative < 0:
print("由于二次项系数为负数,函数开口向下,顶点为最大值点")
print(f"函数的最大值: {vertex_y}")
elif second_derivative > 0:
print("由于二次项系数为正数,函数开口向上,顶点为最小值点")
print(f"函数的最小值: {vertex_y}")
else:
print("这不是二次函数")
# 方法2: 使用二次函数顶点公式验证
# 对于二次函数 y = ax^2 + bx + c顶点x坐标为 x = -b/(2a)
a = -2
b = 8
c = -3
vertex_x_formula = -b / (2*a)
vertex_y_formula = a * vertex_x_formula**2 + b * vertex_x_formula + c
print("\n使用顶点公式验证:")
print(f"顶点x坐标: x = -b/(2a) = {-b}/(2*{a}) = {vertex_x_formula}")
print(f"顶点y坐标: y = {a}*({vertex_x_formula})^2 + {b}*({vertex_x_formula}) + {c} = {vertex_y_formula}")
# 最终结果
print("\n" + "="*40)
print("最终答案:")
print(f"1. 函数的顶点坐标: ({vertex_x}, {vertex_y})")
print(f"2. 函数的最大值: {vertex_y}")
print("="*40)

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

View 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")

View 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. 📈 可视化
![函数图像](figure.png)
**图表说明**
- 蓝色曲线:函数 $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>

View 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}")