跳转至

高等数学(二)导数与微分

章节概述

导数是微积分的核心概念,描述函数的变化率。本章将介绍导数的定义、求导法则、高阶导数以及导数的应用,并通过Python代码演示数值求导方法。

学习目标

  • 理解导数的定义和几何意义
  • 掌握基本求导法则
  • 学会求高阶导数
  • 理解导数的应用
  • 掌握数值求导方法

(一)导数的定义

导数的定义

函数 f(x) 在点 x₀ 处的导数定义为:

f'(x₀) = lim(Δx→0) [f(x₀ + Δx) - f(x₀)] / Δx

几何意义

导数表示函数图像在某点处的切线斜率。

常用导数公式

  1. (xⁿ)' = n·xⁿ⁻¹
  2. (eˣ)' = eˣ
  3. (aˣ)' = aˣ · ln a
  4. (ln x)' = 1/x
  5. (sin x)' = cos x
  6. (cos x)' = -sin x
  7. (tan x)' = sec² x
  8. (cot x)' = -csc² x
  9. (arcsin x)' = 1/√(1-x²)
  10. (arccos x)' = -1/√(1-x²)

数值求导方法

def numerical_derivative(func, x, h=1e-6):
    """
    数值求导(使用中心差分)

    参数:
        func: 函数
        x: 求导点
        h: 步长

    返回:
        float: 导数的近似值

    示例:
        >>> def f(x): return x**2
        >>> numerical_derivative(f, 3)
        6.000000000001087
    """
    return (func(x + h) - func(x - h)) / (2 * h)

实例分析

实例1:求 f(x) = x² 的导数

def f1(x):
    """函数 f(x) = x²"""
    return x**2

for x in [0, 1, 2, 3]:
    derivative = numerical_derivative(f1, x)
    print(f"f'(x) 在 x={x} 处的值: {derivative:.4f}")
    print(f"理论值: {2*x:.4f}")

输出:

f'(x) 在 x=0 处的值: 0.0000
理论值: 0.0000
f'(x) 在 x=1 处的值: 2.0000
理论值: 2.0000
f'(x) 在 x=2 处的值: 4.0000
理论值: 4.0000
f'(x) 在 x=3 处的值: 6.0000
理论值: 6.0000

实例2:求 f(x) = sin x 的导数

import math

def f2(x):
    """函数 f(x) = sin x"""
    return math.sin(x)

for x in [0, math.pi/6, math.pi/4, math.pi/2]:
    derivative = numerical_derivative(f2, x)
    print(f"f'(x) 在 x={x:.4f} 处的值: {derivative:.6f}")
    print(f"理论值 (cos x): {math.cos(x):.6f}")

实例3:求 f(x) = eˣ 的导数

def f3(x):
    """函数 f(x) = eˣ"""
    return math.exp(x)

for x in [0, 1, 2]:
    derivative = numerical_derivative(f3, x)
    print(f"f'(x) 在 x={x} 处的值: {derivative:.6f}")
    print(f"理论值 (eˣ): {math.exp(x):.6f}")

(二)求导法则

基本求导法则

1. 常数法则

(C)' = 0

2. 和差法则

(u ± v)' = u' ± v'

3. 乘积法则

(uv)' = u'v + uv'

4. 商法则

(u/v)' = (u'v - uv') / v²

5. 链式法则

[f(g(x))]' = f'(g(x)) · g'(x)

实例分析

实例1:使用乘积法则

求 f(x) = x² · sin x 的导数

def f_product(x):
    """函数 f(x) = x² · sin x"""
    return x**2 * math.sin(x)

# 数值求导
for x in [0, 1, 2]:
    derivative = numerical_derivative(f_product, x)
    print(f"f'(x) 在 x={x} 处的值: {derivative:.6f}")

解析解:

f'(x) = (x²)' · sin x + x² · (sin x)'
     = 2x · sin x + x² · cos x

实例2:使用商法则

求 f(x) = sin x / x 的导数

def f_quotient(x):
    """函数 f(x) = sin x / x"""
    return math.sin(x) / x if x != 0 else 1

# 数值求导
for x in [1, 2, 3]:
    derivative = numerical_derivative(f_quotient, x)
    print(f"f'(x) 在 x={x} 处的值: {derivative:.6f}")

解析解:

f'(x) = [(sin x)' · x - sin x · (x)'] / x²
     = (cos x · x - sin x) / x²

实例3:使用链式法则

求 f(x) = sin(x²) 的导数

def f_chain(x):
    """函数 f(x) = sin(x²)"""
    return math.sin(x**2)

# 数值求导
for x in [0, 1, 2]:
    derivative = numerical_derivative(f_chain, x)
    print(f"f'(x) 在 x={x} 处的值: {derivative:.6f}")

解析解:

f'(x) = cos(x²) · (x²)'
     = cos(x²) · 2x

(三)高阶导数

高阶导数的定义

f(x) 的 n 阶导数定义为:

f⁽ⁿ⁾(x) = [f⁽ⁿ⁻¹⁾(x)]'

常用高阶导数公式

1. 指数函数

(eˣ)⁽ⁿ⁾ = eˣ

2. 正弦函数

(sin x)⁽ⁿ⁾ = sin(x + nπ/2)

3. 余弦函数

(cos x)⁽ⁿ⁾ = cos(x + nπ/2)

4. 幂函数

(xᵐ)⁽ⁿ⁾ = m(m-1)...(m-n+1) · xᵐ⁻ⁿ

数值求高阶导数

def numerical_derivative_n(func, x, n, h=1e-4):
    """
    数值求 n 阶导数

    参数:
        func: 函数
        x: 求导点
        n: 阶数
        h: 步长

    返回:
        float: n 阶导数的近似值
    """
    if n == 1:
        return numerical_derivative(func, x, h)
    else:
        def derivative_func(t):
            return numerical_derivative(func, t, h)
        return numerical_derivative_n(derivative_func, x, n-1, h)

实例分析

实例1:求 f(x) = sin x 的二阶导数

def f_sin(x):
    """函数 f(x) = sin x"""
    return math.sin(x)

x = math.pi/4
second_derivative = numerical_derivative_n(f_sin, x, 2)
print(f"f''(x) 在 x={x:.4f} 处的值: {second_derivative:.6f}")
print(f"理论值 (-sin x): {-math.sin(x):.6f}")

实例2:求 f(x) = eˣ 的三阶导数

def f_exp(x):
    """函数 f(x) = eˣ"""
    return math.exp(x)

x = 1
third_derivative = numerical_derivative_n(f_exp, x, 3)
print(f"f'''(x) 在 x={x} 处的值: {third_derivative:.6f}")
print(f"理论值 (eˣ): {math.exp(x):.6f}")

(四)导数的应用

1. 切线方程

函数 f(x) 在点 (x₀, f(x₀)) 处的切线方程:

y - f(x₀) = f'(x₀) · (x - x₀)

def tangent_line(func, x0, x):
    """
    计算切线在 x 处的值

    参数:
        func: 函数
        x0: 切点
        x: 求值点

    返回:
        float: 切线在 x 处的值
    """
    slope = numerical_derivative(func, x0)
    y0 = func(x0)
    return y0 + slope * (x - x0)

# 示例
def f(x):
    return x**2

x0 = 1
for x in [0.5, 1, 1.5]:
    y = f(x)
    y_tangent = tangent_line(f, x0, x)
    print(f"x={x}: f(x)={y:.4f}, 切线值={y_tangent:.4f}")

2. 函数的极值

定理:如果 f(x) 在 x₀ 处可导,且 f'(x₀) = 0,则 x₀ 可能是极值点。

判别法: - 如果 f'(x) 在 x₀ 左侧为正,右侧为负,则 x₀ 是极大值点 - 如果 f'(x) 在 x₀ 左侧为负,右侧为正,则 x₀ 是极小值点

def find_extrema(func, x_range, step=0.01):
    """
    寻找函数的极值点

    参数:
        func: 函数
        x_range: x 的范围 [a, b]
        step: 步长

    返回:
        list: 极值点列表
    """
    extrema = []
    for x in [x_range[0] + i * step for i in range(int((x_range[1] - x_range[0]) / step))]:
        derivative = numerical_derivative(func, x)
        if abs(derivative) < 1e-3:  # 导数接近 0
            extrema.append(x)
    return extrema

# 示例
def f_example(x):
    return x**3 - 3*x**2 + 2

extrema = find_extrema(f_example, [-1, 3])
print(f"极值点: {extrema}")

3. 函数的单调性

定理:如果 f'(x) > 0,则 f(x) 单调递增;如果 f'(x) < 0,则 f(x) 单调递减。

def analyze_monotonicity(func, x_range, step=0.1):
    """
    分析函数的单调性

    参数:
        func: 函数
        x_range: x 的范围 [a, b]
        step: 步长

    返回:
        dict: 单调性分析结果
    """
    increasing = []
    decreasing = []

    for x in [x_range[0] + i * step for i in range(int((x_range[1] - x_range[0]) / step))]:
        derivative = numerical_derivative(func, x)
        if derivative > 0:
            increasing.append(x)
        elif derivative < 0:
            decreasing.append(x)

    return {
        'increasing': increasing,
        'decreasing': decreasing
    }

# 示例
result = analyze_monotonicity(f_example, [-2, 4])
print(f"单调递增区间: x ∈ {result['increasing'][0]:.2f} 到 {result['increasing'][-1]:.2f}")
print(f"单调递减区间: x ∈ {result['decreasing'][0]:.2f} 到 {result['decreasing'][-1]:.2f}")

实战练习

练习1:求复合函数的导数

求 f(x) = e^(x²) 的导数

def f_composite(x):
    """函数 f(x) = e^(x²)"""
    return math.exp(x**2)

# 数值求导
for x in [0, 1, 2]:
    derivative = numerical_derivative(f_composite, x)
    print(f"f'(x) 在 x={x} 处的值: {derivative:.6f}")
    # 理论值: 2x · e^(x²)
    theoretical = 2 * x * math.exp(x**2)
    print(f"理论值: {theoretical:.6f}")

练习2:求隐函数的导数

求由方程 x² + y² = 1 确定的隐函数的导数 dy/dx

def implicit_derivative(x, y):
    """
    隐函数求导

    方程: x² + y² = 1

    对两边求导: 2x + 2y · dy/dx = 0
    所以: dy/dx = -x/y
    """
    return -x / y

# 示例
for (x, y) in [(0, 1), (1/√2, 1/√2), (1, 0)]:
    dy_dx = implicit_derivative(x, y)
    print(f"在点 ({x:.4f}, {y:.4f}) 处: dy/dx = {dy_dx:.4f}")

练习3:优化问题

求函数 f(x) = x³ - 3x² + 2 的极值

def f_optimization(x):
    """函数 f(x) = x³ - 3x² + 2"""
    return x**3 - 3*x**2 + 2

# 寻找极值点
extrema = find_extrema(f_optimization, [-1, 3])
print(f"极值点: {extrema}")

# 计算极值
for x in extrema:
    y = f_optimization(x)
    print(f"极值点 x={x:.4f}, f(x)={y:.4f}")

章节小结

本章介绍了导数的基本概念和应用:

  1. 导数的定义:理解导数的定义和几何意义
  2. 求导法则:掌握常数、和差、乘积、商和链式法则
  3. 高阶导数:学会求高阶导数
  4. 导数的应用:理解切线、极值、单调性等应用
  5. 数值求导:掌握数值求导方法

导数是微积分的核心,是理解函数变化规律的重要工具。

下一步

继续学习第三章:积分,学习不定积分和定积分的概念、计算方法和应用。


重点提醒: - 导数表示函数的变化率 - 链式法则是求复合函数导数的关键 - 数值求导是理解导数的重要工具 - 导数的应用广泛,需要熟练掌握