当前位置:首页>python>求最值十大经典数学方法和Python解法

求最值十大经典数学方法和Python解法

  • 2026-06-30 20:30:45
求最值十大经典数学方法和Python解法

求最值十大经典方法

经典例题

题目:已知 x² + 4y² = 2,求 x + 2y 的最大值。

这是一道经典的高中数学最值问题,今天我们用 10种不同方法 来解决它!


方法一:凑对偶式

核心思路

构造一个"对偶"的表达式,利用平方的非负性来求最值。

解题过程

我们知道:

(x + 2y)² + (x - 2y)² = 2x² + 8y² = 2(x² + 4y²)

题目告诉我们 x² + 4y² = 2,代入上式:

(x + 2y)² + (x - 2y)² = 2 × 2 = 4

因为任何数的平方都 ≥ 0,所以:

(x + 2y)² ≤ 4

开方后得到:

|x + 2y| ≤ 2

结论:x + 2y 的最大值是 2,当 x = 2y 时取得。

Python 实现

# 凑对偶式法求解
import sympy as sp

defsolve_by_dual():
# 1. 定义符号变量
    x, y = sp.symbols('x y')

# 2. 构造对偶式
    expr1 = (x + 2*y)**2# 目标表达式的平方
    expr2 = (x - 2*y)**2# 对偶表达式的平方
    dual_sum = expr1 + expr2
    print(f"对偶式和: (x+2y)² + (x-2y)² = {sp.expand(dual_sum)}")

# 3. 因式分解对偶式
    simplified = sp.factor(dual_sum)
    print(f"化简后: {simplified}")

# 4. 代入约束条件 x² + 4y² = 2
    constrained_sum = simplified.subs(x**2 + 4*y**22)
    print(f"代入约束条件后: {constrained_sum}")

# 5. 利用平方非负性求最大值
# (x+2y)² + (x-2y)² = 4,因为 (x-2y)² ≥ 0
# 所以 (x+2y)² ≤ 4
    max_squared = constrained_sum
    print(f"\n因为 (x-2y)² ≥ 0,所以 (x+2y)² ≤ {max_squared}")

# 6. 求最大值
    max_value = sp.sqrt(max_squared)
    print(f"因此 |x + 2y| ≤ {max_value}")

# 7. 求取等号条件:(x-2y)² = 0 ⇒ x = 2y
    print(f"\n取等号条件: (x-2y)² = 0 ⇒ x = 2y")

# 8. 解方程组求极值点
    eq1 = sp.Eq(x, 2*y)
    eq2 = sp.Eq(x**2 + 4*y**22)
    solutions = sp.solve((eq1, eq2), (x, y))
    print(f"极值点: {solutions}")

# 9. 验证结果
for sol in solutions:
        x_val, y_val = sol
        result = x_val + 2*y_val
        print(f"当 x={x_val}, y={y_val} 时,x + 2y = {result}")

return max_value, solutions

max_val, points = solve_by_dual()
print(f"\n【凑对偶式法】x + 2y 的最大值为: {max_val}")
print(f"取得最大值时的点: {points[1]}")

输出

对偶式和: (x+2y)² + (x-2y)² = 2*x**2 + 8*y**2
化简后: 2*(x**2 + 4*y**2)
代入约束条件后: 4

因为 (x-2y)² ≥ 0,所以 (x+2y)² ≤ 4
因此 |x + 2y| ≤ 2

取等号条件: (x-2y)² = 0 ⇒ x = 2y  
极值点: [(-1, -1/2), (1, 1/2)]
当 x=-1, y=-1/2 时,x + 2y = -2
当 x=1, y=1/2 时,x + 2y = 2   

【凑对偶式法】x + 2y 的最大值为: 2
取得最大值时的点: (1, 1/2)

评价:巧思妙解,利用对偶式快速放缩,适合对称结构问题


方法二:万能 k 法

核心思路

把要求的表达式设为 k,转化为一元二次方程有解的条件。

解题过程

令 k = x + 2y,则 x = k - 2y,代入约束条件:

(k - 2y)² + 4y² = 2

展开整理:

8y² - 4ky + (k² - 2) = 0

这是关于 y 的一元二次方程,要有实数解,判别式必须 ≥ 0:

Δ = b² - 4ac = (-4k)² - 4×8×(k² - 2) ≥ 0

计算得:

16k² - 32k² + 64 ≥ 0
-16k² + 64 ≥ 0
k² ≤ 4
-2 ≤ k ≤ 2

结论:k 的最大值是 2。

Python 实现

# 万能k法求解
import sympy as sp

defsolve_by_k_method():
# 1. 定义符号变量
    k, y = sp.symbols('k y')

# 2. 构造关于y的方程
    eq = sp.Eq(8*y**2 - 4*k*y + (k**2 - 2), 0)
    print(f"关于 y 的方程: {eq}")

# 3. 计算判别式
    delta = sp.discriminant(eq, y)
    print(f"判别式 Δ = {delta}")

# 4. 解方程 Δ = 0,求边界值
    boundary_values = sp.solve(sp.Eq(delta, 0), k)
    print(f"边界值: {boundary_values}")

# 5. 求最大值
    max_k = max(boundary_values)
    print(f"k 的最大值为: {max_k}")

# 6. 求极值点
    x, y = sp.symbols('x y')
    sol = sp.solve([sp.Eq(x + 2*y, max_k), sp.Eq(x**2 + 4*y**22)], (x, y))
    print(f"\n极值点: {sol}")

# 7. 验证结果
for solution in sol:
        x_val, y_val = solution
        result = x_val + 2*y_val
        print(f"当 x={x_val}, y={y_val} 时,x + 2y = {result}")

return max_k, sol

max_val, points = solve_by_k_method()
print(f"\n【万能k法】x + 2y 的最大值为: {max_val}")
print(f"取得最大值时的点: {points}")

输出

关于 y 的方程: Eq(k**2 - 4*k*y + 8*y**2 - 2, 0)
判别式 Δ = 64 - 16*k**2
边界值: [-2, 2]
k 的最大值为: 2

极值点: [(1, 1/2)]
当 x=1, y=1/2 时,x + 2y = 2   

【万能k法】x + 2y 的最大值为: 2
取得最大值时的点: [(1, 1/2)] 

评价:通杀全场,将最值问题转化为方程有解条件,适用范围极广


方法三:基本不等式

核心思路

利用基本不等式:对于任意实数 a 和 b,都有 a² + b² ≥ 2ab。

解题过程

令 a = x,b = 2y,则:

x² + (2y)² ≥ 2 × x × 2y = 4xy

已知 x² + 4y² = 2,所以:

2 ≥ 4xy ⇒ xy ≤ 1/2

再看目标表达式:

(x + 2y)² = x² + 4xy + 4y² = (x² + 4y²) + 4xy = 2 + 4xy

代入 xy ≤ 1/2:

(x + 2y)² ≤ 2 + 4×(1/2) = 4

结论:x + 2y ≤ 2。

Python 实现

# 基本不等式法求解
import sympy as sp

defsolve_by_inequality():
# 1. 定义符号变量
    x, y = sp.symbols('x y')

# 2. 基本不等式:a² + b² ≥ 2ab
    a, b = x, 2*y

# 3. 计算不等式两边
    left = a**2 + b**2
    right = 2*a*b
    print(f"基本不等式: {left} ≥ {right}")

# 4. 代入约束条件 x² + 4y² = 2
    left_constrained = left.subs(x**2 + 4*y**22)
    print(f"代入约束条件 x² + 4y² = 2 后: {left_constrained} ≥ {right}")

# 5. 推导 xy 的范围
# 2 ≥ 4xy ⇒ xy ≤ 1/2
    print(f"即: 2 ≥ 4xy ⇒ xy ≤ 1/2")

# 6. 展开目标函数的平方
    target_squared = (x + 2*y)**2
    expanded = sp.expand(target_squared)
    print(f"\n目标函数平方展开: (x + 2y)² = {expanded}")

# 7. 代入约束条件求最大值
# (x + 2y)² = x² + 4xy + 4y² = (x² + 4y²) + 4xy = 2 + 4xy
    target_with_constraint = expanded.subs(x**2 + 4*y**22)
    print(f"代入约束后: (x + 2y)² = {target_with_constraint}")

# 8. 代入 xy 的上限
# (x + 2y)² ≤ 2 + 4×(1/2) = 4
    max_squared = target_with_constraint.subs(x*y, sp.Rational(12))
    print(f"当 xy = 1/2 时,(x + 2y)² = {max_squared}")

# 9. 求最大值
    max_value = sp.sqrt(max_squared)
    print(f"因此 |x + 2y| ≤ {max_value}")

# 10. 求取等号条件:a = b 即 x = 2y
    print(f"\n取等号条件: x = 2y")

    eq1 = sp.Eq(x, 2*y)
    eq2 = sp.Eq(x**2 + 4*y**22)
    solutions = sp.solve((eq1, eq2), (x, y))
    print(f"极值点: {solutions}")

# 11. 验证结果
for sol in solutions:
        x_val, y_val = sol
        result = x_val + 2*y_val
        print(f"当 x={x_val}, y={y_val} 时,x + 2y = {result}")

return max_value, solutions

max_val, points = solve_by_inequality()
print(f"\n【基本不等式法】x + 2y 的最大值为: {max_val}")
print(f"取得最大值时的点: {points[1]}")

输出

基本不等式: x**2 + 4*y**2 ≥ 4*x*y
代入约束条件 x² + 4y² = 2 后: 2 ≥ 4*x*y
即: 2 ≥ 4xy ⇒ xy ≤ 1/2

目标函数平方展开: (x + 2y)² = x**2 + 4*x*y + 4*y**2
代入约束后: (x + 2y)² = 4*x*y + 2
当 xy = 1/2 时,(x + 2y)² = 4
因此 |x + 2y| ≤ 2

取等号条件: x = 2y
极值点: [(-1, -1/2), (1, 1/2)]
当 x=-1, y=-1/2 时,x + 2y = -2
当 x=1, y=1/2 时,x + 2y = 2

【基本不等式法】x + 2y 的最大值为: 2
取得最大值时的点: (1, 1/2)

评价:基石方法,均值不等式是不等式证明的基础,必须熟练掌握


方法四:轮换对称

核心思路

观察约束条件的对称性,假设变量满足某种对称关系时取极值。

解题过程

观察 x² + (2y)² = 2,发现形式对称。

假设 x = 2y(让两个平方项相等),代入:

(2y)² + 4y² = 2 ⇒ 8y² = 2 ⇒ y² = 1/4 ⇒ y = ±1/2

当 y = 1/2 时,x = 1,此时:

x + 2y = 1 + 2×(1/2) = 2

结论:最大值是 2。

Python 实现

# 轮换对称法求解
from sympy import symbols, Eq, solve

defsolve_by_symmetry():
    x, y = symbols('x y')
# 假设 x = 2y(对称条件)
    sol = solve([Eq(x, 2*y), Eq(x**2 + 4*y**22)], (x, y))
# 计算目标函数值
    values = [s[0] + 2*s[1for s in sol]
    max_value = max(values)
return max_value, sol

max_val, points = solve_by_symmetry()
print(f"【轮换对称法】x + 2y 的最大值为: {max_val}")
print(f"取得最大值时的点: {points[1]}")

输出

【轮换对称法】x + 2y 的最大值为: 2
取得最大值时的点: (1, 1/2)

评价:慧眼识珠,通过观察对称性快速定位极值点,需验证确保正确性


方法五:权方和不等式

核心思路

利用分式形式的不等式,适用于幂次结构的问题。

解题过程

权方和不等式的特殊形式:

a²/b + c²/d ≥ (a+c)²/(b+d)

应用到本题:

x²/1 + (2y)²/1 ≥ (x + 2y)²/(1+1)

左边就是 x² + 4y² = 2,所以:

2 ≥ (x + 2y)²/2 ⇒ (x + 2y)² ≤ 4

结论:x + 2y ≤ 2。

Python 实现

# 权方和不等式法求解
import sympy as sp

defsolve_by_quanfanghe():
# 1. 定义符号变量
    x, y = sp.symbols('x y')

# 2. 权方和不等式形式
# a₁²/b₁ + a₂²/b₂ ≥ (a₁ + a₂)²/(b₁ + b₂)
    a1, a2 = x, 2*y
    b1, b2 = 11

# 3. 计算左边
    left_side = a1**2/b1 + a2**2/b2
    print(f"权方和左边: x²/1 + (2y)²/1 = {sp.simplify(left_side)}")

# 4. 代入约束条件 x² + 4y² = 2
    left_with_constraint = left_side.subs(x**2 + 4*y**22)
    print(f"代入约束条件后左边 = {sp.simplify(left_with_constraint)}")

# 5. 计算右边
    right_side = (a1 + a2)**2 / (b1 + b2)
    print(f"权方和右边: (x + 2y)²/(1 + 1) = {sp.simplify(right_side)}")

# 6. 应用不等式求最大值
# 2 ≥ (x + 2y)²/2
# (x + 2y)² ≤ 4
    max_squared = 2 * left_with_constraint
    print(f"\n由不等式得: (x + 2y)² ≤ {sp.simplify(max_squared)}")

# 7. 求最大值
    max_value = sp.sqrt(max_squared)
    print(f"因此 |x + 2y| ≤ {max_value}")

# 8. 求取等号条件
# 权方和取等条件:a₁/b₁ = a₂/b₂
# 即 x/1 = 2y/1 ⇒ x = 2y
    print(f"\n取等号条件: x/1 = 2y/1 ⇒ x = 2y")

    eq1 = sp.Eq(x, 2*y)
    eq2 = sp.Eq(x**2 + 4*y**22)
    solutions = sp.solve((eq1, eq2), (x, y))
    print(f"极值点: {solutions}")

# 9. 验证结果
for sol in solutions:
        x_val, y_val = sol
        result = x_val + 2*y_val
        print(f"当 x={x_val}, y={y_val} 时,x + 2y = {result}")

return max_value, solutions

max_val, points = solve_by_quanfanghe()
print(f"\n【权方和不等式法】x + 2y 的最大值为: {max_val}")
print(f"取得最大值时的点: {points[1]}")

输出

权方和左边: x²/1 + (2y)²/1 = x**2 + 4*y**2
代入约束条件后左边 = 2
权方和右边: (x + 2y)²/(1 + 1) = (x + 2*y)**2/2

由不等式得: (x + 2y)² ≤ 4      
因此 |x + 2y| ≤ 2

取等号条件: x/1 = 2y/1 ⇒ x = 2y
极值点: [(-1, -1/2), (1, 1/2)] 
当 x=-1, y=-1/2 时,x + 2y = -2
当 x=1, y=1/2 时,x + 2y = 2   

【权方和不等式法】x + 2y 的最大值为: 2
取得最大值时的点: (1, 1/2)

评价:高阶技巧,分式结构不等式,对幂次问题有奇效,掌握后可快速口算


方法六:柯西不等式

核心思路

利用向量内积的性质,非常适合线性组合的最值问题。

解题过程

柯西不等式:

(a₁b₁ + a₂b₂)² ≤ (a₁² + a₂²)(b₁² + b₂²)

令 a₁=1, a₂=1, b₁=x, b₂=2y,则:

(x + 2y)² ≤ (1² + 1²)(x² + (2y)²) = 2 × 2 = 4

结论:x + 2y ≤ 2。

Python 实现

# 柯西不等式法求解
import sympy as sp

defsolve_by_cauchy():
# 1. 定义符号变量
    x, y = sp.symbols('x y')

# 2. 柯西不等式形式
# (a₁b₁ + a₂b₂)² ≤ (a₁² + a₂²)(b₁² + b₂²)
    a1, a2 = 11
    b1, b2 = x, 2*y

# 3. 计算左边:(a₁b₁ + a₂b₂)²
    left_side = (a1*b1 + a2*b2)**2
    print(f"目标函数平方: (x + 2y)² = {sp.simplify(left_side)}")

# 4. 计算右边:(a₁² + a₂²)(b₁² + b₂²)
    right_side = (a1**2 + a2**2) * (b1**2 + b2**2)
    print(f"柯西不等式右边: (1² + 1²)(x² + (2y)²) = {right_side}")
    print(f"展开后: {sp.expand(right_side)}")

# 5. 代入约束条件 x² + 4y² = 2
# 使用 factor 先因式分解,再替换
    right_factor = sp.factor(right_side)
    print(f"因式分解后: {right_factor}")
    right_with_constraint = right_factor.subs(x**2 + 4*y**22)
    print(f"代入约束条件 x² + 4y² = 2 后右边 = {sp.simplify(right_with_constraint)}")

# 6. 应用柯西不等式求最大值
# (x + 2y)² ≤ 4 ⇒ |x + 2y| ≤ 2
    max_value = sp.sqrt(right_with_constraint)
    print(f"\n由柯西不等式得: |x + 2y| ≤ {max_value}")

# 7. 求取等号条件:a₁/b₁ = a₂/b₂
# 即 1/x = 1/(2y) ⇒ x = 2y
    eq1 = sp.Eq(x, 2*y)
    eq2 = sp.Eq(x**2 + 4*y**22)

# 8. 解方程组求极值点
    solutions = sp.solve((eq1, eq2), (x, y))
    print(f"\n取等号条件: x = 2y")
    print(f"极值点: {solutions}")

# 9. 验证结果
for sol in solutions:
        x_val, y_val = sol
        result = x_val + 2*y_val
        print(f"当 x={x_val}, y={y_val} 时,x + 2y = {result}")

return max_value, solutions

max_val, points = solve_by_cauchy()
print(f"\n【柯西不等式法】x + 2y 的最大值为: {max_val}")
print(f"取得最大值时的点: {points[1]}")

输出

目标函数平方: (x + 2y)² = (x + 2*y)**2
柯西不等式右边: (1² + 1²)(x² + (2y)²) = 2*x**2 + 8*y**2
展开后: 2*x**2 + 8*y**2
因式分解后: 2*(x**2 + 4*y**2)
代入约束条件 x² + 4y² = 2 后右边 = 4

由柯西不等式得: |x + 2y| ≤ 2

取等号条件: x = 2y
极值点: [(-1, -1/2), (1, 1/2)] 
当 x=-1, y=-1/2 时,x + 2y = -2
当 x=1, y=1/2 时,x + 2y = 2   

【柯西不等式法】x + 2y 的最大值为: 2
取得最大值时的点: (1, 1/2)

评价:向量神器,与权方和不等式等价,是处理线性组合最值的利器


方法七:几何意义法

核心思路

把代数问题转化为几何图形,直观易懂。

解题过程

  • 约束条件 x² + 4y² = 2 是一个椭圆
  • 目标函数 x + 2y = k 是一组斜率为 -1/2 的平行线

当直线与椭圆相切时,k 取得极值。

将 x = k - 2y 代入椭圆方程:

(k - 2y)² + 4y² = 2

相切时只有一个交点,判别式为 0:

Δ = 16k² - 32(k² - 2) = 0 ⇒ k = ±2

Python 实现

# 几何意义法求解
defsolve_by_geometry():
from sympy import symbols, discriminant, solve, Eq
    k, y = symbols('k y')
# 直线与椭圆相切时判别式为0
    eq = Eq(8*y**2 - 4*k*y + (k**2 - 2), 0)
    delta = discriminant(eq, y)
    k_values = solve(delta, k)
    max_value = max(k_values)
# 求切点坐标
    x, y = symbols('x y')
    sol = solve([Eq(x + 2*y, max_value), Eq(x**2 + 4*y**22)], (x, y))
return max_value, sol

max_val, points = solve_by_geometry()
print(f"【几何意义法】x + 2y 的最大值为: {max_val}")
print(f"切点坐标: {points}")

输出

【几何意义法】x + 2y 的最大值为: 2
切点坐标: [(1, 1/2)]

评价:直观易懂,将代数问题几何化,适合理解问题本质


方法八:三角函数法

核心思路

利用椭圆的参数方程,将问题转化为三角函数求最值。

解题过程

椭圆 x²/a² + y²/b² = 1 的参数方程是:

x = a·cosθ, y = b·sinθ

对于 x² + 4y² = 2,即 x²/(√2)² + y²/(√2/2)² = 1:

x = √2·cosθ, y = (√2/2)·sinθ

代入目标函数:

x + 2y = √2·cosθ + 2×(√2/2)·sinθ = √2(cosθ + sinθ)

利用三角恒等式:

cosθ + sinθ = √2·sin(θ + π/4)

所以:

x + 2y = √2 × √2·sin(θ + π/4) = 2·sin(θ + π/4)

因为 sin 的最大值是 1,所以:

x + 2y ≤ 2

Python 实现

# 三角函数法求解
import sympy as sp
import numpy as np

defsolve_by_trigonometry():
# 1. 定义符号变量
    theta = sp.symbols('theta')

# 2. 椭圆参数方程
    x = sp.sqrt(2) * sp.cos(theta)  # x = √2·cosθ
    y = (sp.sqrt(2)/2) * sp.sin(theta)  # y = (√2/2)·sinθ

# 3. 代入目标函数
    expr = x + 2*y
    print(f"代入参数方程: x + 2y = {sp.simplify(expr)}")

# 4. 化简三角表达式
    simplified = sp.simplify(expr / sp.sqrt(2))
    print(f"化简后: (x + 2y)/√2 = {simplified}")

# 5. 用 sympy 求 sin 函数的最大值
    max_sin_value = sp.maximum(sp.sin(theta), theta, sp.Interval(02*sp.pi))
    print(f"\nsinθ 在 [0, 2π] 的最大值为: {max_sin_value}")

# 6. 计算 x + 2y 的最大值
# x + 2y = √2·√2·sin(θ + π/4) = 2·sin(θ + π/4)
    max_value = sp.sqrt(2) * sp.sqrt(2) * max_sin_value
    print(f"因此 x + 2y 的最大值为: {sp.simplify(max_value)}")

# 7. 求取得最大值时的角度
# sin(θ + π/4) = 1 时,θ + π/4 = π/2
    theta_solutions = sp.solve(sp.Eq(sp.sin(theta + sp.pi/4), 1), theta)
    theta_max = theta_solutions[0]
    print(f"\nsin(θ + π/4) = 1 的解: θ = {theta_max}")

# 8. 计算极值点坐标
    x_max = sp.sqrt(2) * sp.cos(theta_max)
    y_max = (sp.sqrt(2)/2) * sp.sin(theta_max)

    print(f"\n当 θ = {sp.N(theta_max, 3)} 时:")
    print(f"  x = √2·cos(θ) = {sp.N(x_max, 4)}")
    print(f"  y = (√2/2)·sin(θ) = {sp.N(y_max, 4)}")
    print(f"  x + 2y = {sp.N(x_max + 2*y_max, 4)}")

return sp.simplify(max_value), (sp.N(x_max), sp.N(y_max))

max_val, point = solve_by_trigonometry()
print(f"\n【三角函数法】x + 2y 的最大值为: {max_val}")
print(f"取得最大值时的点: x={float(point[0]):.2f}, y={float(point[1]):.2f}")

输出

代入参数方程: x + 2y = 2*sin(theta + pi/4)
化简后: (x + 2y)/√2 = sqrt(2)*sin(theta + pi/4)

sinθ 在 [0, 2π] 的最大值为: 1
因此 x + 2y 的最大值为: 2

sin(θ + π/4) = 1 的解: θ = pi/4

当 θ = 0.785 时:
  x = √2·cos(θ) = 1.000     
  y = (√2/2)·sin(θ) = 0.5000
  x + 2y = 2.000

【三角函数法】x + 2y 的最大值为: 2
取得最大值时的点: x=1.00, y=0.50

评价:参数化利器,将椭圆转化为三角函数,需要扎实的三角恒等变换功底


方法九:向量法

核心思路

构造向量,利用向量点积的性质求最值。

解题过程

构造两个向量:

向量 a = (1, 1)
向量 b = (x, 2y)

向量点积性质:

a·b ≤ |a| × |b|

计算:

a·b = 1×x + 1×(2y) = x + 2y
|a| = √(1² + 1²) = √2
|b| = √(x² + (2y)²) = √(x² + 4y²) = √2

所以:

x + 2y ≤ √2 × √2 = 2

Python 实现

import sympy as sp

# 定义符号变量
x, y = sp.symbols("x y")

# 构造向量
v1 = sp.Matrix([11])   # 向量 a = (1, 1)
v2 = sp.Matrix([x, 2*y]) # 向量 b = (x, 2y)

# 计算点积
dot = v1.dot(v2)  # a·b = x + 2y

# 计算向量模长
am = sp.sqrt(v1.dot(v1))  # |a| = √(1² + 1²) = √2
bm = sp.sqrt(v2.dot(v2))  # |b| = √(x² + (2y)²) = √(x² + 4y²)

# 约束条件
exp1 = sp.Eq(x**2 + 4*y**22)

# 向量点积性质:a·b ≤ |a| × |b|
print("点积 a·b =", dot)
print("|a| =", am)
print("|b| =", bm)
print("不等式:", dot, "≤", am, "×", bm)

# 代入约束条件 |b| = √2
bm_substituted = bm.subs(x**2 + 4*y**22)
max_val = am * bm_substituted
print("代入约束条件后 |b| =", bm_substituted)
print("因此最大值为 |a| × |b| =", max_val)

# 求极值点:当 a 与 b 同向时取等号,即 v1 = k * v2
k = sp.symbols('k')
eq1 = sp.Eq(1, k * x)      # 1 = k*x
eq2 = sp.Eq(1, k * 2*y)    # 1 = k*2y
eq3 = sp.Eq(x**2 + 4*y**22)  # 约束条件

solution = sp.solve((eq1, eq2, eq3), (x, y, k))
print("\n极值点:")
for sol in solution:
    x_val, y_val, k_val = sol
    print(f"  x = {x_val}, y = {y_val},此时 x + 2y = {x_val + 2*y_val}")
print(f"\n【向量法】x + 2y 的最大值为: {max_val}")
print(f"取得最大值时的点: {solution[1][:2]}")

输出

点积 a·b = x + 2*y
|a| = sqrt(2)
|b| = sqrt(x**2 + 4*y**2)
不等式: x + 2*y ≤ sqrt(2) × sqrt(x**2 + 4*y**2)
代入约束条件后 |b| = sqrt(2)
因此最大值为 |a| × |b| = 2

极值点:
  x = -1, y = -1/2,此时 x + 2y = -2
  x = 1, y = 1/2,此时 x + 2y = 2   

【向量法】x + 2y 的最大值为: 2
取得最大值时的点: (1, 1/2)

评价:构造思维,通过向量点积性质求最值,需要一定的数学想象力


方法十:拉格朗日乘数法

核心思路

这是高等数学的方法,通过构造拉格朗日函数求条件极值。

解题过程

构造拉格朗日函数:

L(x, y, λ) = x + 2y + λ(2 - x² - 4y²)

分别对 x、y、λ 求偏导并令其为 0:

∂L/∂x = 1 - 2λx = 0  ⇒  x = 1/(2λ)
∂L/∂y = 2 - 8λy = 0  ⇒  y = 2/(8λ) = 1/(4λ)
∂L/∂λ = 2 - x² - 4y² = 0

由前两式得 x = 2y,代入第三式:

(2y)² + 4y² = 2 ⇒ y = ±1/2, x = ±1

结论:最大值为 f(1, 1/2) = 2。

Python 实现

# 拉格朗日乘数法求解
from scipy.optimize import minimize

defsolve_by_lagrange():

defobjective(vars):
        x, y = vars
return -(x + 2*y)  # 求最大值转化为求负最小值

defconstraint(vars):
        x, y = vars
return x**2 + 4*y**2 - 2

    result = minimize(objective, [10.5], constraints={'type''eq''fun': constraint})
    max_value = -result.fun
    x_opt, y_opt = result.x
return max_value, (x_opt, y_opt)

max_val, point = solve_by_lagrange()
print(f"【拉格朗日乘数法】x + 2y 的最大值为: {max_val:.2f}")
print(f"取得最大值时的点: x={point[0]:.2f}, y={point[1]:.2f}")

输出

【拉格朗日乘数法】x + 2y 的最大值为: 2.00
取得最大值时的点: x=1.00, y=0.50

评价:通用大法,高等数学经典方法,适用于各类条件极值问题


方法总结

方法
核心思想
适用场景
难度
凑对偶式
构造对称表达式
对称问题
简单
万能k法
转化为二次方程判别式
一般问题
中等
基本不等式
利用均值不等式
乘积求和
中等
轮换对称
假设变量相等
对称结构
简单
权方和不等式
分式不等式
幂次结构
较难
柯西不等式
向量内积性质
线性组合
中等
几何意义法
数形结合
几何约束
中等
三角函数法
参数化表示
圆/椭圆
中等
向量法
向量点积性质
线性组合
中等
拉格朗日乘数法
多元极值条件
一般优化
较难

最终结论

答案:x + 2y 的最大值是 2

取得条件:当且仅当 x = 1,y = 1/2 时取得。


关注公众号,获取更多数学和编程解题技巧!


导读

sympy玩转数学👈点击阅读

最新文章

随机文章

基本 文件 流程 错误 SQL 调试
  1. 请求信息 : 2026-07-03 09:35:31 HTTP/2.0 GET : https://f.mffb.com.cn/a/497236.html
  2. 运行时间 : 0.108304s [ 吞吐率:9.23req/s ] 内存消耗:4,527.01kb 文件加载:140
  3. 缓存信息 : 0 reads,0 writes
  4. 会话信息 : SESSION_ID=045001f4482acb20a2efab3802bb4806
  1. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/public/index.php ( 0.79 KB )
  2. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/autoload.php ( 0.17 KB )
  3. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_real.php ( 2.49 KB )
  4. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/platform_check.php ( 0.90 KB )
  5. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/ClassLoader.php ( 14.03 KB )
  6. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/composer/autoload_static.php ( 4.90 KB )
  7. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper.php ( 8.34 KB )
  8. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/helper.php ( 2.19 KB )
  9. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/helper.php ( 1.47 KB )
  10. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/stubs/load_stubs.php ( 0.16 KB )
  11. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Exception.php ( 1.69 KB )
  12. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Facade.php ( 2.71 KB )
  13. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/deprecation-contracts/function.php ( 0.99 KB )
  14. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap.php ( 8.26 KB )
  15. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/polyfill-mbstring/bootstrap80.php ( 9.78 KB )
  16. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/Resources/functions/dump.php ( 1.49 KB )
  17. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-dumper/src/helper.php ( 0.18 KB )
  18. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/symfony/var-dumper/VarDumper.php ( 4.30 KB )
  19. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/App.php ( 15.30 KB )
  20. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-container/src/Container.php ( 15.76 KB )
  21. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/container/src/ContainerInterface.php ( 1.02 KB )
  22. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/provider.php ( 0.19 KB )
  23. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Http.php ( 6.04 KB )
  24. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Str.php ( 7.29 KB )
  25. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Env.php ( 4.68 KB )
  26. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/common.php ( 0.03 KB )
  27. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/helper.php ( 18.78 KB )
  28. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Config.php ( 5.54 KB )
  29. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/app.php ( 0.95 KB )
  30. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cache.php ( 0.78 KB )
  31. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/console.php ( 0.23 KB )
  32. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/cookie.php ( 0.56 KB )
  33. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/database.php ( 2.48 KB )
  34. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Env.php ( 1.67 KB )
  35. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/filesystem.php ( 0.61 KB )
  36. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/lang.php ( 0.91 KB )
  37. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/log.php ( 1.35 KB )
  38. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/middleware.php ( 0.19 KB )
  39. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/route.php ( 1.89 KB )
  40. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/session.php ( 0.57 KB )
  41. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/trace.php ( 0.34 KB )
  42. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/config/view.php ( 0.82 KB )
  43. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/event.php ( 0.25 KB )
  44. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Event.php ( 7.67 KB )
  45. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/service.php ( 0.13 KB )
  46. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/AppService.php ( 0.26 KB )
  47. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Service.php ( 1.64 KB )
  48. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Lang.php ( 7.35 KB )
  49. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/lang/zh-cn.php ( 13.70 KB )
  50. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/Error.php ( 3.31 KB )
  51. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/RegisterService.php ( 1.33 KB )
  52. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/services.php ( 0.14 KB )
  53. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/PaginatorService.php ( 1.52 KB )
  54. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ValidateService.php ( 0.99 KB )
  55. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/service/ModelService.php ( 2.04 KB )
  56. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Service.php ( 0.77 KB )
  57. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Middleware.php ( 6.72 KB )
  58. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/initializer/BootService.php ( 0.77 KB )
  59. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Paginator.php ( 11.86 KB )
  60. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-validate/src/Validate.php ( 63.20 KB )
  61. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/Model.php ( 23.55 KB )
  62. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Attribute.php ( 21.05 KB )
  63. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/AutoWriteData.php ( 4.21 KB )
  64. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/Conversion.php ( 6.44 KB )
  65. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/DbConnect.php ( 5.16 KB )
  66. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/ModelEvent.php ( 2.33 KB )
  67. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/concern/RelationShip.php ( 28.29 KB )
  68. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Arrayable.php ( 0.09 KB )
  69. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/contract/Jsonable.php ( 0.13 KB )
  70. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/model/contract/Modelable.php ( 0.09 KB )
  71. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Db.php ( 2.88 KB )
  72. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/DbManager.php ( 8.52 KB )
  73. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Log.php ( 6.28 KB )
  74. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Manager.php ( 3.92 KB )
  75. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerTrait.php ( 2.69 KB )
  76. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/log/src/LoggerInterface.php ( 2.71 KB )
  77. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cache.php ( 4.92 KB )
  78. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/psr/simple-cache/src/CacheInterface.php ( 4.71 KB )
  79. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/helper/Arr.php ( 16.63 KB )
  80. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/driver/File.php ( 7.84 KB )
  81. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/cache/Driver.php ( 9.03 KB )
  82. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/CacheHandlerInterface.php ( 1.99 KB )
  83. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/Request.php ( 0.09 KB )
  84. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Request.php ( 55.78 KB )
  85. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/middleware.php ( 0.25 KB )
  86. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Pipeline.php ( 2.61 KB )
  87. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/TraceDebug.php ( 3.40 KB )
  88. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/middleware/SessionInit.php ( 1.94 KB )
  89. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Session.php ( 1.80 KB )
  90. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/driver/File.php ( 6.27 KB )
  91. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/SessionHandlerInterface.php ( 0.87 KB )
  92. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/session/Store.php ( 7.12 KB )
  93. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Route.php ( 23.73 KB )
  94. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleName.php ( 5.75 KB )
  95. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Domain.php ( 2.53 KB )
  96. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleGroup.php ( 22.43 KB )
  97. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Rule.php ( 26.95 KB )
  98. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/RuleItem.php ( 9.78 KB )
  99. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/route/app.php ( 1.72 KB )
  100. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/Route.php ( 4.70 KB )
  101. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/dispatch/Controller.php ( 4.74 KB )
  102. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/route/Dispatch.php ( 10.44 KB )
  103. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/controller/Index.php ( 4.81 KB )
  104. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/app/BaseController.php ( 2.05 KB )
  105. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/facade/Db.php ( 0.93 KB )
  106. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/connector/Mysql.php ( 5.44 KB )
  107. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/PDOConnection.php ( 52.47 KB )
  108. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Connection.php ( 8.39 KB )
  109. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/ConnectionInterface.php ( 4.57 KB )
  110. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/builder/Mysql.php ( 16.58 KB )
  111. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Builder.php ( 24.06 KB )
  112. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseBuilder.php ( 27.50 KB )
  113. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/Query.php ( 15.71 KB )
  114. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/BaseQuery.php ( 45.13 KB )
  115. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TimeFieldQuery.php ( 7.43 KB )
  116. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/AggregateQuery.php ( 3.26 KB )
  117. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ModelRelationQuery.php ( 20.07 KB )
  118. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ParamsBind.php ( 3.66 KB )
  119. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/ResultOperation.php ( 7.01 KB )
  120. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/WhereQuery.php ( 19.37 KB )
  121. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/JoinAndViewQuery.php ( 7.11 KB )
  122. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/TableFieldInfo.php ( 2.63 KB )
  123. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-orm/src/db/concern/Transaction.php ( 2.77 KB )
  124. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/driver/File.php ( 5.96 KB )
  125. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/LogHandlerInterface.php ( 0.86 KB )
  126. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/log/Channel.php ( 3.89 KB )
  127. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/event/LogRecord.php ( 1.02 KB )
  128. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-helper/src/Collection.php ( 16.47 KB )
  129. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/facade/View.php ( 1.70 KB )
  130. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/View.php ( 4.39 KB )
  131. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Response.php ( 8.81 KB )
  132. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/response/View.php ( 3.29 KB )
  133. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/Cookie.php ( 6.06 KB )
  134. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-view/src/Think.php ( 8.38 KB )
  135. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/framework/src/think/contract/TemplateHandlerInterface.php ( 1.60 KB )
  136. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/Template.php ( 46.61 KB )
  137. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/driver/File.php ( 2.41 KB )
  138. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-template/src/template/contract/DriverInterface.php ( 0.86 KB )
  139. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/runtime/temp/067d451b9a0c665040f3f1bdd3293d68.php ( 11.98 KB )
  140. /yingpanguazai/ssd/ssd1/www/f.mffb.com.cn/vendor/topthink/think-trace/src/Html.php ( 4.42 KB )
  1. CONNECT:[ UseTime:0.000596s ] mysql:host=127.0.0.1;port=3306;dbname=f_mffb;charset=utf8mb4
  2. SHOW FULL COLUMNS FROM `fenlei` [ RunTime:0.000826s ]
  3. SELECT * FROM `fenlei` WHERE `fid` = 0 [ RunTime:0.000456s ]
  4. SELECT * FROM `fenlei` WHERE `fid` = 63 [ RunTime:0.000278s ]
  5. SHOW FULL COLUMNS FROM `set` [ RunTime:0.000484s ]
  6. SELECT * FROM `set` [ RunTime:0.000205s ]
  7. SHOW FULL COLUMNS FROM `article` [ RunTime:0.000542s ]
  8. SELECT * FROM `article` WHERE `id` = 497236 LIMIT 1 [ RunTime:0.000582s ]
  9. UPDATE `article` SET `lasttime` = 1783042531 WHERE `id` = 497236 [ RunTime:0.025147s ]
  10. SELECT * FROM `fenlei` WHERE `id` = 66 LIMIT 1 [ RunTime:0.000389s ]
  11. SELECT * FROM `article` WHERE `id` < 497236 ORDER BY `id` DESC LIMIT 1 [ RunTime:0.000596s ]
  12. SELECT * FROM `article` WHERE `id` > 497236 ORDER BY `id` ASC LIMIT 1 [ RunTime:0.003968s ]
  13. SELECT * FROM `article` WHERE `id` < 497236 ORDER BY `id` DESC LIMIT 10 [ RunTime:0.000719s ]
  14. SELECT * FROM `article` WHERE `id` < 497236 ORDER BY `id` DESC LIMIT 10,10 [ RunTime:0.000722s ]
  15. SELECT * FROM `article` WHERE `id` < 497236 ORDER BY `id` DESC LIMIT 20,10 [ RunTime:0.000730s ]
0.110116s