Maple 微积分实验考试2
Maple Calculus Lab Test 2
MATH1131 核心命令复习
MATH1131 Core Commands Review
针对实验考试的 Maple 核心命令复习,涵盖函数定义、求解、绘图与极值问题
Essential Maple commands for lab exam, covering function definition, solving, plotting, and extremum problems
💡 复习提示: 本笔记涵盖10个核心Maple知识点,建议先完整阅读理解概念,再进行互动测验巩固学习成果。
💡 Study Tip: These notes cover 10 core Maple concepts. We recommend reading through all concepts first, then taking the interactive quiz to reinforce your learning.
这是 Maple 中最基本也最重要的命令之一。它用来给一个变量赋值。
- 用途:将一个数字、一个表达式、一个函数或者一个计算结果存到一个你命名的变量里。
- 语法:变量名 := 值或表达式;
- 注意:它和数学里的单个等号 = 不同。= 在 Maple 里只用于表示一个方程,比如 fsolve 里的 df(x) = 0。
df := D(f); // 将 f 的导函数结果赋值给变量 df
x0 := 0.12345; // 将数值 0.12345 赋值给变量 x0
result := x^2 + 3*x; // 将表达式赋值给变量 result
这用于创建一个可以重复使用的函数。
- 用途:定义一个数学函数,之后可以方便地代入不同的值进行计算。
- 语法:函数名 := 自变量 -> 表达式;
- 调用:定义之后,你就可以像 f(0.1) 或 f(x0) 这样来调用它了。
f := x -> 7^x + 7*cos(7*x/2); // 定义函数 f
g := (x, y) -> x^2 + y^2; // 定义二元函数 g
h := t -> sin(t) * exp(-t); // 定义函数 h
// 函数调用
f(0.1); // 计算 f 在 x=0.1 处的值
g(2, 3); // 计算 g(2,3) 的值
这是 Maple 的求导算子。
- 用途:计算一个函数或表达式的导数。
- 语法:
- 求一阶导数: D(函数名)
- 求二阶导数: D(一阶导函数名) 或者 (D@@2)(原函数名)
f := x -> x^3 + 2*x^2 - 5*x + 1; // 定义函数
df := D(f); // 计算 f 的一阶导数,并存入 df
ddf := D(df); // 计算 df 的导数,即 f 的二阶导数
ddf := (D@@2)(f); // 直接计算 f 的二阶导数,效果同上
// 求导数在特定点的值
df(2); // 计算导数在 x=2 处的值
当方程无法直接解出精确的符号解时,用它来找数值解(近似解)。
- 用途:求解单个或多个方程的数值解。
- 语法:
- 基本形式: fsolve(方程, 变量);
- 在指定区间内求解: fsolve(方程, 变量 = 起点..终点);
// 基本求解
f := x -> x^3 - 2*x - 5;
fsolve(f(x) = 0, x); // 在整个实数范围寻找解
// 指定区间求解
fsolve(df(x) = 0, x = 0..0.3); // 在 x 位于 0 和 0.3 之间寻找解
fsolve(sin(x) = 0.5, x = 0..Pi); // 在指定区间内求解三角方程
这是一个全局变量,用来控制所有浮点数计算的有效数字位数。
- 用途:设定计算结果的精度。
- 语法:Digits := 你想要的数字;
- 注意:Maple 严格区分大小写,Digits 不能写成 digits。
Digits := 10; // 设置10位有效数字
evalf(Pi); // 计算 π 的近似值
Digits := 20; // 提高精度到20位
evalf(sqrt(2)); // 计算 √2 的高精度近似值
这是解决数值定积分问题的核心组合。
- int() 的用途:用来表示一个数学上的积分(定积分或不定积分)。它本身只是建立一个积分的符号表达式。
- evalf() 的用途:用来将一个符号表达式(包括 int 创建的积分表达式)计算出其具体的浮点数值(小数)。
- 组合用途:evalf(int(...)) 是解决数值定积分问题的标准"黄金组合"。
// 数值定积分
integrand := (exp(-x) * cos(x^2 / 3)) / (5 + x);
evalf(int(integrand, x = 0..infinity));
// 有限区间积分
evalf(int(x^2 * sin(x), x = 0..Pi));
// 不定积分(符号积分)
int(x^2 * exp(x), x); // 返回符号结果
- 无穷大 ∞ → infinity
- 圆周率 π → Pi (P大写)
- 虚数单位 i → I (I大写)
- 自然对数的底 e → 通过 exp(1) 表示
这是解决"根据函数选择图像"这类问题的核心命令。
- 用途:用于绘制极坐标系下的函数图像 r = f(θ)。这对于从多个选项中选择正确图像的题目至关重要。
- 重要前提:绘图功能通常在一个叫 plots 的程序包里,因此需要先用 with(plots); 命令加载这个包。
- 语法:polarplot(r的表达式, 角度变量 = 下限..上限);
with(plots); // 加载绘图包
polarplot(3*sin(theta) - cos(4*theta), theta = 0..2*Pi);
// 玫瑰曲线
polarplot(sin(3*theta), theta = 0..Pi);
// 心形线
polarplot(1 + cos(theta), theta = 0..2*Pi);
// 螺旋线
polarplot(theta, theta = 0..4*Pi);
- 加载程序包:with(plots); 只需要在每个 Maple 会话的开头执行一次。
- 变量名:Maple 能够直接识别 theta 作为希腊字母 θ。
- 常数:圆周率 π 必须写作 Pi (P大写),例如 2*Pi。
- 输出类型:这个命令的输出是一个图像,而不是一个数值。
用于求解方程,并给出精确的符号解(例如整数、分数、根式等)。
- 用途:求解方程,给出精确的符号解。这在题目要求 "exact values" 时至关重要。
- 与 fsolve() 的区别:solve() 追求精确解;fsolve() 给出数值近似解(小数)。
- 语法:solve(方程, 变量);
// 二次方程的精确解
solve(x^2 + 2*x - 24 = 0, x); // 输出精确的整数解 -6, 4
solve(x^2 - 2 = 0, x); // 输出带根号的精确解 sqrt(2), -sqrt(2)
// 三角方程的精确解
solve(sin(x) = 1/2, x); // 输出精确的角度解
// 系统方程
solve({x + y = 5, x - y = 1}, {x, y}); // 解方程组
- 使用 solve():当题目要求精确值、分数、根式等符号形式的答案时。
- 使用 fsolve():当需要数值近似解,或者方程过于复杂无法得到符号解时。
这是解决"求函数在闭区间 [a,b] 上的绝对最大/最小值"这类问题的标准方法。
任何一个在闭区间 [a,b] 上的连续函数,都必然存在一个绝对最大值和一个绝对最小值。
这些最大/最小值只会出现在以下三类"候选点"上:
- 驻点 (Stationary Points):在区间内部 (a, b),使得导数 f'(x) = 0 的点。
- 奇点 (Singular Points):在区间内部 (a, b),使得导数 f'(x) 不存在的点。
- 区间端点 (Endpoints):即 x = a 和 x = b。
- 找出所有候选点:驻点、奇点、端点。
- 筛选:只保留所有在闭区间 [a,b] 内的、不重复的候选点。
- 求值:将筛选后的所有候选点逐个代入原始函数 f(x) 中计算函数值。
- 比较:所有计算出的函数值中,最大的就是绝对最大值,最小的就是绝对最小值。
f := x -> abs(x^3 - 2*x^2 - 7*x - 4);
g := x -> x^3 - 2*x^2 - 7*x - 4;
// 找驻点:求解 g'(x) = 0
solve(D(g)(x) = 0, x);
// 找奇点:求解 g(x) = 0(绝对值函数的尖角点)
solve(g(x) = 0, x);
// 然后手动筛选在指定区间内的点,代入原函数求值并比较
limit 命令是 Maple 中计算函数极限的核心工具,尤其在处理洛必达法则问题时,它是你最可靠的验证助手。
只有当极限是 0/0 或 ∞/∞ 的不定式时,才可以尝试使用洛必达法则。
- 验证前提:分别计算分子和分母的极限,以确定极限的类型。这是判断能否使用洛必达法则的关键一步。
- 验证答案:直接计算整个分式的极限,以核对你的最终答案(无论是否使用了洛必达法则)。
- 双边极限:limit(表达式, 变量=趋近的值);
- 单边极限:limit(表达式, 变量=趋近的值, left); 或 limit(表达式, 变量=趋近的值, right);
// 基本极限计算
limit(sin(x)/x, x=0); // 输出 1
// 单边极限
limit(ln(x), x=0, right); // 输出 -infinity
// 验证洛必达法则条件的例子
// 问题: lim(x->0) cos(x)/ln(x) 是否可用洛必达?
// 1. 验证分子极限
limit(cos(x), x=0); // 输出: 1
// 2. 验证分母极限
limit(ln(x), x=0, right); // 输出: -infinity
// 3. 结论: 极限类型是 1/(-∞),不是不定式,不能使用洛必达法则
- 分别计算分子和分母的极限
- 判断是否为 0/0 或 ∞/∞ 不定式
- 如果是不定式,可以使用洛必达法则
- 如果不是,直接计算原极限或使用其他方法
- 最后用 limit 命令验证最终答案
Digits := 10;
f := x -> 3*sin(x^2/2) - (sin(x/2))^2;
df := D(f);
x0 := fsolve(df(x) = 0, x = 1..2);
ddf := D(df);
ddf(x0);
Digits := 10;
integrand := (exp(-x) * cos(x^2 / 3)) / (5 + x);
evalf(int(integrand, x = 0..infinity));
with(plots);
polarplot(3*sin(theta) - cos(4*theta), theta = 0..2*Pi);
This is one of the most basic and important commands in Maple. It is used to assign values to variables.
- Purpose: Store a number, expression, function, or calculation result into a variable you name.
- Syntax: variable_name := value_or_expression;
- Note: It differs from the single equals sign = in mathematics. In Maple, = is only used to represent an equation, such as df(x) = 0 in fsolve.
df := D(f); // Assign the derivative of f to variable df
x0 := 0.12345; // Assign the value 0.12345 to variable x0
result := x^2 + 3*x; // Assign the expression to variable result
This is used to create a reusable function.
- Purpose: Define a mathematical function that can be easily evaluated at different values.
- Syntax: function_name := variable -> expression;
- Usage: After definition, you can call it like f(0.1) or f(x0).
f := x -> 7^x + 7*cos(7*x/2); // Define function f
g := (x, y) -> x^2 + y^2; // Define two-variable function g
h := t -> sin(t) * exp(-t); // Define function h
// Function calls
f(0.1); // Calculate f at x=0.1
g(2, 3); // Calculate g(2,3)
This is Maple's differentiation operator.
- Purpose: Calculate the derivative of a function or expression.
- Syntax:
- First derivative: D(function_name)
- Second derivative: D(first_derivative_name) or (D@@2)(original_function_name)
f := x -> x^3 + 2*x^2 - 5*x + 1; // Define function
df := D(f); // Calculate first derivative of f, store in df
ddf := D(df); // Calculate derivative of df, i.e., second derivative of f
ddf := (D@@2)(f); // Directly calculate second derivative of f, same result
// Evaluate derivative at a specific point
df(2); // Calculate derivative value at x=2
When an equation cannot be solved exactly, use this to find numerical solutions (approximate solutions).
- Purpose: Find numerical solutions to single or multiple equations.
- Syntax:
- Basic form: fsolve(equation, variable);
- Solve in a specified interval: fsolve(equation, variable = start..end);
// Basic solving
f := x -> x^3 - 2*x - 5;
fsolve(f(x) = 0, x); // Find solution in entire real range
// Solve in specified interval
fsolve(df(x) = 0, x = 0..0.3); // Find solution where x is between 0 and 0.3
fsolve(sin(x) = 0.5, x = 0..Pi); // Solve trigonometric equation in specified interval
This is a global variable that controls the number of significant digits in all floating-point calculations.
- Purpose: Set the precision of calculation results.
- Syntax: Digits := desired_number;
- Note: Maple is case-sensitive, so Digits cannot be written as digits.
Digits := 10; // Set 10 significant digits
evalf(Pi); // Calculate approximation of π
Digits := 20; // Increase precision to 20 digits
evalf(sqrt(2)); // Calculate high-precision approximation of √2
This is the core combination for solving numerical definite integral problems.
- int() purpose: Represents a mathematical integral (definite or indefinite). It only creates a symbolic integral expression.
- evalf() purpose: Calculates the floating-point value (decimal) of a symbolic expression (including integral expressions created by int).
- Combined use: evalf(int(...)) is the standard "golden combination" for solving numerical definite integrals.
// Numerical definite integral
integrand := (exp(-x) * cos(x^2 / 3)) / (5 + x);
evalf(int(integrand, x = 0..infinity));
// Finite interval integral
evalf(int(x^2 * sin(x), x = 0..Pi));
// Indefinite integral (symbolic integration)
int(x^2 * exp(x), x); // Returns symbolic result
- Infinity ∞ → infinity
- Pi π → Pi (capital P)
- Imaginary unit i → I (capital I)
- Natural logarithm base e → represented as exp(1)
This is the core command for solving "choose the correct graph from function" type problems.
- Purpose: Plot functions in polar coordinates r = f(θ). This is crucial for questions where you need to select the correct graph from multiple options.
- Important prerequisite: Plotting functions are usually in a package called plots, so you need to load it first with the with(plots); command.
- Syntax: polarplot(r_expression, angle_variable = lower..upper);
with(plots); // Load plotting package
polarplot(3*sin(theta) - cos(4*theta), theta = 0..2*Pi);
// Rose curve
polarplot(sin(3*theta), theta = 0..Pi);
// Cardioid
polarplot(1 + cos(theta), theta = 0..2*Pi);
// Spiral
polarplot(theta, theta = 0..4*Pi);
- Loading package: with(plots); only needs to be executed once at the beginning of each Maple session.
- Variable name: Maple can directly recognize theta as the Greek letter θ.
- Constants: Pi must be written with capital P, e.g., 2*Pi.
- Output type: The output of this command is a graph, not a numerical value.
Used to solve equations and give exact symbolic solutions (e.g., integers, fractions, radicals).
- Purpose: Solve equations with exact symbolic solutions. This is crucial when questions require "exact values".
- Difference from fsolve(): solve() seeks exact solutions; fsolve() gives numerical approximate solutions (decimals).
- Syntax: solve(equation, variable);
// Exact solutions to quadratic equations
solve(x^2 + 2*x - 24 = 0, x); // Outputs exact integer solutions -6, 4
solve(x^2 - 2 = 0, x); // Outputs exact solutions with radicals sqrt(2), -sqrt(2)
// Exact solutions to trigonometric equations
solve(sin(x) = 1/2, x); // Outputs exact angle solutions
// System of equations
solve({x + y = 5, x - y = 1}, {x, y}); // Solve system of equations
- Use solve(): When questions require exact values, fractions, radicals, or other symbolic form answers.
- Use fsolve(): When you need numerical approximate solutions, or the equation is too complex for symbolic solutions.
This is the standard method for solving "find the absolute maximum/minimum of a function on a closed interval [a,b]" type problems.
Any continuous function on a closed interval [a,b] must have an absolute maximum and an absolute minimum.
These maximum/minimum values can only occur at the following three types of "candidate points":
- Stationary Points: Points inside the interval (a, b) where the derivative f'(x) = 0.
- Singular Points: Points inside the interval (a, b) where the derivative f'(x) does not exist.
- Endpoints: Namely x = a and x = b.
- Find all candidate points: Stationary points, singular points, endpoints.
- Filter: Keep only the unique candidate points within the closed interval [a,b].
- Evaluate: Substitute each filtered candidate point into the original function f(x) to calculate function values.
- Compare: Among all calculated function values, the largest is the absolute maximum, the smallest is the absolute minimum.
f := x -> abs(x^3 - 2*x^2 - 7*x - 4);
g := x -> x^3 - 2*x^2 - 7*x - 4;
// Find stationary points: solve g'(x) = 0
solve(D(g)(x) = 0, x);
// Find singular points: solve g(x) = 0 (corner points of absolute value function)
solve(g(x) = 0, x);
// Then manually filter points within the specified interval, substitute into original function and compare
The limit command is Maple's core tool for calculating function limits. It is your most reliable verification assistant when dealing with L'Hopital's rule problems.
L'Hopital's rule can only be attempted when the limit is an indeterminate form of 0/0 or ∞/∞.
- Verify conditions: Calculate limits of numerator and denominator separately to determine the type of limit. This is a crucial step in deciding whether L'Hopital's rule can be applied.
- Verify answers: Directly calculate the limit of the entire fraction to check your final answer (whether or not L'Hopital's rule was used).
- Two-sided limit: limit(expression, variable=approaching_value);
- One-sided limit: limit(expression, variable=approaching_value, left); or limit(expression, variable=approaching_value, right);
// Basic limit calculation
limit(sin(x)/x, x=0); // Outputs 1
// One-sided limit
limit(ln(x), x=0, right); // Outputs -infinity
// Example of verifying L'Hopital's rule conditions
// Question: Can lim(x->0) cos(x)/ln(x) use L'Hopital's rule?
// 1. Verify numerator limit
limit(cos(x), x=0); // Output: 1
// 2. Verify denominator limit
limit(ln(x), x=0, right); // Output: -infinity
// 3. Conclusion: The limit type is 1/(-∞), not an indeterminate form, cannot use L'Hopital's rule
- Calculate limits of numerator and denominator separately
- Determine if it's a 0/0 or ∞/∞ indeterminate form
- If it's an indeterminate form, L'Hopital's rule can be used
- If not, calculate the original limit directly or use other methods
- Finally use the limit command to verify the final answer
Digits := 10;
f := x -> 3*sin(x^2/2) - (sin(x/2))^2;
df := D(f);
x0 := fsolve(df(x) = 0, x = 1..2);
ddf := D(df);
ddf(x0);
Digits := 10;
integrand := (exp(-x) * cos(x^2 / 3)) / (5 + x);
evalf(int(integrand, x = 0..infinity));
with(plots);
polarplot(3*sin(theta) - cos(4*theta), theta = 0..2*Pi);