Maxima简介
目录
1.概述
2.关键字
3.计算
4.代数
5.微积分
6.矩阵计算
7.Maxima编程
8.Maxima的一部分函数列表
1.概述
在linux下打开Maxima的方法
1.maxima <enter>
在电脑上会显示下列介绍:
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
This is a development version of Maxima. The function bug_report()
provides bug reporting information.
(%i1)
这个(%i1)是一个标签,每一个输入输出在它的前面都会有一个标签,i表示你所输入进去的代码(input),o表示电脑对代码作业的响应(output).不要用像%i1或者是%o2这样的变量名,因为这样很容易与标签混淆了.
maxima分辩大小写.所有的内建函数都只有一个小写的函数名如(sin,cos,save,load,etc).内建的常值也有一个小写的名字(% e,%pi,inf,etc).如果你键入SIN(x)或者是Sin(x),Maxima会把它当作和sin(x)不同的函数来处理.用户自己定义函数和 变量名的时候大写小写都可以选择.foo(XY),Foo(xy),FOO(xy)都是不同的函数.
2.关键字
1.结束maxima时,键入quit();
2.中断maxima而不离开时,用快捷键Ctrl+c.知道怎样使用这种中断的方法很重要,举个例子,如果你在做一个要费很长时间的计算 ,如
(%i)sum(1/x^2,x,1,100000);
maxima encountered a lisp error:
console interrupt.
Automatically continuing.
to reenable the lisp debugger set *debugger-hook* to nil.
(%i2)
3.用符号;告诉maxima你输入的命令结束,然后点回车.
4.另外一个结束的命令符是$,但是它不在屏幕显示出maxima计算的结果.这对于有很长的中间过程变量的计算来说是很有用的,因为你不需要花费很长的时间让它显示在屏幕上.
5.如果你不想输入刚才你已经输入的命令,打个比方你想输入你刚才输入的第五行(%i5),你只要在前面加上一对单引号,如,”%i5.
6.如果你想得到maxima当前运行的结果,你可以用它的O标签,也可以用特特殊的显示符号(%);
7.标准量,e,i,pi在maxima中用%e,%i,%pi,来表示.
3.计算
一般运算符
+ 加
- 减
* 乘
/ 除
^ 幂
. 矩阵计算
sqrt(x) x的平方根
maxima的输出用精确有理数表达出来:
(%i1) 1/100 + 1/101;
201
(%o1) —–
10100
如果计算中出现了一些无理的数,那么它会用符号表示出来 :
u%i2) (1 + sqrt(2))^5;
5
(%o2) (sqrt(2) + 1)
(%i3) expand (%);
(%o3) 29 sqrt(2) + 41
但是,它也常常表达为十进制数,这个方法的表达了”,numer”:
(%i4) %, numer;
(%o4) 82.01219330881976
注意这里用到的%是指先前计算的那个值.这个版本的maxima,number显示了一个16位的值,后面几位常常是不可靠的.但是
用bfloat能够提供一个任意高的精度.
(%i5) bfloat (%o3);
The number of significant figures displayed is controlled by the Maxima variable fpprec, which has
the default value of 16:
值的显示精度是由maxima的fpprec来控制的,它的默认值是16
(%i6) fpprec;
(%o6) 16
这里我们可以重新设定它的值:
3
(%i7) fpprec: 100;
(%o7) 100
(%i8) ’’%i5;
(%o8) 8.20121933088197564152489730020812442785204843859314941221#
2371240173124187540110412666123849550160561B1
没有近似估计的大数:
(%i9) 100!;
(%o9) 9332621544394415268169923885626670049071596826438162146859#
2963895217599993229915608941463976156518286253697920827223758251#
185210916864000000000000000000000000
4代数
Maxima’s importance as a computer tool to facilitate analytical calculations becomes more evident
when we see how easily it does algebra for us. Here’s an example in which a polynomial is expanded:
maxima作为一个计算工具的重要性是它能使方便的分析和计算更加现实。下面是多项式展开的一个例子:
(%i1) (x + 3*y + x^2*y)^3;
2 3
(%o1) (x y + 3 y + x)
(%i2) expand (%);
63 43 23 3 52 32
(%o2) x y + 9 x y + 27 x y + 27 y + 3 x y + 18 x y
2 4 2 3
+ 27 x y + 3 x y + 9 x y + x
Now suppose we wanted to substitute 5/z for x in the above expression:
现在假设我们在上一个式子中要用5/z来代替x:
(%i3) %o2, x=5/z;
2 3 2 3
135 y 675 y 225 y 2250 y 125 5625 y 1875 y
(%o3) —— + —— + —– + ——- + — + ——- + ——
z 2 2 3 3 4 4
z z z z z z
2 3
9375 y 15625 y 3
+ ——- + ——– + 27 y
5 6
z z
The Maxima function ratsimp will place this over a common denominator:
在maxima中函数ratsimp将会合并分母相同的项:
(%i4) ratsimp (%);
36 25 3 4
(%o4) (27 y z + 135 y z + (675 y + 225 y) z
2 3 3 2 2
+ (2250 y + 125) z + (5625 y + 1875 y) z + 9375 y z
3 6
+ 15625 y )/z
Expressions may also be factored:
表达式同样也能合并:
4
(%i5) factor (%);
2 3
(3 y z + 5 z + 25 y)
(%o5) ———————-
6
z
maxima同样也能精确的解出非线性系统代数方程。下面这个例子中,我们将解带有三个未知数a b c的三个方程:
(%i6) a + b*c = 1;
(%o6) bc+a=1
(%i7) b - a*c = 0;
(%o7) b-ac=0
(%i8) a + b = 5;
(%o8) b+a=5
(%i9) solve ([%o6, %o7, %o8], [a, b, c]);
25 sqrt(79) %i + 25 5 sqrt(79) %i + 5
(%o9) [[a = ——————-, b = —————–,
6 sqrt(79) %i - 34 sqrt(79) %i + 11
sqrt(79) %i + 1 25 sqrt(79) %i - 25
c = —————], [a = ——————-,
10 6 sqrt(79) %i + 34
5 sqrt(79) %i - 5 sqrt(79) %i - 1
b = —————–, c = - —————]]
sqrt(79) %i - 11 10
注意这个显示包括两个[],每一个中括号的里面都是联立方程的一组精确解。
三角函数在maxima中的计算也是很简单的。
函数trigexpand可以使每一个三角函数都最简化:
(%i10) sin(u + v) * cos(u)^3;
3
(%o10) cos (u) sin(v + u)
(%i11) trigexpand (%);
3
(%o11) cos (u) (cos(u) sin(v) + sin(u) cos(v))
函数trigreduce是使表达转换成另外一种形式,那种形式是一种和的形式,它只包含一种sin 或 cos 函数。
(%i12) trigreduce (%o10);
sin(v + 4 u) + sin(v - 2 u) 3 sin(v + 2 u) + 3 sin(v)
(%o12) ————————— + ————————-
8 8
函数realpart imagpart是返回一个复数的实部和虚部的值:
5
(%i13) w: 3 + k*%i;
(%o13) %i k + 3
(%i14) w^2 * %e^w;
2 %i k + 3
(%o14) (%i k + 3) %e
(%i15) realpart (%);
3 2 3
(%o15) %e (9 - k ) cos(k) - 6 %e k sin(k)
5微积分
Maxima can compute derivatives and integrals, expand in Taylor series, take limits, and obtain exact solutions to ordinary differential equations. We begin by defining the symbol f to be the following function of x:
maxima能计算微分和积分,展开泰勒级数,求极限和精确的求解常微分方程。首先我们先定义一个以x为自变量的函数f:
(%i1) f: x^3 * %e^(k*x) * sin(w*x);
3 kx
(%o1) x %e sin(w x)
We compute the derivative of f with respect to x:
我们求f关于x的导数:
(%i2) diff (f, x);
3 kx 2 kx
(%o2) k x %e sin(w x) + 3 x %e sin(w x)
3 kx
+wx %e cos(w x)
Now we find the indefinite integral of f with respect to x:
现在我们求f关于x的不定积分:
(%i3) integrate (f, x);
6 34 52 7 3
(%o3) (((k w + 3 k w + 3 k w + k ) x
6 24 42 6 2
+ (3 w + 3 k w - 3 k w - 3 k ) x
4 32 5 4 22 4
+ (- 18 k w - 12 k w + 6 k ) x - 6 w + 36 k w - 6 k )
kx 7 25 43 6 3
%e sin(w x) + ((- w - 3 k w - 3 k w - k w) x
5 33 5 2
+ (6 k w + 12 k w + 6 k w) x
5 23 4 3 3 kx
+ (6 w - 12 k w - 18 k w) x - 24 k w + 24 k w) %e
8 26 44 62 8
cos(w x))/(w + 4 k w + 6 k w + 4 k w + k )
A slight change in syntax gives definite integrals:
在语法上的一些小的改变就能求一个定积分:
(%i4) integrate (1/x^2, x, 1, inf);
(%o4) 1
(%i5) integrate (1/x, x, 0, inf);
积分是发散的:
Integral is divergent
– an error. Quitting. To debug this try debugmode(true);
Next we define the simbol g in terms of f (previously defined in %i1) and the hyperbolic sine function,and find its Taylor series expansion (up to, say, order 3 terms) about the point x = 0:
我们定义一个字符g 它是由f函数和sin函数表达,并求出在x=0处泰勒级数的展开:
(%i6) g: f / sinh(k*x)^4;
3 kx
x %e sin(w x)
(%o6) —————–
4
sinh (k x)
(%i7) taylor (g, x, 0, 3);
2 3 2 2 3 3
w wx (w k + w ) x (3 w k + w ) x
(%o7)/T/ — + — - ————– - —————- + . . .
4 3 4 3
k k 6k 6k
求g关于x趋向于0的极限:
(%i8) limit (g, x, 0);
w
(%o8) –
4
k
maxima同样能够允许函数微分不进行计算表达出来,它的形式为:
(%i9) ’diff (y, x);
dy
(%o9) –
dx
The quote operator in (%i9) means “do not evaluate”. Without it, Maxima would have obtained 0:
上面式中’的意思是不计算出来,没有它,maxima就会是0:
(%i10) diff (y, x);
(%o10) 0
Using the quote operator we can write differential equations:
使用’能使我们写出微分方程:
(%i11) ’diff (y, x, 2) + ’diff (y, x) + y;
2
dy dy
(%o11) — + — + y
2 dx
dx
Maxima’s ode2 function can solve first and second order ODE’s:
maxima的ode2 function能解一阶和二阶常微分方程:
(%i12) ode2 (%o11, y, x);
- x/2 sqrt(3) x sqrt(3) x
(%o12) y = %e (%k1 sin(———) + %k2 cos(———))
2 2
7