You are on page 1of 76

# 2002年1月

I

I

《由浅入深 Maple 6》是《精点 Maple 6》丛书的第一本，它涉及了 Maple 6 运行环境、 变量和函数的使用方法、代数问题的演算、几何对象的建立、图形动画的绘制、高等数学问 题的处理、Maple 编程语言的结构、以及 Maple 文件的操作等各方面的内容，是整套丛书的 基础读物。书中每一章集中讲解一个方面的知识，并且每一章开头都以简单易懂的实例作为 引导，对所有操作步骤都有简洁准确的说明。本书的目的就是全面地介绍 Maple 6 能够帮助 大家作些什么，并以生动的实例讲解如何进行操作。

I

# 目 录

 第一篇 初步篇 第1章 Maple 6 起步 ·········································································································2 1.1 什么是Maple ···········································································································3 1.2 Maple的结构 ···········································································································5 1.3 Maple的功能 ···········································································································5 1.3.1 算术 ················································································································7 1.3.2 变量和多项式 ·································································································9 1.3.3 解方程 ··········································································································10 1.3.4 绘图 ·············································································································· 11 1.3.5 表格 ··············································································································13 1.3.6 构造文档 ······································································································14 1.3.7 在线帮助系统 ·······························································································17 1.4 Maple 6 的新特性 ································································································18 1.5 本章小结 ···············································································································18 第2章 安装与设置 ···········································································································19 2.1 系统要求 ···············································································································20 2.2 安装Maple 6··········································································································20 2.3 设置Maple 6··········································································································23 2.2.1 内核模式 ······································································································23 2.2.2 初始化 ··········································································································26 2.4 本章小结 ···············································································································27 第3章 Maple 6运行界面 ·································································································28 3.1 File（文件）菜单 ·································································································29 3.1.1 打开与关闭文件 ···························································································29 3.1.2 保存文件 ······································································································30 3.1.3 文件输出 ······································································································31 3.2 Edit（编辑）菜单 ·································································································33 3.2.1 常规操作 ······································································································34 3.2.2 辅助操作 ······································································································35 3.2.3 专有操作 ······································································································36 3.3 View（查看）菜单 ·······························································································37 3.3.1 按钮工具 ······································································································37 3.3.2 模板工具 ······································································································41 3.3.3 定位工具 ······································································································41 3.3.4 缩略工具 ······································································································42 3.3.5 隐藏工具 ······································································································43

II

 3.4.1 插入文字 ······································································································44 3.4.2 插入对象 ······································································································45 3.5 Format（格式）菜单 ····························································································46 3.5.1 文字类型 ······································································································46 3.5.2 版面格式 ······································································································47 3.5.3 类型转换 ······································································································48 3.6 Spreadsheet（表格）菜单 ····················································································49 3.6.1 表格内容更新 ·······························································································50 3.6.2 表格数据操作 ·······························································································50 3.6.3 表格设置 ······································································································51 3.7 Option（选项）菜单 ····························································································52 3.7.1 环境选项 ······································································································52 3.7.2 显示选项 ······································································································54 3.8 Window（窗口）菜单 ··························································································55 3.9 Help（帮助）菜单································································································57 3.10 本章小结 ·············································································································60 第二篇 运用篇 第4章 Maple中的数 ········································································································62 4.1 数的分类和Maple指令规则 ·················································································63 4.2 整数与分数 ···········································································································64 4.3 小数 ·······················································································································67 4.4 代数数 ···················································································································69 4.5 复数 ·······················································································································71 4.6 有效数字 ···············································································································73 4.7 本章小结 ···············································································································74 第5章 Maple中的变量 ····································································································75 5.1 变量赋值 ···············································································································76 5.1.1 变量赋值与释放 ···························································································76 5.1.2 查看变量赋值状态 ·······················································································79 5.2 变量名 ···················································································································82 5.3 变量的值 ···············································································································84 5.4 数据类型 ···············································································································86 5.4.1 常用数据类型 ·······························································································86 5.4.2 查看数据类型 ·······························································································88 5.5 变量属性 ···············································································································89 5.6 变量假定 ···············································································································90 5.7 本章小结 ···············································································································92 第6章 Maple中的函数 ····································································································94

III

• 6.1.1 赋值符号“:=···························································································95

• 6.1.2 箭头操作符···································································································96

• 6.1.3 命令unapply··································································································98

• 6.1.4 命令proc ·······································································································99

 6.2 常用Maple函数 ··································································································· 100 6.2.1 数学函数 ···································································································· 100 6.2.2 分段函数 ···································································································· 102 6.2.3 复合函数 ···································································································· 105 6.2.4 匿名函数 ···································································································· 106 6.3 本章小结 ············································································································· 107 第7章 初等代数 ············································································································· 108 7.1 多项式与有理式 ································································································· 109 7.1.1 一元多项式································································································· 101 7.1.2 多元多项式································································································· 113 7.1.3 有理式 ········································································································ 114 7.2 多项式与函数的操作 ························································································· 116 7.2.1 表达式简化（simplify） ············································································ 116 7.2.2 展开（expand） ························································································· 118 7.2.3 分类化简（combine） ··············································································· 119 7.2.4 标准化（normal） ····················································································· 120 7.2.5 合并同类项（collect） ·············································································· 121 7.2.6 排序（sort）······························································································· 123 7.2.7 转换（convert） ························································································· 125 7.2.8 因式分解（factor）···················································································· 126 7.3 代数方程 ············································································································· 127 7.4 方程组 ················································································································· 129 7.4.1 线性方程组································································································· 129 7.4.2 解的校验 ···································································································· 131 7.4.3 非线性方程组 ····························································································· 132 7.5 数值求解 ············································································································· 135 7.6 不等式 ················································································································· 138 7.7 需要说明的问题 ································································································· 140 7.7.1 没有结果 ···································································································· 140 7.7.2 结果不完整································································································· 141 7.8 本章小结 ············································································································· 143 第8章 平面几何 ············································································································· 145 8.1 平面几何概述 ····································································································· 146 8.2 平面点 ················································································································· 147 8.3 线段 ····················································································································· 155 8.4 直线 ····················································································································· 158 8.5 圆························································································································· 165 8.6 椭圆 ····················································································································· 173

IV

• 8.8 圆双曲线 ············································································································· 179

• 8.9 多边形与多角形 ································································································· 183

• 8.10 二次曲线 ··········································································································· 186

• 8.11 正方形 ··············································································································· 188

• 8.12 三角形 ··············································································································· 190

• 8.13 平面图形的变换 ······························································································· 202

• 8.14 平面几何图形绘制 ··························································································· 211

• 8.15 本章小结 ··········································································································· 214

9

• 9.1 空间点 ················································································································· 216

• 9.2 空间线段和有向线段 ························································································· 220

• 9.3 空间直线 ············································································································· 221

 9.4 平面 ····················································································································· 226 9.5 球体 ····················································································································· 229
• 9.6 多面体 ················································································································· 233

• 9.7 立体几何图形变换 ····························································································· 237

• 9.8 本章小结 ············································································································· 243

 第三篇 提高篇 第10章 Maple绘图 ········································································································ 245
• 10.1 平面绘图 ··········································································································· 246

• 10.1.1 参数方程 ·································································································· 248

• 10.1.2 极坐标 ······································································································ 250

• 10.1.3 间断函数 ·································································································· 252

• 10.1.4 多重绘图 ·································································································· 256

• 10.1.5 散点图 ······································································································ 257

• 10.2 三维图形 ··········································································································· 258

• 10.2.1 参数方程 ·································································································· 260

• 10.2.2 柱坐标 ······································································································ 261

• 10.2.3 球坐标 ······································································································ 263

• 10.2.4 网格密度 ·································································································· 264

• 10.2.5 光源 ·········································································································· 265

• 10.3 文字标注 ··········································································································· 266

• 10.3.1 标题 ·········································································································· 266

• 10.3.2 坐标轴标注 ······························································································· 267

• 10.3.3 标签 ·········································································································· 268

• 10.4 特殊绘图 ··········································································································· 269

• 10.4.1 隐函数绘图 ······························································································· 269

• 10.4.2 不等式绘图 ······························································································· 269

• 10.4.3 对数坐标 ·································································································· 270

• V

 10.4.5 等值线 ······································································································ 272 10.4.6 空间曲线与管状图 ··················································································· 273 10.4.7 三维直方图 ······························································································· 274 10.4.8 轨迹图 ······································································································ 274 10.5 plottools工具包 ································································································· 275 10.6 简单动画 ··········································································································· 281 10.6.1 二维动画 ·································································································· 281 10.6.2 三维动画 ·································································································· 282 10.7 图形复合 ··········································································································· 284 10.8 本章小结 ··········································································································· 286 第11章 线性代数 ··········································································································· 288 11.1 线性代数工具包 ······························································································· 289 11.2 向量 ··················································································································· 289 11.2.1 定义向量 ··································································································· 289 11.2.2 向量运算 ··································································································· 290 11.3 矩阵 ··················································································································· 292 11.3.1 定义矩阵 ··································································································· 293 11.3.2 矩阵运算 ··································································································· 293 11.3.3 矩阵操作 ··································································································· 296 11.4 解线性方程组 ··································································································· 297 11.4.1 消元法 ······································································································ 298 11.4.2 逆矩阵法 ··································································································· 299 11.4.3 命令linsolve ······························································································ 299 11.5 本章小结 ··········································································································· 300 第12章 微积分与级数 ··································································································· 301 12.1 极限 ··················································································································· 302 12.2 微分 ··················································································································· 305 12.2.1 微分命令 ·································································································· 305 12.2.2 多次微分 ·································································································· 306 12.2.3 多元函数微分 ··························································································· 307 12.2.4 隐函数求导 ······························································································· 307 12.3 积分 ··················································································································· 309 12.3.1 不定积分 ·································································································· 309 12.3.2 定积分 ······································································································ 310 12.3.3 近似积分 ·································································································· 310 12.4 级数 ··················································································································· 312 12.5 本章小结 ··········································································································· 314 第13章 编程初步 ··········································································································· 315 13.1 简单程序设计 ··································································································· 316 13.2 选择结构 ··········································································································· 317 13.3 循环结构 ··········································································································· 318

VI

• 13.5 子程序和函数 ··································································································· 321

• 13.5.1 定义函数（proc···················································································· 322

• 13.5.2 函数中的返回命令（RETURN···························································· 327

• 13.5.3 出错处理（ERROR·············································································· 328

• 13.6 本章小结 ··········································································································· 329

• 14

文件操作与输入与输出 ··················································································· 330

• 14.1 Maple文件 ········································································································· 331

• 14.2 文件操作 ··········································································································· 332

• 14.3 读文件 ··············································································································· 333

• 14.3.1 读取数据 ·································································································· 333

• 14.3.2 读取命令 ·································································································· 335

• 14.4 写文件 ··············································································································· 335

• 14.4.1 指定输出方向 ···························································································

• 336

• 14.4.2 保存数据 ·································································································· 337

• 14.4.3 保存变量、表达式 ··················································································· 339

• 14.5 输出工作表 ······································································································· 339

• 14.5.1 输出文本 ·································································································· 340

• 14.5.2 输出LATEX代码 ······················································································ 341

• 14.5.3 输出FORTRAN代码················································································· 341

• 14.6 图形输出 ··········································································································· 343

• 14.7 本章小结 ··········································································································· 343

• 基本认识；

# 初 步 篇

对于初次接触 Maple 的读者来讲，一定会有一种感觉，那就是：虽然通过前言的

介绍知道了 Maple 可以帮助我们进行数学运算，但是仍然不知道它是怎么工作的，也不

知道它到底能做哪些具体的事情，更不知道我们应当如何使用它。

为了消除读者怀有的这些疑惑，本书以前三章组成“初步篇”：

首先扼要说明了 Maple 的组织结构，并借助一些典型范例介绍了 Maple 在各个数

学分支中的使用情况，以引导读者循序渐进地了解 Maple 的应用领域、建立对 Maple

然后讲述了怎样将 Maple 安装到计算机上，指出了 Maple 与其他应用软件在安装

过程中的不同之处和注意事项，并结合 Maple 运行核心的两种具体形式介绍了配置方法， 大家可以根据自己的实际情况加以选择； 最后向读者介绍怎样打开 Maple，介绍了用户界面的构成，并讲解一些主要菜单的 功能和使用方法，其中穿插的一些具体的示例，目的是帮助读者学习这些菜单的使用。 读者在学习了“初步篇”中的内容后，一定会对 Maple 的特点及功能有一个全面 的了解，并且能够掌握一些基本的操作。 好了，现在就开始吧！

# Maple 6 起步

Maple 作为一种简便实用的数学运算工具，越来越受到大家

的重视。但是它能够帮助我们做什么、有哪些特点、适用范围有 多广呢？本章的目的就是回答以上的问题，帮助读者对 Maple 6 产生一个总体印象。 本章主要介绍 Maple 的初步知识、基本功能及版本 6 的主 要特点。首先介绍了 Maple 的来历、应用领域；简单地阐述了 Maple 的组织结构；以代表性的实例讲述了 Maple 的主要功能； 并扼要介绍了 Maple 6 的一些特性。

本章主要包括以下内容：

 什么是 Maple Maple 的结构 Maple 的功能 Maple 6 的新特性

• 1.1 什么是 Maple

Maple 是一个具有强大符号运算能力、数值计算能力、图形处理能力的交互式计算

机代数系统（Computer Algebra System），它主要用于对各种数据、图形的计算和生成，

以及对这些结果的编辑。它可以借助键盘和显示器代替原来的笔和纸进行数学运算。可

以用它解决各种方程、方程组、微分方程、线性代数等数学问题，得到它们的解析解或

者数值解。数学、物理等各方面的理论和应用问题都可以利用 Maple 所带的各种软件包

来解决。这个超强的计算工具不仅适合于数学家、物理学家、工程师，还适合于化学家，

生物学家，社会学家，总之它适合于所有需要数学计算的人。

所谓计算机代数系统，就是指能够对符号和表达式进行运算，并能够求解方程和处

理函数的计算机软件。计算机代数系统的研究开发最早开始于 1959 年，那时，麻萨诸塞

州的一群研究人员开始研制一个称为 MACSYMA 的计算机软件，也就是早期的计算机

代数系统。这些人对计算机充满了信心，认为计算机能够帮助人类完成许多重要的智能

型工作，而数学用来作为载体以展示计算机在机器智能方面的能力（之所以选择数学作 为载体，是因为数学具有很强的规律性和结构性）。MACSYMA 的开发成功证明了计算 机在处理数学问题方面（如求解微分方程）并不象以前想象的那样困难，实际上教会机 器去求解数学问题不比教会人去求解数学问题更难。 在 1980 年，沃特卢(加拿大东南部城市)大学的一些研究者开始探讨计算机代数系统 在工程等领域的应用问题。它们对手头已有的一些计算工具并不满意，根据实际需要和 以往工作中的经验，他们又提出了新的计算机代数系统应当满足的标准：首先，新的系 统必须允许广大的用户（包括学生）在较低配置的计算机上使用；其次，新的系统必须 具有清晰的逻辑性和浅显易懂的语法结构；最重要的是，新的系统必须便于日后升级。 为此，这些研究者成立了“符号运算小组”，这个研究小组潜心于满足上述标准的计算机 代数系统的研究。后来，他们的研究成果被称为 Maple。 大家都知道，在处理数学和物理问题的时候，经常遇到的是大量繁琐的数学运算， 除了面临字符形式的公式推导，还要进行许多数值运算工作。在得到一个结果后，还要 对以前的运算过程进行验算以保证其正确率。如果所处理的问题稍微复杂一些，那么用 传统的手工加草稿纸的运算方式将会消耗大量的人力和物力，而且每当某一步骤出现问 题时，就不得不返回头，在一大堆草稿中搜寻和检查。如此反复几次后，原来还保持一 定顺序的草稿很可能混作一团，原来还清晰的思路很可能变得纵横交错，没有头绪了。 其实，我们大量的精力都花在了重复性的工作上，而且一点小小的失误可能会给整个工 作造成巨大的障碍，甚至成为失败的主要原因。如果利用 Maple 的代数运算功能来帮助 我们处理那些简单而又繁琐的计算工作，或者利用 Maple 的符号运算功能帮助我们推导 公式，那么我们就可以节约出大量时间和精力，并将注意力转移到如何采用更加有效的 方法解决全局问题上。如果在某个环节上出了问题，我们可以容易地检验思路是否正确， 而不用花费精力去怀疑具体的推导和计算过程。如果要对问题的解决方法进行调整，也

的麻烦。
匪浅了。

能够在我们需要的地方直接作修改，然后按几次键盘就能够得到新的结果。如果想对不

同的方法进行比较，可以根据同一个原始文件创建多个运算文档，从而省去了重复抄写

工程师和科研人员常常需要对所研究的物理对象建立数学模型，然后求解这个数学

问题。以往的做法通常是借助编程语言，如 Fortran 等编制计算机程序来求解，虽然现在

有许多标准的样板程序可以用来作为参考，但还是免不了录入的麻烦，恐怕还需要找几

个简单算例来验证，而且对基本方法需要作改动时，往往会花费大量的时间去修改程序。

实际上，Maple 所提供的运算能力完全能够帮助我们去处理这些工作，我们需要作的仅

仅是以标准的、直观的、并且为我们熟知的形式将数学模型输入计算机，然后按下回车

键，等待运算结果。对于普通的数学模型，Maple 能够给出相当直观的符号形式的解析

解；而对于相对复杂的模型，Maple 能够给出任意精度的数值结果。当然，并不是说 Maple

可以求解任意复杂的数学问题，但只要它能够解决大部分常规的问题，我们就已经受益

数据处理是任何计算工作之后必定要做的事，我们需要对计算结果进行统计分析，

需要将结果以图形的方式来表现。比较原始的做法是根据运算结果或实验数据用手工来

描点、绘图；现在常用的方法是将结果整理成数据表格，再利用绘图软件根据数据表绘 制图形。而 Maple 的图形处理功能为我们提供了另一种良好的选择，我们可以直接利用 Maple 的运算结果，键入简单的绘图命令，马上就能够得到所需要的图形。这样，在对 某个过程进行重复修改的时候，就可以省去在计算环境与绘图环境之间来回切换的麻烦 了，而且 Maple 在图形方面的许多附加功能可以帮助我们更好地理解和把握所得到的计 算结果。 我们完全有可能需要将计算结果、图形等整理成报告，Maple 也提供了很好的文档 处理功能。与其它文字处理器相比，Maple 在结构和表达形式上具有很强的优势。首先， 在计算报告中会存在大量的公式和表达式，在 Maple 提供的交互式的编辑环境中，可以 通过简单的操作来创建和组织复杂的公式，使用者既可以键入字符，也可以借助模板直 接输入公式，而 Maple 输出的是标准的数学形式，再加上大家都非常熟悉的一些编辑操 作，很容易创建文字、图形、表达式共存的计算报告；其次，Maple 提供的结构和类型， 可以帮助使用者将计算结果整理成为脉络清晰、层次分明的科技文档。另外，Maple 为 我们提供了较为现代的书签、超链接等工具，有了它们，完全有可能在自己的报告文档 中处于不同位置的相关内容之间建立联系，在必要时进行快速切换；或者将自己的文档 与其他文档联系起来，无论这些文件是在本地还是在远程计算机上。 总之，在数值计算、符号运算以及图形处理方面，以往用手工操作非常费力的、或 者自己编程非常繁琐的、或者可以利用应用软件而无法充分利用现有结果的各项工作， 用 Maple 都可以方便、快捷地加以处理。

• 1.2 Maple 的结构

Maple 作为能够处理数学问题的计算机代数系统，它首先具备的就是能够处理用户

命令输入、管理内部数据的“内核”；而且，为了适应各方面运算的需求，同时又不至于

造成资源浪费，Maple 具备许多外挂的函数库（也称为工具包），在需要时可以由用户自

行加载；Maple 又是一种交互式的应用软件，所以具备良好的图形用户界面，通过这个

接口，用户才能够向 Maple 发出指令并得到执行。

Maple 的结构有如一台计算机， Maple 的“内核” 好比是主机，在这里，用户输

入的命令得到解释和执行，输入的数据和运算的结果得以保存。用户界面好比是显示器

和键盘，通过它们，用户才能够了解 Maple 现在在干什么，才能够对主机下达命令。Maple

的外挂工具包就好比是计算机的可选配件，用户根据不同的需求可以选择性地安装其中

的某一件，就象要上网时插上“猫”、想“OK”时接上音箱一样，所不同的仅仅是调用

工具包 package_name 的时候是使用命令 with(package_name)

• 1.3 Maple 的功能

简单地讲，Maple 是处理数学问题的工具。而数学是研究数和形的科学。 由于生活和劳动上的需求，即使是原始的民族，也知道简单的计算，并由用手指或 实物计数发展到用数字计数。在商代，中国就已经出现用十进制数字表示方法。在《九 章算术》中，已载有开平方、开立方的计算法则，以及分数的各种运算和解线性联立方 程组的方法，并引入了负数的概念。在宋代，出现了“天元”（即未知数）的概念、求高 次方程数值解与求多至四个未知数的代数方程组的方法，与之相伴出现了多项式的表达 及运算法则。在中国以外，F.韦达于 16 世纪以文字代替方程系数，引入了代数的符号演 算。后来，对代数方程解的性质的探讨，则从线性方程组导致行列式、矩阵、线性空间、 线性变换等概念于理论的出现，从代数方程导致复数、对称函数等概念的引入。形的研 究属于几何学的范畴，它是由工具的制作与测量的要求促成的。中国的《墨经》中就曾 经对一系列的几何概念做出了科学的定义，而欧几里得的《几何原本》建立了用定义、 公理、定理、证明构成的演绎体系，成为近代数学公理化的楷模。 初等代数（或称为古典代数）是研究数字和文字的代数运算（加法、减法、乘法、 除法、乘方、开方）的理论和方法，是研究实数或复数和以它们为系数的多项式的代数 运算的理论和方法。它的特点是高度计算性，其中心问题是实或复系数多项式方程（也 称为代数方程）、方程组的求解。 线性代数主要处理线性关系（即数学对象之间的关系是以一次形式表示）问题，它 作为一个独立的分支在 20 世纪才形成。最古老的线性问题是线性方程组的解法，随着研 究线性方程组和变量的线性变换问题的深入，行列式和矩阵在 18~19 世纪期间先后产生， 为处理线性问题提供了有力的工具。向量的引入，形成了向量空间的概念，并且所有线

性问题都可以用向量空间的观点加以讨论，因此，向量空间及其线性变换，以及与此相

联系的矩阵理论，构成了线性代数的中心内容。

微积分是与应用联系发展起来的，如今，它在天文学、力学、物理学、化学、生物

学、工程学、经济学等各领域内，都有越来越广泛的应用。微积分是研究函数的微分、

积分以及有关概念和应用的数学分支。微分学研究函数的导数与微分及其在函数研究中

的应用，其基本思想在于考虑函数在小范围内是否可能用线性函数或多项式函数来任意

近似表示，它是建立在实数、函数、极限、连续性等一组基本概念之上的。积分学主要

研究积分的性质及其在自然科学与技术科学中的应用，其基本思想是通过有限逼近无限，

它包括不定积分和定积分。自从微积分建立以来，建立了许多数学分支，如常微分方程、

偏微分方程、积分方程、泛函分析等，这些分支共同构成了现在的数学分析。

总的来说，在数与形构成的数学世界中出现的所有事物，都是 Maple 的处理对象。

从算术运算到方程组求解，从函数运算到微分和积分，从点、直线等平面几何元素到多

1-1
Maple 6 快捷图

面体、星形体等立体几何对象，都可以用 Maple 来处理。

既然 Maple 可以用来作这么多事情，那么它具体是如

何工作的呢？在这一节里，我们将在 Maple 6 提供的环境

下，通过一些简单示例，概括地介绍 Maple 的功能。 首先要做的是启动 Maple 程序。在 Windows 环境下， 如果已经安装了 Maple 6，在计算机的桌面上就会出现如 图 1-1 所示的快捷图标： 双击该图标就可以启动 Maple 6，启动后屏幕显示见 图 1-2

1-2 初始启动窗口

1.3.1
算术
算术是数学中最古老同时又是最基本的一个分支，它研究数的性质及其运算，包括
正整数、分数、小数的性质以及他们的四则运算（加、减、乘、除）。用 Maple 来做算
术题时，用户完全可以将它作为一个“计算器”使用，这个“计算器”可以处理任何关
于整数、分数以及小数的四则运算。
我们先看整数运算的例子。首先，在命令提示符“>”后键入：
> 2+3;
注意一定要在表达式后面加上“;”，它在 Maple 中用来表示一个命令的结尾（也可
以用“:”作为命令的结尾，但此时 Maple 将不输出任何结果，只是将计算结果保存起
来）。按下回车键，得到：
5
如果没有键入“;”将会怎样？
> 2+3

Warning, premature end of input

系统将会提示操作出错，这时只要在新的提示符后键入“;”并按下回车键，正确 的结果就会显示出来。 如果希望重新显示刚才的运算结果，可以在下一步操作中用“%”调用此结果： > %;

5

对于分数、小数的运算，我们可以按照同样的方法键入计算式并按下回车键，就能 够立即得到结果。在下面的例子中，我们以符号“/”作为分数线： > 2/3+1/7;

> 0.472+1.38;

17

21

1.852

如果参与运算的是一个分数和一个小数，那么得到的结果将以小数形式出现： > 2/3+1.38;

2.046666667

指数运算相对来说稍微复杂一些，但对于 Maple，指数运算的操作并不比上面的分 数、小数加减法更困难： > 2^99;

633825300114114700748351602688

> 2001^11;

2059292202282269582789281320220022001

分数和小数的指数运算对 Maple 来讲同样简单，而且对不同类型的输入，Maple

输出相应类型的结果。从下面的例子中是不是可以感觉到 Maple 这个“计算器”要比真

.2489206111 10 -59

1

的计算器的功能强大的多呢？

> 0.25^99;

> 1/4^99;

401734511064747568885490523085290650630550748445698208825344

当然，上面的结果看起来不太习惯，如果认为所显示的结果太长，就可以借助 evalf

命令将运算结果转换为简单形式。还记得“%”吗，它可以用来引用上一步得到的结果，

.2489206111 10 -59

这里我们将它与 evalf 命令结合使用：

> evalf(%);

请大家注意，在 Maple 中允许将光标移动到任意位置并按下回车键来执行光标当前 位置的命令，所以，命令的执行顺序有可能与命令的排列顺序不同。所以，一定要注意 运算符“%”只能引用刚刚执行过的命令所得到的结果，而无论此命令位置与发出引用 动作的命令位置之间关系如何。

### 1.3.2 变量和多项式

变量，用直观的语言可以描述为数值可变的量，它是代表数学公式中一个可变量的

符号，是可以假定为一组特定值中之任一值的量。有了变量的概念，我们就可以用一个

变量来代替一个或一类数字组成各种复杂的表达式。而具有 (

a x

n

n

+

a

n 1

n 1

x

+

a x a

1

0

### )

形式

的表达式，我们称之为多项式。一个变量，既可以具有数值型的值，也能够以多项式作 为它的值。 在代数运算中，除了直接是用数字进行算术运算外，也可以用字母等符号作为变量 代表一个或一类数字进行运算，而在具体的数字与该变量之间建立联系的过程称为对变 量的赋值。我们已经在 1.2.2 节中看到，可以用符号“:=”对变量进行赋值，例如将数 字 5 赋值给变量 a> a:=5;

a := 5

Maple 对用户的命令输入做出反应，将运算结果输出到屏幕上，同时将变量及其赋 值保存在 Maple“内核”中，供以后的表达式和计算过程调用。在上面的计算中，Maple 已经建立了数字 5 与变量 a 的联系，则借助运算符“^”计算 2 a 次方将得到 2 5

32

> 2^a;

如果借助运算符“*”计算变量 a 2.4 的乘积，我们就会得到 5×2.4 的结果：

> 2.4*a;

12.0

值得注意的是，Maple 中所有的命令必须完整地输入，而不能按照我们日常书写计

算公式或表达式时的简写输入，否则，系统将显示出错信息。例如上面的例子中，如果

省略了乘号“*”，Maple 就不会得到正确的计算结果：

> 2.4a;

Error, missing operator or `;`

变量的值也可以是一个字符，而对变量进行字符型赋值，就需要用符号“' '”将

作为变量的值的字符引起来，例如将字符 c 赋值给变量 a

a := c

> a:='c';

当然也可以将字符 a 赋值给变量 a，这种赋值方法也可以理解为清除以前对变量 a 的赋值，在进行数字计算中如果要对某个变量重新赋值之前，可以采用这种操作。这时， 如果仍然输入有关变量 a 的表达式或命令，则 Maple 返回所输入的表达式。例如： > a^2+2.4*a;

 2 a + 2.4 a 多项式是代数中最基本的研究对象之一，多项式理论的发展与多项式方程（即代数 方程）的研究有密切联系。我们知道，每一个多项式都可以分解为不可约分多项式的乘 积。如果能够得到多项式的最简分解形式，那么代数方程的求解就会容易的多。但是多 项式的因式分解并不是件简单的事，尤其遇到次数较高的多项式，用手工进行因式分解 将十分困难。 现在，有了 Maple 的帮助，上述问题将不再是难题，因为在 Maple 环境下，只需要 使用命令 factor 就可以轻松地对多项式进行因式分解。例如： > factor(x^3+5.0); ( x + 1.709975947 ) ( x 2 + − 1.709975947 x 2.924017740 ) > factor(x^3+y^3); 2 ( y + x ) ( x − xy y 2 + ) 用 Maple 不但能够分解因式，而且也能够将乘积形式的表达式展开，这是需要用到 命令 expand。在实际运算过程中，很可能由于失误输入了错误的数字或表达式，所以需 要常常进行检查，那么，按照当前的结果反推回去与原来的表达式比较，可能是一种十 分有效的方法。例如把上面的因式分解结果还原： > expand(%); x 3 + y 3
１０
毫无疑问，结果与原来的表达式完全相同。
到现在为止，我们已经看到如何用 Maple 为变量赋值和处理多项式，那么，是否能
够用某个变量来表示一个多项式呢？换句话说，是否能够用多项式为变量赋值呢？答案
是肯定的。例如：
> p:=x^2+2*x-3:
>
请注意，上面的命令没有以分号“；”结尾，而是使用了冒号“：”，这两个符号的作
用基本相同，都可以用来作为命令行的结束标志，但他们存在一点差别，即以“；”结尾
的命令对用户输入立即做出反应，运算结果会显示出来；而以“：”结尾的命令不会将运
算结果输出到屏幕上。此时如果要查看结果，可以利用“%”，也可以直接键入变量名：
> p;
2
x
+
2 x
3
我们仍然可以利用 factor 对变量 p 所代表的多项式进行因式分解：
> factor(p);
( x + 3(
)
x − 1 )
1.3.3
解方程

方程是包括未知量的等式，而这些未知量可以是未知变量，也可以是未知函数，解

方程的目的是求这些未知量。方程有多种形式，包括代数方程、常微分方程、偏微分方

程、积分方程等。

代数方程是置有限项之和为零所得到的方程，其中每一项是变量的正整数次幂（包 括零次幂）之积。求解代数方程的 Maple 命令是 solve(Equation,var)，其中 Equation 是要

求解的方程，var 是作为未知数的变量。例如求解方程 车键后将得到这个方程的两个根：

2

• x = 4

就输入下面的命令，按下回

> solve(x^2

= 4,

x);

2, -2

如果方程中含有其他未知变量作为参数时，方程的根就由含有该变量的表达式表示。

例如求解方程

2

bx = 4

，其解为：

> solve(b*x^2

= 4, x);

{ x = 2

• 1 }, { x = −2

b
• 1 }

b

求上面已经定义的变量 p 在等于零时的根： > solve(p=0);

1, -3

常微分方程和偏微分方程统称为微分方程，它们是含有自变量、未知函数及其微商

１１
（或偏微商）的方程。在 Maple 里求解这些方程所用到的命令是 dsolve。如果要求解如
下的微分方程：
∂ ∂ x y( x )
 −
y( x ) 2
+
y( x ) sin ( x )
cos ( x )
=
0
我们首先将这个表达式赋值给变量 ode1，然后用 dsolve 命令求解方程 ode1=0：
> ode1 := diff(y(x),x)-y(x)^2+y(x)*sin(x)-cos(x);
> ans1 := dsolve(ode1=0);
( −cos ( x ) )
e
ans1 := y( x ) = sin( x ) −
( −cos ( x ) )
_C1 +
 e
d x
其中，diff 命令的作用是对函数进行微分。
1.3.4
绘图
Maple 的图形功能为用户提供了方便、快捷的绘图方法，使用户仅仅输入简单的命
令就可以得到满意的结果。如果需要对图形进行修改，也只需要按照绘图命令的格式增
加或删除相应的选项。例如对 p=x^2+2*x-3 在指定的范围内绘制图形，如图 1-3 所示：

1-3 表达式 p 所代表的曲线

利用 Maple 6 生成的图形，可以查看当 p 等于零时，自变量 x 的取值，这样可以粗 略地检验在上一节中用 solve 命令所得到的根（这种方法在需要对运算结果的大概性质 进行直观的、快速的了解时非常有用，因为某些时候我们不需要对运算结果精确地掌握， 而只需要对其趋势有比较粗略的印象）。这时，在输出图形上单击鼠标左键，图形周围出 现黑色线框，表明该图形以被选中，屏幕显示见图 1-4。与图 1-3 所显示屏幕的不同之处

１２

单击鼠标左键，可以在屏幕左上部的文字框中看到该交点的坐标值。

在于，当前屏幕上部的工具条下面出现了一些新的工具图标，它们是有关绘图和编辑图

形的工具。在这些图形工具条的左端有一个文字框，里面所显示的数字是指鼠标刚才点

击位置的坐标（图 1-4 中椭圆框勾出的位置）。用鼠标指向图线与横坐标轴相交的位置并

1-4 输出图形被选中时的屏幕

如果对上面的绘图命令稍作修改，可改变图形纵坐标的显示范围，如图 1-5 所示：

> plot(p,x=-5
..
3,y=-5 10); ..

1-5 纵坐标改变后的曲线

除了平面图形，我们也能够使用简单的 Maple 命令生成漂亮的立体图形，而且还能

够从任意视角观察所生成的图形。例如绘制曲面命令如下：

> plot3d( sin(x*y) , x = -2

..

2,

y = -1

..

1

);

１３

被选中，并且在工具条下面出现一些新的工具按钮。这时，如果按住鼠标左键不放并四

处拖动，图形将跟随鼠标的移动而旋转。这样，用户就可以从不同的视角来观察所生成

的三维图形了。

1-6
曲面 sin(x*y)的三维图形

### 表格

使用 Maple 同样可以建立表格。图 1-7 所示的就是一张用 Maple 生成的表格：

1-7
Maple 中的表格

１４

首先将光标移到需要插入表格的区域，然后选择菜单项 Insert | SpreadSheet 后，就可

以在当前位置出现一个空白的电子表格，这个表格与 Microsoft Excel 中的表格基本相似，

不同点在于这里的表格可以容纳和执行 Maple 命令。

当用户在某个单元个上单击鼠标左键选定该单元格时，位于屏幕顶部工具条下面的

文字框中将出现当前单元格中表达式的 Maple 命令。在这个文字框中，可以输入新的表

达式或者修改已经存在的表达式，当用户按下回车键后，当前单元格中的内容将按照用

户输入重新显示。

### 构造文档

文档编辑器是大家都常用的工具，例如 WordLATEX 等。Maple 同样也为用户提

供了得心应手的文档编辑环境，而且用 Maple 来创建和组织文档，可以方便地利用由

Maple 本身所得到的运算结果、公式和图形。由于 Maple 本身就可以生成数学公式，所

以在组织科技文档时具有突出的优势，而且在文档中可以直接执行 Maple 命令，大大减

少了在文档编辑器与运算软件之间来回切换的麻烦。另外，Maple 也为用户提供了“书

签”、“超链接”等使用的工具。

如图 1-8 示，Maple 中创建的文档正文可以设置排版格式，如文字位置、字体、对

齐方式，其操作与字处理器 Word 中基本相同。

1-8
在 Maple 中编辑文档

公式输入是大家经常遇到的麻烦问题，在 Word 中可以利用公式编辑器的模板，而

Maple 中只需要按照一般的数学描述形式键入命令就可以得到标准的公式。例如要得

到积分式

β

0

x 2 sin( α x ) d

x 只需输入：

１５

..

beta );

> Int( x^2*sin(alpha*x), x=0

请注意，输入命令首字母的大小写是有区别的，例如上述命令如果写作下面的形式，

+

2

则只能得到积分的运算结果，而不是积分表达式：

..

> int( x^2*sin(alpha*x), x=0

α

2

β 2 cos( α β )

beta );

cos α β )

2(

2 α β sin( α β )

α 3

这是因为在 Maple 中，许多情况下首字母大写只表示按照标准形式显示输入内容，

而首字母小写才是要求得到该输入的运算结果。

有时需要将文档按照内容的层次以章节的方式来组织，在 Maple 中，这些工作可以

轻松地完成，如图 1-9 每一小节都可以通过左端的按钮展开和关闭，这样可以使用户能

够按照任意层次显示文档，使整个文档显得条理分明、层次清晰。

1-9 按节组织文档

书签和超链接是网页工具，Maple 也提供了书签、超链接以帮助用户在文档中不同

的位置之间、不同文档之间、文档与网页之间建立快速连接，使文档内容更加生动。要

创建书签可以在选定书签位置之后，从菜单 View 中选择 Bookmarks，然后输入所要创建

（或者先选定要链接的正文，然后在菜单 Format 中选择 Convert to，再选择 Hyperlink），

输入所链接的书签名或文档名称。

如图 1-10，在“example_F”与“example_G”两个文档中，一共包含了四节正文“Section

1”、“Section 2”、“Section 3”和“Section B”，在“Section 3”和“Section B”两小节中

分别创建了书签（书签是建立超链接之前必须创建的），并与“Section 1”和“Section 2

两节中标有下划线的文字建立了超链接。当用户在超链接“Section 3”上单击鼠标左键

时，窗口自动地跳转到“This section show the…”处（如果此节是关闭状态，则点击超

链接后这一节内容将自动展开）；当用户在超链接“Section B.2”上单击鼠标左键时，窗

１６

口自动地跳转到文档“example_G”中的“Section B.2”处（如果此时文档“example_G

处于还未打开，系统将自动在当前窗口中打开此文档，而文档“example_F”会关闭）。

1-10 Maple 文当中建立书签和链接

### 1.3.7 在线帮助系统

Maple 具有一个十分有用的在线帮助系统，学会使用帮助将使我们更好地利用 Maple

所提供的各种功能。在 Maple 中，可以通过菜单 Help 进入帮助系统，例如选择 Help

单中的 Topic Search 命令就可以得到如图 1-11 的对话框，在最上方的文字框内输入某个

主题，就能够查询有关该主题的帮助信息。

1-11 寻找特定主题的帮助信息

如果在命令提示符“>”后键入“?”，按下回车键，以进入如图 1-12 所示的帮助系

统画面。

１７

1-12 由命令“?”进入在线帮助系统

在前面几节中，我们已经学习了一些常用的 Maple 命令，如果大家对其中的某些具

体命令的使用方法还没有完全弄明白，或者希望了解更多的信息，那么可以借助

?+commandname”也可以激活包含关于该命令详细信息的帮助窗口，例如，键入“?+

和“?^”将得到如图 1-13 的画面。

1-13 由命令“? +commandname 进入在线帮助系统

形式输出。

１８

• 1.4 Maple 6 的新特性

Maple 6 作为 Maple 家族最年轻的成员，不仅继承和发扬了各版本“前辈”的优点，

而且在图形用户界面（GUI）、图形处理、外挂工具包的更新、与 Excel 2000 的衔接等方

面得到了升级和更新，使得 Maple 6 更加完善。

Maple 6 的用户界面中，可以将不同用户的环境设置保存在不同的目录下，从而为

每一位用户提供了个性化的空间。得到强化的查找和替换的功能，使用户能够在工作表

中逐一地查找某个字符或字符串，也能够一次性地完成所有替换工作。电子表格方面功

能的提高使得用户在命令行中就能够创建或操作表格中的内容。超链接编辑器也得到改

善，使得用户能够同时修改所有超链接。如果用户希望工作表中只显示单一类型的内容，

比如只显示输入命令或者计算结果，Maple 6 的隐藏功能可以帮助用户隐藏其他不需要

的内容。在使用模板进行输入时，模板可以调节大小。另外，Maple 6 允许工作表以 RTF

图形方面的新特性在于用户可以为在 Maple 6 下创建的平面图形增加可编辑的标

签，并且能够为图形对象加上多个标题。最为突出的是，由 Maple 6 生成的三维图形能

够通过鼠标的托拽实时地旋转方向。

外挂工具包方面，Maple 6 集成了 NAG 线性代数计算模块，使得 Maple 6 在处理线

性代数问题时达到更高的精度。

Maple 6 的工作表能够与 Microsoft Excel 2000 很好地衔接，用户不但可以在两个应

用程序之间顺利地实现拷贝和粘贴操作，而且能够在 Excel 中调用 Maple 命令。

1.5 本章小结

本章主要回顾了 Maple 的产生和发展的过程，帮助读者对 Maple 建立起初步的印象；

同时简单地阐述了 Maple 的组织结构；以若干简单的、并且具有代表性的实例介绍了

Maple 在算术、多项式、方程求解、绘图、电子表格等方面的功能，以期给读者留下较

为概括的概念，了解 Maple 到底是用来做什么的、是怎么做的；本章同时介绍了如何使

用在线帮助系统，以使读者在阅读本书时能够通过查询某些具体命令的信息加深对

Maple 的认识；本章的最后扼要介绍了当前流行的版本 Maple 6 的一些特性。

１０９

# 初等代数

初等代数是数学中的一个重要的、基础的分支，是古老的算术的推广和发展，它

研究数字和文字的代数运算（加法、减法、乘法、除法、乘方、开方等）的理论和方

法，更确切地说，它研究数或复数和以它们为系数的多项式的代数问题的理论和方法。

初等代数运算是 Maple 最基本的计算功能，它包括了算术、多项式操作、因式

分解、方程与方程组的求解、以及解不等式等。初等代数问题的特点是高度计算性，

Maple 在计算方面的强大功能可以帮助我们轻松地处理初等代数问题。

本章具体包括以下内容：

 多项式和有理式 多项式操作 解方程 解方程组 数值求解 不等式

１０９

7.1 多项式与有理式

多项式是代数学中最基本的研究对象之一，它也是 Maple 中经常处理的对象。多项

式就是由若干独立的项元素所构成的表达式，其中每一项都是某个变量的幂。根据多项

式中所包含的基本变量的数目，多项式可以分为一元多项式（表达式中只存在一个基本

变量）和多元多项式（表达式中含有一个以上基本变量）。

有理式的概念建立在多项式基础之上，如果 f g 都是多项式，那么 f/g 形式的表达

式就称为有理式。

### 7.1.1 一元多项式

一元多项式是最简单的多项式，一般地，我们称具有如下形式的表达式为一元多项

式的“标准型”：

a x

n

n

+

a

n 1

x

n 1

+

+

a x

2

2

+

+

a x a

1

0

其中，n 是多项式次数，

a

n

a

n 1

a

0

是多项式系数，

a x

k

k

称为多项式的 k 次项，

如果 不等于 0，则称上述多项式为 n 次多项式，此时

a

n

a x

n

n

就是该多项式的首项。可以

看到，一元多项式的“标准型”各项是按照变量 x 的指数递减顺序排列的，而如果不按

照这样的顺序排列的多项式则称为“合并型”多项式。

一个多项式的要素包括多项式次数、首项系数等，在 Maple 中，我们可以借助一些

命令和函数来查看多项式的这些要素。请看示例：

> p1:=-3*x+7*x^2-3*x^3+7*x^4; # 合并型多项式

p1 := 3 x + 7 x

2

3

x 3

+ 7 x 4

这一条命令所定义的多项式 p1 没有按照变量 x 的指数递减顺序排列各项，所以它是

“合并型”的。我们可以看到它的最高次项为

7 x

• 4 ，现在使用 degree 命令和 lcoeff 命令

来查看 p1 的次数和首项系数：

> degree=degree(p1); # 查看多项式的次数

degree = 4

> leading_coefficient:=lcoeff(p1); # 查看多项式的首项系数

此外，我们还能够使用 type 命令去判断某一个函数名多代表的内容是否为多项式，

其命令输入如下，type 命令的返回值是逻辑值，这里由于 p1 是多项式，所以 type 命令

的返回值为 true，否则将显示 false

１１０

> type(p1,polynom); # 判断表达式是否为多项式
true
多项式能够参与四则运算，利用 Maple 进行多项式的四则运算时十分简洁和准确的。
对于多项式的加减法，Maple 将自动合并参与运算的各多项式中的同类项（次数相同的
项）。例如定义“标准型”多项式 p2 并与刚刚用到的多项式 p1 进行运算：
> p2:=5*x^5+3*x^3+x^2-2*x+1; # 标准型多项式
5
p2 := 5 x
+
3 x 3
+
x 2
2 x
+
1
> 2*p1-3*p2+3; # 多项式加减法
2
11 x
15 x 3
+
14 x 4
− 15 x 5
对于多项式的乘法，Maple 并不直接输出其化简结果，如果需要得到多项式形式的
结果，我们必须使用 expand 命令将运算结果展开，或者使用 collect 命令合并同类项：
> p1*p2; # 多项式乘法
2
5
( −3 x + 7 x
3 x 3
+
7 x 4
) ( 5 x
+
3 x 3
+
x 2
2 x
+
1
)
> expand(%); # 展开多项式相乘的结果
6
−17 x
+
11 x 4
20 x 3
+
13 x 2
3 x
+
56 x 7
+
4 x 5
15 x 8
+ 35 x 9
> collect(p1*p2,x); # 合并同类项
9
35 x
15
x 8
+
56
x 7
17
x 6
+
4
x 5
+
11
x 4
20
x 3
+
13
x 2
− 3 x
看起来有点麻烦，为什么不直接输出展开后的结果呢？这是因为用户所输入的表达
式写成多项式形式时可能会很长，而同时又不希望花费太多的时间去注意运算结果的细
节，这时系统没有必要自动将结果展开。例如 (
) 10
3 x + 5
的展开式长达 11 项：
> (3*x+5)^10;
( 3 x + 5 ) 10
> expand(%);
9
8
7
6
59049
x 10 +
984150 x
+
7381125 x
+
32805000 x
+
95681250 x
+ 191362500 x 5
4
3
2
+
265781250 x
+
253125000 x
+
158203125 x
+ 58593750 x + 9765625
在上面多项式相乘的结果中，各项的排列并没有按照固定的升次或降次顺序，这个
现象与系统节约运算时间、存储位置等有关。如果用户觉得这种显示方式不利于阅读或
观察，可以用 sort 命令来排序：
> sort(%);
9
35 x
15
x 8
+
56
x 7
17
x 6
+
4
x 5
+
11
x 4
20
x 3
+
13
x 2
− 3 x

实际上，sort 命令会改变系统内部数据的存储结构。这是因为在 Maple 内部，相同

的表达式只存储一次，当输入新的表达式时，系统首先对它进行必要的化简，然后检查

该式是否已经保存过，如果以前出现过这个表达式，则系统不重复记忆；如果没有出现

１１１

顺序

过，则记忆化简后的表达式。因此，改变某个表达式的顺序，将会对所有包含此式的结

果产生影响。下面的示例中首先以不规则形式定义表达式 p

3

+ x 2

> p:=1+x+x^3+x^2; # 任意排列

p := 1 + x + x

此时，按其他顺序输入与 p 相同的表达式不会被系统存储，Maple 将继续使用以前

记忆的表达式，所以其顺序不变：

> x^3+x^2+x+1; # 重新输入的多项式不会改变该表达式在 Maple 内核中的存储

1 + x + x

3

+ x 2

这样的情况在多项式 p 参与乘法运算时也会发生：

)

1 + x + x

3

+

x

2

)

> q:=(x-1)*(x^3+x^2+x+1);

q := ( x 1(

这是因为我们没有从根本上变更多项式在 Maple“记忆”中的排列顺序。那么，怎

样才能改变这个顺序呢？请大家看看下面的示例，其中 sort 命令的作用是按照“标准型”

调整多项式各项的排列顺序：

> sort(p); # 对多项式 p 进行排序

3

x +

x 2

+

x

+

1

> q; # 重新显示多项式 q

( x 1(

)

3

x +

x 2

+

x

+

1

)

原来用 sort 命令排序后，Maple“记忆”中的多项式 p 被更新了，这一点从多项式 q

的结果中就能够看到。

刚才已经学习了使用命令 lcoeff 查看多项式首项的系数，还记得吗？那么，如果希

望知道多项式中其他项的系数该怎么办？现在我们就来介绍查看多项式系数的另外两个

命令，它们是 tcoeff coeff。其中 tcoeff 命令用于得到多项式最低次项的系数，而 coeff

命令可以用来查看某一具体次数项的系数。这里仍然以多项式 p1 p2 为例，请看下面

的例子：

> tcoeff(p2,x), tcoeff(p2-1,x); # 查看多项式最低次项的系数

1, -2

> coeff(p1,x^4), coeff(p1,x,4); # 查看具体次数项系数的两种命令形式

7, 7

对于项数较少的多项式，我们可以使用 coeffs 命令显示所有次数项的系数，例如要

得到多项式 p2 中各项系数的命令输入如下：

> coeffs(p2,x,'powers'); # 显示多项式 p2 各项系数

1, -2,,,

3

1

5

１１２

> powers; # 与以上各系数所对应的多项式元素

1,,

x x ,

3

x

2

, x 5

大家已经知道，Maple 在进行多项式加减法时会自动合并同类项，而在进行乘法时

将保留乘积形式，而在使用命令 lcoefftcoeffcoeffs 以及 degree 时，所操作的多项式

必须已经被展开，而且同类项已经被合并，所以，使用上述命令时，如果遇到包含多项

式乘积的表达式则需要先用命令 collect 进行转换，否则得不到正确的结果。例如：

> lcoeff(x^2-x*(x-1),x); # 含多项式乘积时求首项系数出错

0

> lcoeff(collect(x^2-x*(x-1),x),x); # 求首项系数正确的命令输入

1

> coeffs((x^2-1)*(x^2+1),x); # 含多项式乘积时求各项系数出错

Error, invalid arguments to coeffs

> coeffs(collect((x^2-1)*(x^2+1),x),x); # 求各项系数正确的命令输

-1, 1

> degree(x^2-x*(x-1),x); # 含多项式乘积时求多项式次数出错

2

> degree(collect(x^2-x*(x-1),x)); # 求多项式次数正确的命令输入

1

多项式的除法是多项式操作中最为繁琐的工作，但有了 Maple 的帮助，这样的工作

就显得很容易了。多项式除法的操作主要涉及两个命令，即 quo rem。前者用以求两

个多项式相除所得的商式，后者求余式。例如计算多项式多项式 p2 除以 p1，并将得到

的余式存储在变量 r 中，命令输入如下：

> q:=quo(p2,p1,x,'r'); # p2 除以 p1 的商式

> r;

# p2 除以 p1 的余式

• 5 15

q :=

7

49

x

+

1

53

49

x 3

+

x

2

53

49

x

rem 的书写格式与 quo 相同，但两个命令中的第四个参数意义不同，在 rem 中的这

个参数存放的是多项式 p2 除以 p1 后得到的商式。以下命令的作用是计算 p2 除以 p1

并将得到的商式存储在变量 e 中：

> rem(p2,p1,x,'e'); # p2 除以 p1 的余式

1

53

49

x 3

+

x

2

53

49

x

１１３

> e;
输入如下：

# p2 除以 p1 的商式

5

15

7

49

x

+

求多项式的最大公因式也是多项式操作的重要组成部分，Maple 提供了命令 gcd

以在有理数范围内求多项式的最大公因式。例如求多项式 p1 p2 的最大公因式，命令

> gcd(p1,p2); # p1 p2 的最大公因式

x

2

+ 1

有时我们在遇到较为复杂的多项式时，需要将其转换成最简因式乘积的形式，这项

原本用手工推导起来极为费力的工作，用 Maple 就只需输入简单的 factor 命令：

2

3 x 3 + 7 x 4

3 x

+

3

2

x

) ( 5 x

56 x 7

+

1( x

)

• 5 )

+

2

 + 3 x 3 + x 2 − 2 x + 1 4 x 5 − 15 x 8 + 35 x 9 2 + 1 )

> polynomial:=p1*p2;

polynomial := ( 3 x + 7 x

20 x 3

+

13 x 2

( 7 x 3(

)

5 x

> expand(polynomial);

17 x

6

+

11 x 4

x

> factor(%);

### 7.1.2 多元多项式

多元多项式是指表达式中含有两个或两个以上自变量的多项式，其中每一项的次数

等于该项包含所有变量的指数之和。例如定义多项式 polynomial

> polynomial:=6*x*y^5+12*y^4+14*y^3*x^3-15*x^2*y^3+9*x^3*y^2

-30*x*y^2-35*x^4*y+18*x^2*y+21*x^5;

polynomial :=

5

6 x y +

12 y 4

+

14 y 3 x 3

15

x 2 y 3

+

9

x 3 y 2

30

x y 2

35 x 4 y

+

18 x 2 y

+

21 x 5

可以看到，Maple 并没有自动地对所输入的多项式各项进行排序，仅仅按照用户的

原始输入显示，这时，同样可以用 sort 命令按照缺省的排列顺序排序，其排序依据是各

项的次数，并遵循如下规则：

1 < y < x < y < xy < x < y < xy < x y < x

2

2

3

2

2

3

对上述多项式进行排序的结果为：

> sort(polynomial); # 多元多项式排序

14 x

3

y 3

+

6 x y 5

+

21 x 5

35 x 4 y

+

9 x 3 y 2

15 x 2 y 3

+

12 y 4

+

18 x 2 y

30 x y 2

Maple 允许用户按照某个单独变量的次数进行排序，此时的排列顺序所依据的标准

如下：

１１４

1

<

y

<

y

2

< <

<

x xy

<

x

2

<

例如对多项式 polynomial 进行排序，将变量 x 视为基本变量，而将变量 y 当作系数

+ 12 y 4

对待，其结果为：

> sort(polynomial, [x,y], 'plex'); # 按照单独变量排序

21 x

5

35 x 4 y

+

14 x 3 y 3

+

9 x 3 y 2

15 x 2 y 3

+

18 x 2 y

+

6 x y 5

30 x y 2

同样可以对多元多项式进行同类项合并，命令输入为：

) x 2

+

> collect(polynomial,x); # 合并同类项

21 x

5

35

x 4 y

+

( 14 y

3

+

9 y 2

) x 3

+

( 18 y 15 y

3

( 30 y

2

+

6 y 5

) x

+

12 y 4

对单变量多项式适用的许多命令，例如求系数命令 coeff coeffs、分解因式命令

factor 等都适用于多变量多项式。现在以多项式 polynomial 为例，求其中含有 x 3 项的系

数，下面的两种命令书写形式作用相同：

> coeff(polynomial, x^3), coeff(polynomial, x, 3);

14 y

3

+

9 y 2

, 14 y

3

+ 9 y 2

coeff 嵌套使用也可以求某个具体项的系数，如 x 3 y 2 的系数：

> coeff(coeff(polynomial, x^3), y^2); # x 3 y 2 的系数

9

获取关于变量 x 的各阶项系数的 coeffs 命令与因式分解的 factor 命令在使用方法上

基本相同，请看下面的两个例子：

> coeffs(polynomial, x, 'powers'); powers; # 关于变量 x 的各项系

数与其对应项

4

12 y ,

30 y

2

+ 6 y 5

,

14 y

3

+ 9 y 2

,

18 y 15 y 3

21

,,

35 y

1,,

x x ,

3

x 2 x 5

,

, x 4

> factor(polynomial); # 因式分解

( 3

2

x

5 x y 2 y 3

+

) ( 7 x

3

+

6 y 3 x y 2

+

)

多变量多项式的操作对手工运算来说是非常困难的，但从上面的介绍可以看到，有

Maple 的帮助，这些工作都能够轻松地完成，用户仅仅需要了解几个简单命令的使用

方法，便可以节约大量的时间和精力。

### 有理式

以一元多项式为例，设多项式 f g 的基本变量为 x，并且 g 0 ，那么 f/g 就是关

于变量 x 的有理式。例如：

> f:=x^2+3*x+2; g:=x^2+5*x+6;

１１５

 f := x 2 + 3 2 x + g := x 2 + 5 6 x + h := x 2 + 3 2 x + x 2 + 5 6 x +

> h:=f/g;

表达式 h 就是一个标准的有理式。由于有理式由两个多项式构成，那么如果需要单

独使用其中位于分子、分母的多项式该怎么办呢？Maple 为我们提供的 numer denom

命令就能够解决问题，其中 unmer 命令用以求得分子位置的多项式，而 denom 命令的结

果为分母位置的多项式：

> numer(h); # 求有理式的分子

 x 2 + 3 x + 2 x 2 + 5 x + 6 ff := ( x − 1( ) x 2 + 3 x + 2 ) gg := ( x − 1 ) 2 ( x 2 + 5 x + 6 ) x 2 + 3 x + 2 ( x − 1( ) x 2 + 5 x + 6 )

> denom(h); # 求有理式的分母

在创建有理函数时，分子与分母中如果出现了显式公因式，Maple 将约去此式；但

如果公因式隐含与分子与分母之中，系统不会自动地采取化简动作。例如下面由多项式

ff 和多项式 gg 构成的有理式 ff/gg 中，显式出现的公因式(x-1)被约去，而隐含的公因式

(x+2)仍然存在：

> ff:=(x-1)*f;

> gg:=(x-1)^2*g;

> ff/gg;

如果希望将有理函数化为最简形式，即约去分子、分母之间所有公因式，包括隐含

公因式，则需要用命令 normal 来完成：

> normal(h); # 约去有理式 h 分子与分母之间的公因式

 x + 1 x + 3 > normal(ff/gg); # 约去有理式 ff/gg 分子与分母之间的公因式 x + 1 ( x + 3( ) x − 1 )

Maple 之所以不会自动地对有理式进行约分，是由于如下原因：

(1) 约分后的结果描述起来很可能很繁。例如(x 10000 -1)/(x-1)要比其约分后的表达式

简便的多，因为它的约分结果长达 10000 项；

１１６

>

(2) Maple 的结构充分地考虑到了运算的效率，而对有理函数进行约分将要花费大

量的运算时间，如果对所有输入都进行化简，将降低系统效率；

(3) 在以后的运算中，用户很可能还需要用到当前有理函数中的表达式，保持当前

形式有利于阅读和检查。

在结束本节之前，再举一个有理式的示例以总结所讲述的内容。我们首先定义了有

理函数 ratexpr；然后分别将其分子、分母化为最简因式乘积形式；最后约去分子分母的

公因式，将 ratexpr 化为最简形式：

f:=161*y^3+333*x*y^2+184*y^2+162*x^2*y+144*x*y+77*y+99*x+88;

f := 161 y

 3 + 333 x y 2 + 184 y 2 + 162 x 2 y + 144 x y + 77 y + 99 x + 88 2 + 28 x 2 y + 63 x y + 147 y + 36 x 3 + 32 x 2 + 117 x + 104 3 333 x y 2 + 184 y 2 + 162 x 2 y + 144 x y + 77 y + 99 x + 88 49 y 2 + 28 x 2 y + 63 x y + 147 y + 36 x 3 + 32 x 2 + 117 x + 104 ( 18 x y + 23 y 2 + 11 ) ( 7 y + 9 x + 8 ) ( 7 y + 4 x 2 + 13 ) ( 7 y + 9 x + 8 ) 18 x y + 23 y 2