Maxima

Maxima包含在Sage中,是用clisp(Lisp语言的一种)实现的。Maxima所使用的开源的基于Tk/Tcl的绘图程序openmath随Sage一同发布。然而,gnuplot包(Maxima默认的绘图程序)作为Sage的可选包发布。除了别的功能,Maxima可以做符号计算。Maxima可以做符号积分和微分,解1阶常微分方程组,大多数2阶线性常微分方程组,并且实现了对任意阶的线性方程组进行Laplace变换。Maxima还了解很多特殊函数,能够通过gnuplot绘图,进行矩阵运算(如行消去,特征值和特征向量),以及求解多项式方程组。

我们通过构造矩阵来展示Sage的Maxima接口,其中$i,j$项是$i/j$,$i,j=1,\ldots,4$。

  1. sage: f = maxima.eval('ij_entry[i,j]:= i/j')
  2. sage: A = maxima('genmatrix(ij_entry,4,4)'); A
  3. matrix([1,1/2,1/3,1/4],[2,1,2/3,1/2],[3,3/2,1,3/4],[4,2,4/3,1])
  4. sage: A.determinant()
  5. 0
  6. sage: A.echelon()
  7. matrix([1,1/2,1/3,1/4],[0,0,0,0],[0,0,0,0],[0,0,0,0])
  8. sage: A.eigenvalues()
  9. [[0,4],[3,1]]
  10. sage: A.eigenvectors()
  11. [[[0,4],[3,1]],[[[1,0,0,-4],[0,1,0,-2],[0,0,1,-4/3]],[[1,2,3,4]]]]

另外一个例子:

  1. sage: A = maxima("matrix ([1, 0, 0],[1, -1, 0],[1, 3, -2])")
  2. sage: eigA = A.eigenvectors()
  3. sage: V = VectorSpace(QQ,3)
  4. sage: eigA
  5. [[[-2,-1,1],[1,1,1]],[[[0,0,1]],[[0,1,3]],[[1,1/2,5/6]]]]
  6. sage: v1 = V(sage_eval(repr(eigA[1][0][0]))); lambda1 = eigA[0][0][0]
  7. sage: v2 = V(sage_eval(repr(eigA[1][1][0]))); lambda2 = eigA[0][0][1]
  8. sage: v3 = V(sage_eval(repr(eigA[1][2][0]))); lambda3 = eigA[0][0][2]
  9. sage: M = MatrixSpace(QQ,3,3)
  10. sage: AA = M([[1,0,0],[1, - 1,0],[1,3, - 2]])
  11. sage: b1 = v1.base_ring()
  12. sage: AA*v1 == b1(lambda1)*v1
  13. True
  14. sage: b2 = v2.base_ring()
  15. sage: AA*v2 == b2(lambda2)*v2
  16. True
  17. sage: b3 = v3.base_ring()
  18. sage: AA*v3 == b3(lambda3)*v3
  19. True

最后,我们给一个通过Sage调用openmath绘图的例子。这里很多内容是根据Maxima参考手册修改而来。

绘制多个函数的二维图像:

  1. sage: maxima.plot2d('[cos(7*x),cos(23*x)^4,sin(13*x)^3]','[x,0,1]', # not tested
  2. ....: '[plot_format,openmath]')

“实时”的三维图像,可以用鼠标拖动:

  1. sage: maxima.plot3d ("2^(-u^2 + v^2)", "[u, -3, 3]", "[v, -2, 2]", # not tested
  2. ....: '[plot_format, openmath]')
  3. sage: maxima.plot3d("atan(-x^2 + y^3/4)", "[x, -4, 4]", "[y, -4, 4]", # not tested
  4. ....: "[grid, 50, 50]",'[plot_format, openmath]')

下面是著名的Möbius带:

  1. sage: maxima.plot3d("[cos(x)*(3 + y*cos(x/2)), sin(x)*(3 + y*cos(x/2)), y*sin(x/2)]", # not tested
  2. ....: "[x, -4, 4]", "[y, -4, 4]", '[plot_format, openmath]')

下面是著名的Klein瓶:

  1. sage: maxima("expr_1: 5*cos(x)*(cos(x/2)*cos(y) + sin(x/2)*sin(2*y)+ 3.0)- 10.0")
  2. ....: 5*cos(x)*(sin(x/2)*sin(2*y)+cos(x/2)*cos(y)+3.0)-10.0
  3. sage: maxima("expr_2: -5*sin(x)*(cos(x/2)*cos(y) + sin(x/2)*sin(2*y)+ 3.0)")
  4. -5*sin(x)*(sin(x/2)*sin(2*y)+cos(x/2)*cos(y)+3.0)
  5. sage: maxima("expr_3: 5*(-sin(x/2)*cos(y) + cos(x/2)*sin(2*y))")
  6. 5*(cos(x/2)*sin(2*y)-sin(x/2)*cos(y))
  7. sage: maxima.plot3d ("[expr_1, expr_2, expr_3]", "[x, -%pi, %pi]", # not tested
  8. ....: "[y, -%pi, %pi]", "['grid, 40, 40]",'[plot_format, openmath]')