声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 3507|回复: 1

[其它软件] Maxima手册

[复制链接]
发表于 2007-6-29 01:30 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
很偶然的机会让我遇到了MAXIMA并产生了学习的兴趣。可是网上有关的资料非常少,中文的就更少了。幸亏软件自带帮助手册。所以打算从此处入手,一边翻译一边学习。顺便也可以为朋友们提供一份看的过去的东西。由于自己的英文水平的浅陋,很多地方自己看的似懂非懂,还要在底下琢磨,不过会尽量忠实于原文。实在译不出的会根据自己的理解来写。

MAXIMA是一个完整的计算机代数计算系统。
MAXIMA是由William F. Schelter用COMMON LISP实现的 , 基于MIT上的Macsyma的最初版本,由能源部门发布。现在从DOE获得了派生版本的权限,并遵守GNU公共协议。

MAXIMA介绍
当键入“maxima”命令启动MAXIMA后,MAXIMA会显示版本信息和提示符。每个MAXIMA命令都以分号结尾。以“quit()”结束对话,退出系统。下面是一个简单的对话的例子:
  1. sonia$ maxima
  2. GCL (GNU Common Lisp)  Version(2.3) Tue Mar 21 14:15:15 CST 2000
  3. Licensed under GNU Library General Public License
  4. Contains Enhancements by W. Schelter
  5. Maxima 5.4 Tue Mar 21 14:14:45 CST 2000 (enhancements by W. Schelter)
  6. Licensed under the GNU Public License (see file COPYING)
  7. (C1) factor(10!);

  8.                                    8  4  2
  9. (D1)                              2  3  5  7
  10. (C2) expand((x+y)^6);

  11.            6        5       2  4       3  3       4  2      5      6
  12. (D2)      y  + 6 x y  + 15 x  y  + 20 x  y  + 15 x  y  + 6 x  y + x
  13. (C3) factor(x^6-1);

  14.                                      2            2
  15. (D3)               (x - 1) (x + 1) (x  - x + 1) (x  + x + 1)
  16. (C4) quit();

  17. sonia$
复制代码


MAXIMA可以搜索信息页。使用describe命令可以显示其所带参数相关的文档。如:
  1. (C1) describe(factor);

  2. 0: DONTFACTOR :(maxima.info)Definitions for Matrices and ..
  3. 1: EXPANDWRT_FACTORED :Definitions for Simplification.
  4. 2: FACTOR :Definitions for Polynomials.
  5. 3: FACTORFLAG :Definitions for Polynomials.
  6. 4: FACTORIAL :Definitions for Number Theory.
  7. 5: FACTOROUT :Definitions for Polynomials.
  8. 6: FACTORSUM :Definitions for Polynomials.
  9. 7: GCFACTOR :Definitions for Polynomials.
  10. 8: GFACTOR :Definitions for Polynomials.
  11. 9: GFACTORSUM :Definitions for Polynomials.
  12. 10: MINFACTORIAL :Definitions for Number Theory.
  13. 11: NUMFACTOR :Definitions for Special Functions.
  14. 12: SAVEFACTORS :Definitions for Polynomials.
  15. 13: SCALEFACTORS :Definitions for Miscellaneous Options.
  16. 14: SOLVEFACTORS :Definitions for Equations.
  17. Enter n, all, none, or multiple choices eg 1 3 : 2 8;

  18. Info from file /d/linux/local/lib/maxima-5.4/info/maxima.info:
  19. - Function: FACTOR (EXP)
  20.      factors the expression exp, containing any number of variables or
  21.      functions, into factors irreducible over the integers.
  22.      FACTOR(exp, p) factors exp over the field of integers with an
  23.      element adjoined whose minimum polynomial is p.  FACTORFLAG[FALSE]
  24.      if FALSE suppresses the factoring of integer factors of rational
  25.      expressions.  DONTFACTOR may be set to a list of variables with
  26.      respect to which factoring is not to occur.  (It is initially
  27.      empty).  Factoring also will not take place with respect to any
  28.      variables which are less important (using the variable ordering
  29.      assumed for CRE form) than those on the DONTFACTOR list.
  30.      SAVEFACTORS[FALSE] if TRUE causes the factors of an expression
  31.      which is a product of factors to be saved by certain functions in
  32.      order to speed up later factorizations of expressions containing
  33.      some of the same factors.  BERLEFACT[TRUE] if FALSE then the
  34.      Kronecker factoring algorithm will be used otherwise the Berlekamp
  35.      algorithm, which is the default, will be used.  INTFACLIM[1000] is
  36.      the largest divisor which will be tried when factoring a bignum
  37.      integer.  If set to FALSE (this is the case when the user calls
  38.      FACTOR explicitly), or if the integer is a fixnum (i.e.  fits in
  39.      one machine word), complete factorization of the integer will be
  40.      attempted.  The user's setting of INTFACLIM is used for internal
  41.      calls to FACTOR. Thus, INTFACLIM may be reset to prevent MACSYMA
  42.      from taking an inordinately long time factoring large integers.
  43.      NEWFAC[FALSE] may be set to true to use the new factoring routines.
  44.      Do EXAMPLE(FACTOR); for examples.

  45. - Function: GFACTOR (EXP)
  46.      factors the polynomial exp over the Gaussian integers (i.  e.
  47.      with SQRT(-1) = %I adjoined).  This is like FACTOR(exp,A**2+1)
  48.      where A is %I.
  49.           (C1)  GFACTOR(X**4-1);
  50.           (D1)        (X - 1) (X + 1) (X + %I) (X - %I)
  51. (D1)                      FALSE
复制代码


要想在以后的运算中使用当前的一个结果,可以把它赋值给一个变量或者通过它自动提供的标签来引用它。另外,%用来引用最近的计算结果。例如:
  1. C2) u:expand((x+y)^6);

  2.            6        5       2  4       3  3       4  2      5      6
  3. (D2)     y  + 6 x y  + 15 x  y  + 20 x  y  + 15 x  y  + 6 x  y + x
  4. (C3) diff(u,x);

  5.                 5         4       2  3       3  2       4        5
  6. (D3)        6 y  + 30 x y  + 60 x  y  + 60 x  y  + 30 x  y + 6 x
  7. (C4) factor(d3);

  8.                                            5
  9. (D4)                             6 (y + x)
  10. MAXIMA 可以使用复数和数字常量。
  11. (C6) cos(%pi);

  12. (D6)                                  - 1

  13. (C7) %e^(%i*%pi);

  14. (D7)                                  - 1
复制代码



MAXIMA可以进行微积分运算,如:
  1. C8) u:expand((x+y)^6);

  2.            6        5       2  4       3  3       4  2      5      6
  3. (D8)     y  + 6 x y  + 15 x  y  + 20 x  y  + 15 x  y  + 6 x  y + x
  4. (C9) diff(%,x);

  5.                 5         4       2  3       3  2       4        5
  6. (D9)        6 y  + 30 x y  + 60 x  y  + 60 x  y  + 30 x  y + 6 x
  7. (C10) integrate(1/(1+x^3),x);

  8.                                          2 x - 1
  9.                        2            ATAN(-------)
  10.                   LOG(x  - x + 1)        SQRT(3)    LOG(x + 1)
  11. (D10)           - --------------- + ------------- + ----------
  12.                          6             SQRT(3)          3
复制代码


MAXIMA可以求解线形系统和三次方程。
  1. C11) linsolve( [ 3*x + 4*y = 7, 2*x + a*y = 13], [x,y]);

  2.                                7 a - 52        25
  3. (D11)                     [x = --------, y = -------]
  4.                                3 a - 8       3 a - 8
  5. (C12) solve( x^3 - 3*x^2 + 5*x = 15, x);

  6. (D12)              [x = - SQRT(5) %I, x = SQRT(5) %I, x = 3]
复制代码


MAXIMA也可以求解非线形方程。注意,如果你不打算在屏幕上显示结果的话,可以使用“$”来代替命令结尾的“;”。
  1. C13) eq1: x^2 + 3*x*y + y^2 = 0$

  2. (C14) eq2: 3*x + y = 1$

  3. (C15) solve([eq1, eq2]);

  4.               3 SQRT(5) + 7      SQRT(5) + 3
  5. (D15) [[y = - -------------, x = -----------],
  6.                     2                 2

  7.                                     3 SQRT(5) - 7        SQRT(5) - 3
  8.                                [y = -------------, x = - -----------]]
  9.                                           2                   2
复制代码


在X window系统下,MAXIMA可以生成一个或多个函数的图形:
  1. (C13) plot2d(sin(x)/x,[x,-20,20]);

  2. (YMIN -3.0 YMAX 3.0 0.29999999999999999)
  3. (D13)                                  0
  4. (C14) plot2d([atan(x), erf(x), tanh(x)], [x,-5,5]);

  5. (YMIN -3.0 YMAX 3.0 0.29999999999999999)
  6. (YMIN -3.0 YMAX 3.0 0.29999999999999999)
  7. (YMIN -3.0 YMAX 3.0 0.29999999999999999)
  8. (D14)                                  0
  9. (C15) plot3d(sin(sqrt(x^2+y^2))/sqrt(x^2+y^2),[x,-12,12],[y,-12,12]);

  10. (D15)                                  0
复制代码


移动光标到图形窗口的左上角,系统将弹出一个菜单以供你生成图形的PostScript文件。(默认存储在你的home目录下。)并且你还可以旋转一个3D图形。

小注:①MAXIMA有Windows版本。
             ②最后让我们以一个MAXIMA生成的3D图形例子来结束本节,输入以下命令并回车。
plot3d(x^2+y^2,[x,-12,12],[y,-12,12]);

sdfplot.jpg

转自:http://www.cnblogs.com/sirsunny/category/8680.html

[ 本帖最后由 suffer 于 2007-6-29 01:33 编辑 ]
回复
分享到:

使用道具 举报

 楼主| 发表于 2007-6-29 01:35 | 显示全部楼层
帮助介绍

    最有用的在线帮助命令是DESCRIBE,通过给它设定参数可以获得包含其参数指定字符的所有相关命令的帮助信息。比如你想知道一个内置运算的意思例如INTEGER 或者FACTOR等,可以输入describe(“fact”)。另外你也可以输入 ?fact 。比如下面这个例子:
  
  1. C3) ? inte;

  2. 0: (maxima.info)Integration.
  3. 1: Introduction to Integration.
  4. 2: Definitions for Integration.
  5. 3: INTERRUPTS.
  6. 4: ASKINTEGER :Definitions for Simplification.
  7. 5: DISPLAY_FORMAT_INTERNAL :Definitions for Input and Output.
  8. 6: INTEGERP :Definitions for Miscellaneous Options.
  9. 7: INTEGRATE :Definitions for Integration.
  10. 8: INTEGRATION_CONSTANT_COUNTER :Definitions for Integration.
  11. 9: INTERPOLATE :Definitions for Numerical.
  12. Enter n, all, none, or multiple choices eg 1 3 : 7 8;

  13. Info from file /d/linux2/local/share/info/maxima.info:
  14. - Function: INTEGRATE (EXP, VAR)
  15.      integrates exp with respect to var or returns an integral
  16.      expression (the noun form) if it cannot perform the integration
  17.      (see note 1 below).  Roughly speaking three stages are used:
复制代码

在上例中,用户说他打算看看第7和第8项的内容。注意“;”必须跟在两个数字之后。他也可以输入all以查看所有的项。


LISP和Maxima

    Maxima全部是用lisp写的。这里有一个关于函数和变量的命名约定:在lisp层中所有的以一个$开头的符号在macsyma级别读入时,这个$将会被去掉。例如在lisp下面有这样两个函数:TRANSLATE和$TRANSLATE。如果在macsyma层你调用函数 TRANSLATE(FOO); 这个函数实际上是调用的$TRANSLATE函数。存取别的函数必须加上?前缀。
  1. (C1) ?TRANSLATE(FOO);
复制代码


!注意不要在?和函数名之间加入空格,否则maxima会以为你想查看该函数的帮助信息。
因为是完全不同的函数,所以不会得到你想要的结果。

   你可以按照下面的方式输入lisp命令。
  1. (C1) :lisp (foo 1 2)
复制代码


    或者使用to_lisp();得到一个lisp提示,退出maxima并进入lisp。
    交替的键入Ctrl-c 将进入debug中断。这样可以进入一个lisp break loop。你现在可以对$d2进行求值并查看在lisp内部格式中符号标记D2的值。如果你处在一个debug break中,可以键入 :q 退回到顶层。如果你已经使用to_lisp();命令退出了maxima,你可以输入以下命令来重新启动Maxima会话。

  1. MAXIMA>(run)
复制代码


   
    如果打算写个lisp函数并在macsyma层调用它,你应该在函数名前加上$。注意所有在lisp层输入的符号都会被自动
变为大写字母,除非使用类似 |$odeSolve| 使之保持原来的样子。
    在Maxima中允许混合大小写输入一个符号,如果这个符号在之前已经存在则会自动变成大写。如果该符号是第一次
被读入,而且没有和它具有相同字母只是大小写不同的符号存在,就不会变成大写。下面是一个例子:

  1. (C1) Integrate;
  2. (D1) INTEGRATE

  3. (C2) Integ;
  4. (D2) Integ
复制代码


这是因为Integrate 符号已经存在了,它是Maxima的一个基本元素,所以会自动变为大写。但是INTEG并不存在,因此Integ的写法是允许的。这看起来有点怪。这样做的优点是当你输入小写符号时可以立即知道它是不是maxima的关键字和函数。

要从lisp层进入Maxima,必须使用#$宏。

                          (setq $foo #$[x,y]$)

按照下面的输入可以得到相同的结果:

  1. (C1)FOO:[X,Y];
复制代码


不过foo不会在VALUES 列表中显示。 要想看到foo的macsyma打印格式必须输入:

(displa $foo)

    在本文档中当我们想要引用一个 macsyma 符号的时候,我们通常将省略$。但是如果我们同时又想要引用一个lisp符号的话这样做会引起混乱。我们通常使用小写字母来表示lisp 符号,表示macsyam符号时则使用大写字母。例如 LIST 指的是 $list,而list则指的是lisp符号“list”。

既然使用MAXIMA语言定义的函数不是普通的lisp函数,你必须使用mfuncall来调用它们。例如:

  1. (D2)                        FOO(X, Y) := X + Y + 3
复制代码


then at lisp level

CL-MAXIMA>>(mfuncall '$foo 4 5)
12

许多 lisp 函数 are shadowed 在maxima 包。这是因为它们在maxima中的用法和作为一个系统函数被定义不一致。例如在common lisp 的行为和在Maclisp中的就不一样。如果你想在maxima包使用zeta lisp 方式你应该使用 global:typep (or cl:typep for common lisp)。就像这样:

  (macsyma:typep '(1 2)) ==> 'list
  (lisp:typep '(1 2))==> error (lisp:type-of '(1 2))==> 'cons


看一下在"src/maxima-package.lisp"哪个符号被shadowed ,或者看看在lisp下所做的包的描述。


垃圾收集

符号计算会造成大量的垃圾。对其有效得加以控制在完成一些工作时是至关紧要的。

借着 GCL 的帮助, UNIX 系统下可以使用保护系统调用 (包括 SUN OS 4.0 和 一些BSD变种) 一个层次垃圾收集。它只对最近才写入的页进行收集。相关信息请参考ALLOCATE 和 GBCGCL 下的CGL文档。 在 lisp level 使用 (setq si::*notify-gbc* t) 将会帮你确定哪个区域可能需要更多的空间。

文件编制

资料的源代码是 `.texi' tex格式。通过这个格式我们可以生成在线命令 ? 和 describe 所使用的文件信息,也可以生成html或pdf文件。


帮助命令:

Function: DEMO (file)

功能和BATCH 相同,但是会在每个命令行之后暂停并在键入一个空格后继续。(如果在xmaxima下运行,则需要在一个新行后输入;)。demo文件都以.dem结尾。

Function: DESCRIBE (cmd)

这个命令将显示包含 "cmd"字符串的所有命令的相关信息。
(C1) describe("integ");
0: (maxima.info)Integration.
1: Introduction to Integration.
2: Definitions for Integration.
3: ASKINTEGER :Definitions for Simplification.
..
Enter n, all, none, or multiple choices eg 1 3 : 2 3;
Info from file /d/linux2/local/share/info/maxima.info:
Definitions for Integration
===========================

- Function: CHANGEVAR (EXP,F(X,Y),Y,X)
...

Function: EXAMPLE (command)
    将启动一个关于command命令如何工作的实例。像DEMO命令一样在每个命令行后都会暂停等待输入一个空格。
    包含在例子中的文件的名字由 manual_demo变量提供,默认是 maxima.dem。
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-5-9 18:20 , Processed in 0.134399 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表