WxMaxima

wxMaxima 用户手册

WxMaxima is a graphical user interface (GUI) for the Maxima computer algebra system (CAS). WxMaxima allows one to use all of Maxima’s functions. In addition, it provides convenient wizards for accessing the most commonly used features. This manual describes some of the features that make wxMaxima one of the most popular GUIs for Maxima.

wxMaxima 的 logo

在介绍本手册的内容之前,先给出一些关于文档导航的说明。正下方是一个简短的目录。单击任何列出的条目,即可跳转到手册对应节的顶部。单击目录可定位到详细的目录。此扩展目录可用于更直接地跳转到手册的各小节、小小节,以方便查看内容。

WxMaxima basics

wxMaxima 向 Maxima 添加的命令

当 wxMaxima 不按预期运行时的解决办法

常见提问(Frequently asked questions)

wxMaxima 支持的命令行参数


1 wxMaxima 简介

1.1 Maxima 和 wxMaxima

在开源领域,大型项目通常被分割成小型项目,后者对于小规模开发组来说更容易处理。例如,一个 CD 刻录机程序会包括一个实际刻录 CD 的命令行程序和一个图形用户界面,该界面使得用户不必了解所有的命令行参数就能刻录 CD,从而实际上避开了使用命令行。这种方法的一个优点是,投入到命令行程序中的开发工作可以被许多程序共享:同一个刻录 CD 的命令行程序可以用作文件管理器应用程序的“发送到 CD”插件、音乐播放器的“刻录到 CD”功能以及 DVD 备份工具的刻录 CD 功能。另一个优点是将一个大型任务分解成更小的部分时,开发人员就可以为同一个程序提供多个用户界面。

一个像 Maxima 这样的计算机代数系统(CAS,computer algebra system)也适合前述框架。Maxima 可以用作任意精度计算器程序的底层软件,也可以在更大计算系统中作为公式转换程序来帮助计算(例如 Sage)。Maxima 也可以直接作为独立的计算系统使用,它可以通过命令行来访问。然而,在通常情况下,像 wxMaxima 这样的用户界面是使用 Maxima 的一种更有效的方法,特别是对于新手而言更是如此。

1.1.1 Maxima

Maxima 是一个功能齐全的计算机代数系统(CAS)。CAS 是一个程序,它可以通过对公式变形并找到问题的解来求解数学问题,而不是仅仅输出结果的数值。换言之,Maxima 可以作为一个计算器,给出变量的数值表示,也可以提供解析解。此外,它还提供了一系列数值分析方法,用于求解没有解析解的方程或方程组。

Maxima 截图,命令行

Extensive documentation for Maxima is available in the internet. Part of this documentation is also available in wxMaxima’s help menu. Pressing the Help key (on most systems the F1 key) causes wxMaxima’s context-sensitive help feature to automatically jump to Maxima’s manual page for the command at the cursor.

1.1.2 WxMaxima

WxMaxima is a graphical user interface that provides the full functionality and flexibility of Maxima. WxMaxima offers users a graphical display and many features that make working with Maxima easier. For example wxMaxima allows one to export any cell’s contents (or, if that is needed, any part of a formula, as well) as text, as LaTeX or as MathML specification at a simple right-click. Indeed, an entire workbook can be exported, either as a HTML file or as a LaTeX file. Documentation for wxMaxima, including workbooks to illustrate aspects of its use, is online at the wxMaxima help site, as well as via the help menu.

wxMaxima 界面

在 wxMaxima 中输入的计算式是由 Maxima 命令行工具在后台执行的。

1.2 工作簿(Workbook)基础

大部分 wxMaxima 功能是不言自明的,但有些细节需要注意。这个网站包含多个工作簿,这些工作簿涉及 wxMaxima 的各个方面。学习其中的一些(特别是“10 minute (wx)Maxima tutorial”,即“十分钟 (wx)Maxima 教程”)将增加用户对 Maxima 的内容和 wxMaxima 与 Maxima 交互过程的熟悉度。本手册集中描述 wxMaxima 的某些功能,这些功能可能并非不言而喻的,也可能不会被在线文档涵盖。

1.2.1 工作簿的使用

One of the very few things that are not standard in wxMaxima is that it organizes the data for Maxima into cells that are evaluated (which means: sent to Maxima) only when the user requests this. When a cell is evaluated, all commands in that cell, and only that cell, are evaluated as a batch. (The preceding statement is not quite accurate: One can select a set of adjacent cells and evaluate them together. Also, one can instruct Maxima to evaluate all cells in a workbook in one pass.) WxMaxima’s approach to submitting commands for execution might feel unfamiliar at the first sight. It does, however, drastically ease work with big documents (where the user does not want every change to automatically trigger a full re-evaluation of the whole document). Also, this approach is very handy for debugging.

如果输入文本到 wxMaxima 中,则会自动创建一个新的工作簿单元格。可以在工具栏中选择此单元格的类型。如果创建了一个(数学)代码单元格,则可以将该单元格发送到 Maxima,这将使得计算结果显示在代码下方。下面显示了一对这样的命令:

输入、输出单元格

在计算(数学)输入单元格的内容时,Maxima 会为该输入指定一个标签(默认情况下以红色显示,并且可以由“%i”加数字识别),以便在 wxMaxima 会话的后续内容中引用该标签。Maxima 生成的输出也会获得以“%o”开头的标签,而当用户为输出指定了名称(如变量名)时,该标签是隐藏的。在后一种情况下,默认显示用户定义的名称。不过,此时仍可以访问 Maxima 自动生成的“%o”型标签。

除了(数学)输入单元格外,wxMaxima 中还可以使用文本单元格、图片单元格、标题单元格、节单元格和小节单元格等。每个单元格都有独立的撤消缓冲区,因此通过更改多个单元格的内容,然后逐步撤销不需要的更改来进行调试,是非常容易的。此外,工作簿本身有一个全局撤消缓冲区,可以撤消单元格编辑、添加和删除操作。

下图显示了不同的单元格类型(标题单元格、节单元格、小节单元格、文本单元格、输入/输出单元格和图片单元格):

wxMaxima 的不同类型单元格

1.2.2 单元格

The worksheet is organized in cells. WxMaxima knows the following cell types:

当输入文本时,wxMaxima 的默认行为是自动创建一个数学单元格。可以使用“单元格”菜单、菜单中显示的热键或工具栏中的下拉列表创建其他类型的单元格。一旦创建了非数学单元格,输入到文档的任何内容都将被解释为文本。

A (C-style) comment text can be part of a math cell as follows: /* This comment will be ignored by Maxima */

/*” marks the start of the comment, “*/” the end.

1.2.3 水平光标和竖直光标

If the user tries to select a complete sentence, a word processor will try to extend the selection to automatically begin and end with a word boundary. Likewise, if more than one cell is selected, wxMaxima will extend the selection to whole cells.

What isn’t standard is that wxMaxima provides drag-and-drop flexibility by defining two types of cursors. WxMaxima will switch between them automatically when needed:

When you start wxMaxima, you will only see the blinking horizontal cursor. If you start typing, a math cell will be automatically created and the cursor will change to a regular vertical one (you will see a right arrow as “prompt”, after the Math cell is evaluated (CTRL+ENTER), you will see the labels, e.g. (%i1), (%o1)).

(blinking) horizontal cursor after wxMaxima start

You might want to create a different cell type (using the “Cell” menu), maybe a title cell or text cell, which describes, what will be done, when you start creating your worksheet.

If you navigate between the different cells, you will also see the (blinking) horizontal cursor, where you can insert a cell into your worksheet (either a math cell, by just start typing your formula - or a different cell type using the menu).

(blinking) horizontal cursor between cells

1.2.4 向 Maxima 发送单元格

The command in a code cell is executed once by pressing CTRL+ENTER, SHIFT+ENTER or the ENTER key on the keypad. The wxMaxima default is to enter commands when either CTRL+ENTER or SHIFT+ENTER is entered, but wxMaxima can be configured to execute commands in response to ENTER.

1.2.5 命令自动补全

WxMaxima contains an autocompletion feature that is triggered via the menu (Cell/Complete Word) or alternatively by pressing the key combination CTRL+SPACE. The autocompletion is context-sensitive. For example, if activated within a unit specification for ezUnits it will offer a list of applicable units.

ezUnits

Besides completing a file name, a unit name, or the current command or variable name, the autocompletion is able to show a template for most of the commands indicating the type (and meaning) of the parameters this program expects. To activate this feature press SHIFT+CTRL+SPACE or select the respective menu item (Cell/Show Template).

1.2.5.1 希腊字母

计算机一般以 8 位值(8-bit)存储字符,所以最多可以储存 256 个不同字符。大部分语言中的所有字母、数字和控制符号(传输结束、字符串结束、为菜单绘制矩形的线条和边缘等)都符合该限制。

For most countries, the codepage of 256 characters that has been chosen does not include things like Greek letters, though, that are frequently used in mathematics. To overcome this type of limitation Unicode has been invented: An encoding that makes English text work like normal, but to use much more than 256 characters.

Maxima allows Unicode if it was compiled using a Lisp compiler that either supports Unicode or that doesn’t care about the font encoding. As at least one of this pair of conditions is likely to be true. WxMaxima provides a method of entering Greek characters using the keyboard:

按键 希腊字母 按键 希腊字母 按键 希腊字母
a alpha i iota r rho
b beta k kappa s sigma
g gamma l lambda t tau
d delta m mu u upsilon
e epsilon n nu f phi
z zeta x xi c chi
h eta om omicron y psi
q theta p pi o omega
A Alpha I Iota R Rho
B Beta K Kappa S Sigma
G Gamma L Lambda T Tau
D Delta M Mu U Upsilon
E Epsilon N Nu P Phi
Z Zeta X Xi C Chi
H Eta Om Omicron Y Psi
T Theta P Pi O Omega

用同样的方法还可以输入一些其他的数学符号:

keys to enter mathematical symbol
hbar Planck’s constant: a h with a horizontal bar above it
Hbar a H with a horizontal bar above it
2 squared
3 to the power of three
/2 1/2
partial partial sign (the d of dx/dt)
integral integral sign
sq square root
ii imaginary
ee element
in in
impl implies implies
inf infinity
empty empty
TB big triangle right
tb small triangle right
and and
or or
xor xor
nand nand
nor nor
equiv equivalent to
not not
union union
inter intersection
subseteq subset or equal
subset subset
notsubseteq not subset or equal
notsubset not subset
approx approximately
propto proportional to
neq != /= or # not equal to
+/- or pm a plus/minus sign
<= or leq equal or less than
>= or geq equal or greater than
<< or ll much less than
>> or gg much greater than
qed end of proof
nabla a nabla operator
sum sum sign
prod product sign
exists there exists sign
nexists there is no sign
parallel a parallel sign
perp a perpendicular sign
leadsto a leads to sign
-> a right arrow
–> a long right arrow

If a special symbol isn’t in the list, it is possible to input arbitrary Unicode characters by pressing ESC [number of the character (hexadecimal)] ESC.

因此 ESC 61 ESC 输入了字符 a.

Please note that most of these symbols (notable exceptions are the logic symbols) do not have a special meaning in Maxima and therefore will be interpreted as ordinary characters. If Maxima is compiled using a Lisp that doesn’t support Unicode characters they might cause an error message.

It may be the case that e.g. greek characters or mathematical symbols are not included in the selected font, then they can not be displayed. To solve that problem, select other fonts (using: Edit -> Configure -> Style).

1.2.6 侧边栏

Shortcuts to the most important Maxima commands, things like a table of contents, windows with debug messages or a history of the last issued commands can be accessed using the side panes. They can be enabled using the “View” menu. They all can be moved to other locations inside or outside the wxMaxima window. Other useful panes is the one that allows to input Greek letters using the mouse.

各种类型的侧边栏

In the “table of contents” side pane, one can increase or decrease a heading by just clicking on the heading with the right mouse button and select the next higher or lower heading type.

Increase or decrease headings in the TOC side pane

1.2.7 MathML 输出

Several word processors and similar programs either recognize MathML input and automatically insert it as an editable 2D equation - or (like LibreOffice 5.1) have an equation editor that offers an “import MathML from clipboard” feature. Others support RTF maths. WxMaxima, therefore, offers several entries in the right-click menu.

1.2.8 标记语言(Markdown)支持

WxMaxima offers a set of standard Markdown conventions that don’t collide with mathematical notation. One of these elements is bullet lists.

普通文本
 *一个条目,缩进级别为 1
 *另一个条目,缩进级别为 1
   *一个条目,缩进级别为 2
   *另一个条目,缩进级别为 2
*第三个条目,缩进级别为 1
普通文本

WxMaxima will recognize text starting with > chars as block quotes:

普通文本
>引用文字
>引用文字
>引用文字
普通文本

WxMaxima’s TeX and HTML output will also recognize => and replace it by the corresponding Unicode sign:

cogito => sum.

Other symbols the HTML and TeX export will recognize are <= and >= for comparisons, a double-pointed double arrow (<=>), single-headed arrows (<->, -> and <-) and +/- as the respective sign. For TeX output also << and >> are recognized.

1.2.9 快捷键

大多数快捷键可以在相应菜单的文本中找到。由于它们实际上是从菜单文本中获取的,所以可以通过 wxMaxima 的翻译文本进行定制,以满足本地用户的需求,因此我们不在这里记录它们。但是,一些快捷键或其别名并没有记录在菜单中:

1.2.10 导出 TeX 时的原始 TeX 代码

如果文本单元格以 TeX: 开头,则导出 TeX 时,文件将包含 TeX: 标记后面的文本。使用此功能可以在 wxMaxima 工作簿中输入 TeX 代码。

1.3 文件格式

在 wxMaxima 中输入的内容可以存为以下三种文件格式之一,以供以后使用:

1.3.1 .mac

.mac files are ordinary text files that contain Maxima commands. They can be read using Maxima’s batch() or load() command or wxMaxima’s File/Batch File menu entry.

One example is shown below. Quadratic.mac defines a function and afterward generates a plot with wxdraw2d(). Afterward the contents of the file Quadratic.mac are printed and newly defined function f() is evaluated.

Loading a .mac file with batch()

Attention: Although the file Quadratic.mac has a usual Maxima extension (.mac), it can only be read by wxMaxima, since the command wxdraw2d() is a wxMaxima-extension to Maxima.

用户可以使用 .mac 文件编写自己的程序包。但是由于它们没有包含足够的结构信息,因此不能作为一个 wxMaxima 工作簿来读取。

1.3.2 .wxm

.wxm files contain the worksheet except for Maxima’s output. On Maxima versions >5.38 they can be read using Maxima’s load() function just as .mac files can be. With this plain-text format, it sometimes is unavoidable that worksheets that use new features are not downwards-compatible with older versions of wxMaxima.

1.3.3 .wxmx

这种基于 XML 的文件格式保存了完整的工作簿内容,包括缩放因子和观察列表等内容。它是首选的文件格式。

1.4 设置选项

对于一些常见的可设置变量,wxMaxima提供了两种设置方法:

wxMaxima 设置对话框

1.4.1 默认动图帧率

用于新生成动图的帧率保存在变量 wxanimate_framerate 中,可以使用设置对话框更改此变量在新工作簿中的初始值。

1.4.2 新 Maxima 会话的默认绘图尺寸

After the next start, plots embedded into the worksheet will be created with this size if the value of wxplot_size isn’t changed by maxima.

为了仅对单个绘图命令设置绘制图形的大小,可以使用以下代码:

wxdraw2d(
   explicit(
       x^2,
       x,-5,5
   )
), wxplot_size=[480,480]$

1.4.3 在文本中匹配括号

该选项使以下两个功能生效:

1.4.4 不自动保存工作簿

If this option is set, the file where the worksheet is will be overwritten only the request of the user. In case of a crash/power loss/… a recent backup copy is still made available in the temp directory, though.

如果未设置此选项,则 wxMaxima 的行为更像现代手机软件:

1.4.5 设置信息保存的位置

当使用 Unix/Linux 系统时,设置信息将保存在主目录中的 .wxMaxima 文件里(如果 wxWidgets 版本号小于 3.1.1)或 .config/wxMaxima.conf 文件里(如果 wxWidgets 的版本号大于等于 3.1.1(XDG标准))。用户可以通过命令 wxbuild_info(); 或使用菜单选项 “帮助->关于”(Help->About)来检索 wxWidgets 版本号。wxWidgets 是跨平台的 GUI 库,也是 wxMaxima 的底层库(因此 wxMaxima 的名称中带“wx”)。 (由于文件名以点“.”开头,文件 .wxMaxima.config 将被隐藏)。

当使用 Windows 系统时,配置信息将存储在注册表中。在注册表中的以下位置可以找到 wxMaxima 的相关条目:HKEY_CURRENT_USER\Software\wxMaxima


2 对 Maxima 功能的扩充

WxMaxima is primarily a graphical user interface for Maxima. As such, its main purpose is to pass along commands to Maxima and to report the results of executing those commands. In some cases, however, wxMaxima adds functionality to Maxima. WxMaxima’s ability to generate reports by exporting a workbook’s contents to HTML and LaTeX files has been mentioned. This section considers some ways that wxMaxima enhances the inclusion of graphics in a session.

2.1 为变量添加下标

wxsubscripts specifies, if (and how) wxMaxima will autosubscript variable names:

If it is false, the functionality is off, wxMaxima will not autosubscript part of variable names after an underscore.

If it is set to 'all, everything after an underscore will be subscripted.

If it is set to true variable names of the format x_y are displayed using a subscript if

How variables are autosubscripted using wxsubscripts

If the variable name doesn’t match these requirements, it can still be declared as “to be subscripted” using the command wxdeclare_subscript(variable_name); or wxdeclare_subscript([variable_name1,variable_name2,...]); Declaring a variable as subscripted can be reverted using the following command: wxdeclare_subscript(variable_name,false);

You can use the menu “View->Autosubscript” to set these values.

2.2 在状态栏中提供反馈信息

Long-running commands can provide user feedback in the status bar. This user feedback is replaced by any new feedback that is placed there (allowing to use it as a progress indicator) and is deleted as soon as the current command sent to Maxima is finished. It is safe to use wxstatusbar() even in libraries that might be used with plain Maxima (as opposed to wxMaxima): If wxMaxima isn’t present the wxstatusbar() command will just be left unevaluated.

for i:1 thru 10 do (
    /* 告诉用户目前的运行位置 */
    wxstatusbar(concat("Pass ",i)),
    /* (sleep n) 是可接在字符"?"后使用的 Lisp 函数 */
    /* 它推迟了程序的运行,此处是 3 秒 */
    ?sleep(3)
)$

2.3 绘图

因为绘图功能与图形密切相关,所以图形用户界面理应为原始程序的绘图功能提供一些扩充内容。

2.3.1 Embedding a plot into the worksheet

Maxima normally instructs the external program gnuplot to open a separate window for every diagram it creates. Since many times it is convenient to embed graphs into the worksheet instead wxMaxima provides its own set of plot functions that don’t differ from the corresponding maxima functions save in their name: They are all prefixed by a “wx”. For example wxplot2d corresponds to plot2d, wxplot3d corresponds to plot3d, wxdraw corresponds to draw and wxhistogram corresponds to histogram.

2.3.2 设置嵌入图形的大小

As noted above, the configure dialog provides a way to change the default size plots created which sets the starting value of wxplot_size. The plotting routines of wxMaxima respect this variable that specifies the size of a plot in pixels. It can always be queried or used to set the size of the following plots:

wxplot_size:[1200,800]$
wxdraw2d(
    explicit(
        sin(x),
        x,1,10
    )
)$

如果只更改一个绘制图片的大小,wxMaxima 提供了一种只为当前单元格更改属性的方法。具体用法为,将 wxplot_size=[value1,value2] 附加到 wxdraw2d() 命令结尾,而不是作为该命令的一部分:

wxdraw2d(
    explicit(
        sin(x),
        x,1,10
    )
),wxplot_size=[1600,800]$

Setting the size of embedded plot with wxplot_size works for embedded plots using e.g. wxplot, wxdraw, wxcontour_plot and wximplicit_plot commands and for embedded animations with with_slider_draw and wxanimate commands.

2.3.3 更好的绘图质量

Gnuplot doesn’t seem to provide a portable way of determining whether it supports the high-quality bitmap output that the Cairo library provides. On systems where gnuplot is compiled to use this library the pngCairo option from the configuration menu (that can be overridden by the variable wxplot_pngcairo) enables support for antialiasing and additional line styles. If wxplot_pngCairo is set without gnuplot supporting this the result will be error messages instead of graphics.

2.3.4 在交互式 gnuplot 窗口中打开嵌入的绘图

如果绘图时使用 wxdraw 类型的命令(不含 wxplot2dwxplot3d),并且底层的 gnuplot 项目文件不是太大,则 wxMaxima 提供了一个右键单击菜单,允许在交互式的 gnuplot 窗口中打开绘制的图形。

2.3.5 在绘图窗口中打开 gnuplot 控制台

在 Windows 系统上,如果 Maxima 的变量 gnuplot_command 的值 “gnuplot” 被换为 “wgnuplot”,则 gnuplot 会打开一个控制台窗口,在该窗口中可以输入 gnuplot 的命令。但是,启用此功能会使得每次绘图时 gnuplot 短时间内独占键盘。

2.3.6 在工作簿中嵌入动图

3D diagrams tend to make it hard to read quantitative data. A viable alternative might be to assign the 3rd parameter to the mouse wheel. The with_slider_draw command is a version of wxdraw2d that does prepare multiple plots and allows to switch between them by moving the slider on top of the screen. WxMaxima allows to export this animation as an animated gif.

with_slider_draw 命令的前两个参数是用于控制绘图的变量名称和变量值的列表,接下来的参数与 wxdraw2d 命令的参数相同:

with_slider_draw(
    f,[1,2,3,4,5,6,7,10],
    title=concat("f=",f,"Hz"),
    explicit(
        sin(2*%pi*f*x),
        x,0,1
    ),grid=true
);

对三维绘图而言,类似的功能由命令 with_slider_draw3d 提供,可用参数来旋转三维图形:

wxanimate_autoplay:true;
wxanimate_framerate:20;
with_slider_draw3d(
    α,makelist(i,i,1,360,3),
    title=sconcat("α=",α),
    surface_hide=true,
    contour=both,
    view=[60,α],
    explicit(
        sin(x)*sin(y),
        x,-π,π,
        y,-π,π
    )
)$

如果重要的是图的大致形状,那么只要稍微移动一点,就可以直观地看出它的三维特征:

wxanimate_autoplay:true;
wxanimate_framerate:20;
with_slider_draw3d(
    t,makelist(i,i,0,2*π,.05*π),
    title=sconcat("t=",t),
    surface_hide=true,
    contour=both,
    view=[60,30+5*sin(t)],
    explicit(
        sin(x)*y^2,
        x,-2*π,2*π,
        y,-2*π,2
    )
)$

For those more familiar with plot than with draw, there is a second set of functions:

Normally the animations are played back or exported with the frame rate chosen in the configuration of wxMaxima. To set the speed at an individual animation is played back the variable wxanimate_framerate can be used:

wxanimate(a, 10, sin(a*x), [x,-5,5]),
     wxanimate_framerate=6$

The animation functions use Maxima’s makelist command and therefore share the pitfall that the slider variable’s value is substituted into the expression only if the variable is directly visible in the expression. Therefore the following example will fail:

f:sin(a*x);
with_slider_draw(
    a,makelist(i/2,i,1,10),
    title=concat("a=",float(a)),
    grid=true,
    explicit(f,x,0,10)
)$

如果修改为明确要求 Maxima 代入滑块变量的值,则修改后的代码可用于绘制动图:

f:sin(a*x);
with_slider_draw(
    b,makelist(i/2,i,1,10),
    title=concat("a=",float(b)),
    grid=true,
    explicit(
        subst(a=b,f),
        x,0,10
    )
)$

2.3.7 同时打开多个绘图窗口

While not being provided by wxMaxima this feature of Maxima (on setups that support it) sometimes comes in handily. The following example comes from a post from Mario Rodriguez to the Maxima mailing list:

    load(draw);

    /* Parabola in window #1 */
    draw2d(terminal=[wxt,1],explicit(x^2,x,-1,1));

    /* Parabola in window #2 */
    draw2d(terminal=[wxt,2],explicit(x^2,x,-1,1));

    /* Paraboloid in window #3 */
    draw3d(terminal=[wxt,3],explicit(x^2+y^2,x,-1,1,y,-1,1));

在同一个窗口中绘制这些图形也是可行的:

    wxdraw(
        gr2d(
            key="sin (x)",grid=[2,2],
            explicit(sin(x),x,0,2*%pi)),
        gr2d(
        key="cos (x)",grid=[2,2],
        explicit(cos(x),x,0,2*%pi))
     );

2.3.8 “用 draw 函数绘图”侧边栏

The “Plot using draw” sidebar hides a simple code generator that allows generating scenes that make use of some of the flexibility of the draw package maxima comes with.

2.3.8.1 二维图形

提供绘制二维图形的 draw() 命令的简单模板。然后可以使用具体的绘图命令填充该模板,例如利用“二维图形”按钮下方的其他按钮导入绘图命令。

One helpful feature of the 2D button is that it allows to set up the scene as an animation in which a variable (by default it is t) has a different value in each frame: Often a moving 2D plot allows easier interpretation than the same data in a non-moving 3D one.

2.3.8.2 三维图形

Generates the skeleton of a draw() command that draws a 3D scene. If neither a 2D nor a 3D scene is set up, all of the other buttons set up a 2D scene that contains the command the button generates.

2.3.8.3 表达式

在光标当前所在的 draw() 命令中添加绘图函数表达式,如 sin(x), x*sin(x) 或者 x^2+2*x-4 等 。每个图中可以绘制任意数量的图形。如果没有 draw() 命令,将调用绘制二维图形的模板。

2.3.8.4 隐式图形

尝试寻找满足 y=sin(x)y*sin(x)=3x^2+y^2=4 之类的表达式的所有解,并在光标当前所在的 draw() 命令中绘制对应曲线。如果没有 draw() 命令,将调用绘制二维图形的模板。

2.3.8.5 参数式图形

将变量(如 t)从下限变化到上限,并在当前绘图命令中使用两个表达式(如 t*sin(t)t*cos(t)),以生成曲线上点的横、纵坐标 (x,y)(在三维图形中,第三个表达式生成竖坐标 z)。

2.3.8.6

绘制多个点,并且可以选择顺次连接它们。点的坐标取自列表的列表、二维数组或为每个轴指定的一个列表或数组。

2.3.8.7 图形标题

在图形上方绘制标题。

2.3.8.8 坐标轴

设置坐标轴。

2.3.8.9 等高线

(Only for 3D plots): Adds contour lines similar to the ones one can find in a map of a mountain to the plot commands that follow in the current draw() command and/or to the ground plane of the diagram. Alternatively, this wizard allows skipping drawing the curves entirely only showing the contour plot.

2.3.8.10 图形名称

在图例中增加下一个图形对应的图例项。空名称将阻止为下一个图形生成图例项。

2.3.8.11 线条颜色

为当前 draw() 命令所绘图形设置线条颜色。

2.3.8.12 填充颜色

为当前 draw() 命令所绘图形设置填充颜色。

2.3.8.13 网格

弹出设置网格线的向导。

2.3.8.14 精度

允许选择适当数目的点,以兼顾速度与精度(任何绘图程序都会权衡两者)。

2.4 嵌入图片

如果使用的是 .wxmx 文件格式,则可以通过拖放将图片文件嵌入 wxMaxima 文档中。但有时(例如某个图像的内容可能在稍后发生更改)最好指明在计算时加载图像:

show_image("man.png");

2.5 启动时读取的文件

在 wxMaxima 的设置对话框中可以编辑两个文件的命令,这些命令在启动时被执行:

这些文件位于用户的主目录或配置文件目录中的 Maxima 用户目录(在 Windows 系统中通常为 maxima,在其他系统中为 .maxima)。使用命令 maxima_userdir; 可以确定该目录。

2.6 以 wx 开头的特殊变量

2.7 输出美观的二维公式

函数 table_form() 显示的二维列表比 Maxima 的默认输出更具可读性。该函数的输入是一个列表,其中含一个或多个列表。与 print 命令类似,此命令即使以符号 $ 结尾也会显示输出。以分号 ; 结束命令时,除了得到列表,还会有“done”语句。

table_form(
    [
        [1,2],
        [3,4]
    ]
)$

正如下一个例子所示,可以在执行 table_form 命令之前创建需要显示的列表。

一个三行表的例子

此外,由于矩阵是含列表的列表,它也可以用类似的方式转换为表格。

另一个 table_form 的例子

2.8 错误(bug)报告

WxMaxima provides a few functions that gather bug reporting information about the current system:

2.9 让输出显示为红色

Maxima’s box() command causes wxMaxima to print its argument with a red foreground, if the second argument to the command is the text highlight.


3 疑难解答

3.1 无法连接到 Maxima

Since Maxima (the program that does the actual mathematics) and wxMaxima (providing the easy-to-use user interface) are separate programs that communicate by the means of a local network connection. Therefore the most probable cause is that this connection is somehow not working. For example, a firewall could be set up in a way that it doesn’t just prevent unauthorized connections from the internet (and perhaps intercept some connections to the internet, too), but also blocks inter-process-communication inside the same computer. Note that since Maxima is being run by a Lisp processor the process communication that is blocked does not necessarily have to be named “maxima”. Common names of the program that opens the network connection would be sbcl, gcl, ccl, lisp.exe, or similar names.

On Unix computers another possible reason would be that the loopback network that provides network connections between two programs in the same computer isn’t properly configured.

3.2 从损坏的 .wxmx 文件中取回信息的方法

Internally most modern XML-based formats are ordinary zip files. WxMaxima doesn’t turn on compression, so the contents of .wxmx files can be viewed in any text editor.

If the zip signature at the end of the file is still intact after renaming a broken .wxmx file to .zip most operating systems will provide a way to extract any portion of the information that is stored inside it. This can be done when there is a need of recovering the original image files from a text processor document. If the zip signature isn’t intact that does not need to be the end of the world: If wxMaxima during saving detected that something went wrong there will be a .wxmx~ file whose contents might help.

即使没有 .wxmx~ 文件,.wxmx 文件中 XML 部分是未压缩的,可以将该文件重命名为 .txt 文件,并使用文本编辑器恢复文件中的 XML 部分(以 <?xml version="1.0" encoding="UTF-8"?> 开头,并以 </wxMaximaDocument> 结尾(在 XML 部分的前后,可在文本编辑器中看到一些不可读的二进制内容)。

If a text file containing only these contents (e.g. copy and paste this text into a new file) is saved as a file ending in .xml, wxMaxima will know how to recover the text from the document.

3.3 在命令完成前显示一些调试信息

通常 wxMaxima 会等待最后的公式形成后才开始输出,这节省了多次尝试输出部分公式的时间。不过, disp() 命令可以立即输出调试信息,而不必等待当前的 Maxima 命令完成:

for i:1 thru 10 do (
   disp(i),
   /* (sleep n) 是可接在字符"?"后使用的 Lisp 函数 */
   /* 它推迟了程序的运行,此处是 3 秒 */
   ?sleep(3)
)$

3.4 绘图结果是空的绘图框和错误信息

这意味着 wxMaxima 无法读取由 Maxima 指示 gnuplot 创建的文件。

这个错误的可能原因如下:

3.5 绘制动图时得到“error: undefined variable(错误:未定义的变量)”

The value of the slider variable by default is only substituted into the expression that is to be plotted if it is visible there. Using a subst command that substitutes the slider variable into the equation to plot resolves this problem. At the end of section Embedding animations into the spreadsheet, you can see an example.

3.6 I lost cell content and undo doesn’t remember

对单元格的操作和单元格内部的更改均有单独的撤消函数,因此发生这种情况的可能性很低。如果确实是这样,有如下方法可以恢复数据:

playback();

3.7 WxMaxima starts up with the message “Maxima process terminated.”

一个可能的原因是,在设置对话框的“Maxima”选项卡中设置的位置找不到 Maxima 程序,因此根本无法运行 Maxima。将路径设置为有效的 Maxima 二进制文件所在文件夹应该可以解决此问题。

3.8 Maxima 永远在计算中而不响应输入

理论上讲,有可能是 wxMaxima 没有意识到 Maxima 已经完成了计算,因此没有得到通知,以告知它可以向 Maxima 发送新的数据。如果是这种情况,重新求值可能会使两个程序同步。

3.9 基于 SBCL 的 Maxima 耗尽内存

The Lisp compiler SBCL by default comes with a memory limit that allows it to run even on low-end computers. When compiling a big software package like Lapack or dealing with extremely big lists of equations this limit might be too low. In order to extend the limits, SBCL can be provided with the command line parameter --dynamic-space-size that tells SBCL how many megabytes it should reserve. A 32bit Windows-SBCL can reserve up to 999 Megabytes. A 64-bit SBCL version running on Windows can be instructed to use more than the about 1280 Megabytes compiling Lapack needs.

为 Maxima(因此也为 SBCL)提供命令行参数的一种方法是利用 wxMaxima 设置对话框的“额外的 Maxima 参数(Additional parameters for Maxima)”字段。

SBCL 内存

3.10 在 Ubuntu 系统上,有时输入无响应或响应迟缓

安装软件包 ibus-gtk 应该可以解决此问题. 详情见 https://bugs.launchpad.net/ubuntu/+source/wxwidgets3.0/+bug/1421558

3.11 WxMaxima halts when Maxima processes Greek characters or Umlauts

如果所使用的 Maxima 基于SBCL,则必须将以下行添加到 .sbclrc 文件中:

(setf sb-impl::*default-external-format* :utf-8)

The folder where this file has to be placed is system- and installation-specific. But any SBCL-based Maxima that already has evaluated a cell in the current session will happily tell where it can be found after getting the following command:

:lisp (sb-impl::userinit-pathname)

3.12 绘图

3.12.1 是否可以同时输出和嵌入绘图文件?

The worksheet embeds .png files. WxMaxima allows the user to specify where they should be generated:

wxdraw2d(
    file_name="test",
    explicit(sin(x),x,1,10)
);

If a different format is to be used, it is easier to generate the images and then import them into the worksheet again:

load("draw");
pngdraw(name,[contents]):=
(
    draw(
        append(
            [
                terminal=pngcairo,
                dimensions=wxplot_size,
                file_name=name
            ],
            contents
        )
    ),
    show_image(printf(false,"~a.png",name))
);
pngdraw2d(name,[contents]):=
    pngdraw(name,gr2d(contents));

pngdraw2d("Test",
        explicit(sin(x),x,1,10)
);

3.12.2 是否可以指定绘制图形的相对比例?

Not directly using Maxima. But there are Gnuplot commands for it:

wxdraw2d(
    proportional_axis=xy,
    explicit(sin(x),x,1,10)
),wxplot_size=[1000,1000];

3.12.3 After upgrading to MacOS 13.1 plot and/or draw commands output error messages like


1 HIToolbox 0x00007ff80cd91726 _ZN15MenuBarInstance22EnsureAutoShowObserverEv + 102
2 HIToolbox 0x00007ff80cd912b8 _ZN15MenuBarInstance14EnableAutoShowEv + 52
3 HIToolbox 0x00007ff80cd35908 SetMenuBarObscured + 408
...

This might be an issue with the operating system. Disable the hiding of the menu bar (SystemSettings => Desktop & Dock => Menu Bar) might solve the issue. See wxMaxima issue #1746 for more information.


4 常见提问(FAQ)

4.1 有没有办法在 LaTeX 页面中显示更多的文字?

Yes. Use the LaTeX package “geometry” to specify the size of the borders.

You can add the following line to the LaTeX preamble (for example by using the respective field in the config dialogue (“Export”->“Additional lines for the TeX preamble”), to set borders of 1cm):

\usepackage[left=1cm,right=1cm,top=1cm,bottom=1cm]{geometry}

4.2 是否有深色模式?

If wxWidgets is new enough, wxMaxima will automatically be in dark mode if the rest of the operating system is. The worksheet itself is by default equipped with a bright background. But it can be configured otherwise. Alternatively, there is a View/Invert worksheet brightness menu entry that allows to quickly convert the worksheet from dark to bright and vice versa.

4.3 WxMaxima sometimes hangs for several seconds once in the first minute

WxMaxima delegates some big tasks like parsing Maxima’s >1000-page-manual to background tasks, which normally goes totally unnoticed. At the moment the result of such a task is needed, though, it is possible that wxMaxima needs to wait a couple of seconds before it can continue its work.

4.4 Especially when testing new locale settings, a message box “locale ‘xx_YY’ can not be set” occurs

Locale warning

(The same problem can occur with other applications too). The translations seem okay after you click on ‘OK’. WxMaxima does not only use its own translations but the translations of the wxWidgets framework too.

These locales maybe not present in the system. On Ubuntu/Debian systems they can be generated using: dpkg-reconfigure locales

4.5 How can I use symbols for real numbers, natural numbers (ℝ, ℕ), etc.?

You can find these symbols in the Unicode sidebar (search for ‘double-struck capital’). But the selected font must also support these symbols. If they do not display properly, select another font.


5 命令行参数

Most operating systems provide less complicated ways of starting programs than the command-line so this possibility is only rarely used. WxMaxima still provides some command-line switches, though.

Instead of a minus, some operating systems might use a dash in front of the command-line switches.


6 About the program, contributing to wxMaxima

wxMaxima is mainly developed using the program language C++ using the wxWidgets framework, as build system we use CMake, a small part is written in Lisp. You can contribute to wxMaxima, join the wxMaxima project at https://github.com/wxMaxima-developers/wxmaxima, if you have knowledge of these programming languages and want to help and contribute to the open source project wxMaxima.

The source code of wxMaxima is documented using Doxygen here.

The program is nearly self-contained, so except for system libraries (and the wxWidgets library), no external dependencies (like graphic files or the Lisp part (the wxmathML.lisp-file) is needed, these files are included in the executable.

If you are a developer, you might want to try out a modified wxmathML.lisp-file without recompiling everything, one can use the command line option --wxmathml-lisp=<str> to use another Lisp file, not the included one.