Linux下的数学工具Maxima 简明教程(下)

三角运算
(%i1) trigexpand(sin(10*x+y));
(%o1)                 cos(10 x) sin(y) + sin(10 x) cos(y)
(%i2) trigexpand(sin(2*x));
(%o2)                           2 cos(x) sin(x)
(%i3) trigsimp(2*cos(x)^2+sin(x)^2);
                                     2
(%o3)                             cos (x) + 1
(%i4) trigreduce(-sin(x)^2+3*cos(x)^2+x);
                      cos(2 x)      cos(2 x)   1        1
(%o4)                 -------- + 3 (-------- + -) + x - -
                         2             2       2        2

代数推理
(%i1) assume(x>0,y<-1,z>=0);
(%o1)                      [x > 0, y < - 1, z >= 0]
(%i2) assume(a<b and b<c);
(%o2)                           [b > a, c > b]
(%i3) facts();
(%o3)               [x > 0, - 1 > y, z >= 0, b > a, c > b]
(%i4) is(a>c);
(%o4)                                false
(%i5) is(z-y>0);
(%o5)                                true
(%i6) is(z-x>0);

Maxima was unable to evaluate the predicate:
z - x > 0
-- an error.  Quitting.  To debug this try debugmode(true);
(%i7) prederror:false;
(%o7)                                false
(%i8) is(z-x>0);
(%o8)                               unknown
(%i9) forget(a<b);
(%o9)                               [b > a]
(%i10) is(a>c);
(%o10)                              unknown

级数计算
(%i1) sum(i,i,1,5);
(%o1)                                 15
(%i2) sum(i^2,i,1,5);
(%o2)                                 55
(%i3) sum(1/2^i,i,1,inf);
                                   inf
                                   ====
                                        1
(%o3)                               >    --
                                   /      i
                                   ====  2
                                   i = 1
(%i4) sum(1/2^i,i,1,inf),simpsum;
(%o4)                                  1
(%i5) sum(1/i^2,i,1,inf),simpsum;
                                        2
                                     %pi
(%o5)                                ----
                                      6
(%i6) sum(1/i,i,1,inf),simpsum;
(%o6)                                 inf

微积分
(%i1) limit(1/x,x,inf);
(%o1)                                  0
(%i2) limit(sin(x)/x,x,0);
(%o2)                                  1
(%i3) limit(sin(x),x,inf);
(%o3)                            &n
bsp;    ind
(%i4) diff(3*x^2+x+5/x,x);
                                       5
(%o4)                            6 x - -- + 1
                                        2
                                       x
(%i5) diff(sin(x)*tan(x),x);
                                           2
(%o5)                   cos(x) tan(x) + sec (x) sin(x)
(%i6) diff(%e^(a*x),x);
                                        a x
(%o6)                               a %e
(%i7) integrate(sin(x)^3,x);
                                  3
                               cos (x)
(%o7)                          ------- - cos(x)
                                  3
(%i8) integrate(x^3,x,1,3);
(%o8)                                 20
(%i9) taylor(%e^x,x,0,3);
                                     2    3
                                    x    x
(%o9)/T/                    1 + x + -- + -- + . . .
                                    2    6
(%i10) taylor(sin(x),x,0,5);
                                  3    5
                                 x    x
(%o10)/T/                    x - -- + --- + . . .
                                 6    120
(%i11) taylor(sqrt(x+1),x,1,3);
                                                     2                  3
                    sqrt(2) (x - 1)   sqrt(2) (x - 1)    sqrt(2) (x - 1)
(%o11)/T/ sqrt(2) + --------------- - ---------------- + ----------------
                           4                 32                128
                                                                        + . . .
(%i12) ratsimp(%);
                      3              2
             sqrt(2) x  - 7 sqrt(2) x  + 43 sqrt(2) x + 91 sqrt(2)
(%o12)       -----------------------------------------------------
                                      128

矩阵运算
(%i1) f[i,j]:=i+j;
(%o1)                           f     := i + j
                                 i, j
(%i2) genmatrix(f,3,3);
                                  [ 2  3  4 ]
                                  [         ]
(%o2)                       &nbs
p;     [ 3  4  5 ]
                                  [         ]
                                  [ 4  5  6 ]
(%i3) g[i,j]:=i-2^j;
                                              j
(%o3)                           g     := i - 2
                                 i, j
(%i4) genmatrix(g,3,3);
                               [ - 1  - 3  - 7 ]
                               [               ]
(%o4)                          [  0   - 2  - 6 ]
                               [               ]
                               [  1   - 1  - 5 ]
(%i5) %o2+%o4;
                                 [ 1  0  - 3 ]
                                 [           ]
(%o5)                            [ 3  2  - 1 ]
                                 [           ]
                                 [ 5  4   1  ]
(%i6) %o2.%o4;
                               [ 2  - 16  - 52 ]
                               [               ]
(%o6)                          [ 2  - 22  - 70 ]
                               [               ]
                               [ 2  - 28  - 88 ]
(%i7) %o2^^3;
                               [ 360  474  588 ]
                               [               ]
(%o7)                          [ 474  624  774 ]
                               [               ]
                               [ 588  774  960 ]
(%i8) x:matrix([17, 3],[-8, 11]);
                                  [ 17   3  ]
(%o8)                             [         ]
                                  [ - 8  11 ]
(%i9) x^^-1;
                                [ 11      3  ]
                                [ ---  - --- ]
                                [ 211    211 ]
(%o9)                           [            ]
                                [  8    17   ]
            &n
bsp;                   [ ---   ---  ]
                                [ 211   211  ]

想了解更多请阅读官方文档:
http://maxima.sourceforge.net/docs/manual/en/maxima.html

做人要厚道
转贴请注明出处

Linux下的数学工具Maxima 简明教程(上)

    这个Blog里曾经多次提到过超强数学软件Mathematica,但目前为止我还没发现它的Linux版,Wine似乎也没有用。其实,在Linux下也有很多类似于Mathematica的数学软件,其中Maxima是我用的最多的一个。这里简单介绍一下Maxima的各个函数供大家参考,也方便我自己今后查询。

安装:sudo apt-get install maxima maxima-share
运行:maxima
退出:quit();

基本运算
(%i1) 2+3;
(%o1)                                  5
(%i2) 5*6;
(%o2)                                 30
(%i3) %+2;
(%o3)                                 32
(%i4) %o1*%o3;
(%o4)                                 160
(%i5) 4/7+3/4;
                                      37
(%o5)                                 --
                                      28
(%i6) float(%);
(%o6)                          1.321428571428571
(%i7) 2^32;
(%o7)                             4294967296
(%i8) 30!;
(%o8)                  265252859812191058636308480000000
(%i9) float(sqrt(2));
(%o9)                          1.414213562373095

三角函数和对数函数
(%i1) float(sin(1));
(%o1)                           0.8414709848079
(%i2) sin(%pi/2);
(%o2)                                  1
(%i3) sin(%pi/2)+cos(%pi/3);
                                       3
(%o3)                                  -
                                       2
(%i4) float(sec(%pi/3)+csc(%pi/3));
(%o4)                          3.154700538379252
(%i5) log(1);
(%o5)                                  0
(%i6) float(log(10));
(%o6)                          2.302585092994046
(%i7) log(%e);
(%o7)                                  1
(%i8) log(2^a);
(%o8)                              log(2) a
(%i9) %e^log(2);
(%o9)                                 2

变量操作
(%i1) a^2-b^2;
                                     2    2
(%o1)                               a  - b
(%i2) a:3;
(%o2)                                  3
(%i3) a^2-b^2;
                                         2
(%o3)                               9 - b
(%i4) b:2;
(%o4)                                  2
(%i5) a^2-b^2;
(%o5)                                  5
(%i6) kill(a);
(%o6)                                done
(%i7) kill(b);
(%o7)                                done
(%i8) a^2-b^2;
                                     2    2
(%o8)                      &nb
sp;        a  - b

函数操作
(%i1) f(x):=x^2-1;
                                         2
(%o1)                           f(x) := x  - 1
(%i2) f(2);
(%o2)                                  3
(%i3) f(100);
(%o3)                                9999
(%i4) float(f(2/3));
(%o4)                         - 0.55555555555556
(%i5) a:4/5;
                                       4
(%o5)                                  -
                                       5
(%i6) f(a);
                                       9
(%o6)                                - --
                                       25

多项式运算(展开、合并、化简和消元)
(%i1) expand((a+b)^3);
                            3        2      2      3
(%o1)                      b  + 3 a b  + 3 a  b + a
(%i2) factor(a^2-b^2);
(%o2)                          - (b - a) (b + a)
(%i3) ratsimp((x^2-1)/(x+1));
(%o3)                                x - 1
(%i4) eliminate([x^2+x*y+z=0,3*x+5*y+z=0,x-y-2*z^2=1],[y,z]);
                             4      3       2
(%o4)               [- x (8 x  - 2 x  + 19 x  - 50 x + 25)]

解方程
(%i1) solve(x^2-3*x+4/x=5,x);
                         sqrt(5) + 1      sqrt(5) - 1
(%o1)             [x = - -----------, x = -----------, x = 4]
                              2                2
(%i2) funcsolve(f(n)*(n+1)+2*n=1-f(n)/n,f(n));
                                      n (2 n - 1)
(%o2)                        f(n) = - -----------
                                       2
                                      n  + n + 1
(%i3) solve([x+3*y=10,1/x+x*y=4],[x,y]);
                              sqrt(69) - 9      4 sqrt(3) sqrt(23) - 34
(%o3) [[x = 1, y = 3], [x = - ------------, y = -----------------------],
                                   2            9 sqrt(3) sqrt(23) - 75
                                    sqrt(69) + 9      4 sqrt(3) sqrt(23) + 34
                               [x = ------------, y = -----------------------]]
                                         2            9 sqrt(3) sqrt(23) + 75
(%i4) solve(x^2+b*x+c=0,x);
                           2                       2
                     sqrt(b  - 4 c) + b      sqrt(b  - 4 c) - b
(%o4)         [x = - ------------------, x = ------------------]
                      &nbs
p;      2                       2
(%i5) find_root(x^x=2,x,1,2);
(%o5)                          1.559610469462369
(%i6) find_root(sin(x)=x/2,x,0.1,%pi);
(%o6)                          1.895494267033981

数论相关
(%i1) mod(100,7);
(%o1)                                  2
(%i2) primep(3214567);
(%o2)                                true
(%i3) next_prime(200);
(%o3)                                 211
(%i4) factor(1001);
(%o4)                               7 11 13
(%i5) factor(30!);
                        26  14  7  4   2   2
(%o5)                  2   3   5  7  11  13  17 19 23 29
(%i6) gcd(200,780);
(%o6)                                 20
(%i7) binomial(7,4);
(%o7)                                 35
(%i8) fib(7);
(%o8)                                 13

画函数图像
(%i1) plot2d(x^3+2*x^2-3,[x,-2,2]);
*** X11 output driver not found, switching to dumb terminal!
*** If you want to use the X11 output, please install the gnuplot-x11 package

  14 ++-------+--------+--------+--------+-------+--------+--------+-------++
     +        +        +        +        +       +       x^3+2*x^2-3 $$$$$$ $
  12 ++                                                                    $+
     |                                                                    $ |
  10 ++                                                                  $ ++
     |                                                                  $   |
     |                                                                  $   |
   8 ++                                                                $   ++
     |                                                                $     |
   6 ++                                                             $$     ++
     |                                                             $$       |
   4 ++                                                          $$        ++
     |                                                          $$          |
   2 ++   
                                                     $$          ++
     |                                                      $$$             |
     |                                                     $$               |
   0 ++                                                 $$$                ++
     |                                               $$$$                   |
  -2 ++$$$$$$$$$$$$$$$$$$$$$$$$$$               $$$$$                      ++
     $$       +        +        $$$$$$$$$$$$$$$$ +        +        +        +
  -4 ++-------+--------+--------+--------+-------+--------+--------+-------++
    -2      -1.5      -1      -0.5       0      0.5       1       1.5       2

(%o1)

你可以通过安装gnuplot-x11让maxima在X上画图,安装方法是:
sudo apt-get install gnuplot-x11
maxima也可以画3D图像,比如执行下面代码可以画出sin(x)cos(y)的图像,我就不贴图了,大家自己试试。
plot3d(sin(x)*cos(y),[x,-2,2],[y,-2,2]);

做人要厚道
转贴请注明出处