/usr/share/doc/maxima-doc/html/intromax.html is in maxima-doc 5.27.0-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<meta name="GENERATOR" content="TtH 3.85">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css"> div.p { margin-top: 7pt;}</style>
<style type="text/css"><!--
td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
td div.norm {line-height:normal;}
pre
{
border: 1px solid gray;
padding-top: 1em;
padding-bottom: 1em;
padding-left: 1em;
padding-right: 1em;
background-color: #F1F5F9; /* light blue-gray */
}
span.roman {font-family: serif; font-style: normal; font-weight: normal;}
span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
span.overacc1 {position: relative; left: .6em; top: -1.2ex;} --></style>
<title> Introduction to Maxima</title>
<h1 align="center">Introduction to Maxima </h1>
<h3 align="center">Richard H. Rand<br />
Dept. of Theoretical and Applied Mechanics, Cornell University
<a href="#tthFtNtAAB" name="tthFrefAAB"><sup>1</sup></a> </h3>
<h3 align="center"> </h3>
<div class="p"><!----></div>
Copyright (c) 1988-2010 Richard H. Rand.
<div class="p"><!----></div>
This document is free; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation. See the GNU General Public License for more
details at http://www.gnu.org/copyleft/gpl.html
<div class="p"><!----></div>
<h1>Contents </h1><a href="#tth_sEc1"
>1 Introduction </a><br />
<a href="#tth_sEc2"
>2 Special keys and symbols </a><br />
<a href="#tth_sEc3"
>3 Arithmetic </a><br />
<a href="#tth_sEc4"
>4 Algebra </a><br />
<a href="#tth_sEc5"
>5 Calculus </a><br />
<a href="#tth_sEc6"
>6 Matrix calculations </a><br />
<a href="#tth_sEc7"
>7 Programming in Maxima </a><br />
<a href="#tth_sEc8"
>8 A partial list of Maxima functions</a><br />
<div class="p"><!----></div>
<h2><a name="tth_sEc1">
1</a> Introduction <a name="sec:introduction">
</a></h2>
<div class="p"><!----></div>
To invoke Maxima in a console, type
<pre>
maxima <enter>
</pre>
<div class="p"><!----></div>
The computer will display a greeting of the sort:
<pre>
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)
</pre>
<div class="p"><!----></div>
The <tt>(%i1)</tt> is a "label". Each input or output line is
labelled and can be referred to by its own label for the rest of the
session. <tt>i</tt> labels denote your commands and <tt>o</tt> labels
denote displays of the machine's response. <em>Never use variable
names like <tt>%i1</tt> or <tt>%o5</tt>, as these will be confused with
the lines so labeled</em>.
<div class="p"><!----></div>
Maxima distinguishes lower and upper case. All built-in functions
have names which are lowercase only (<tt>sin</tt>, <tt>cos</tt>, <tt>save</tt>,
<tt>load</tt>, etc). Built-in constants have lowercase names (<tt>%e</tt>,
<tt>%pi</tt>, <tt>inf</tt>, etc). If you type <tt>SIN(x)</tt> or <tt>
Sin(x)</tt>, Maxima assumes you mean something other than the built-in
<tt>sin</tt> function. User-defined functions and variables can have
names which are lower or upper case or both. <tt>foo(XY)</tt>, <tt>
Foo(Xy)</tt>, <tt>FOO(xy)</tt> are all different.
<div class="p"><!----></div>
<h2><a name="tth_sEc2">
2</a> Special keys and symbols <a name="sec:keys">
</a></h2>
<div class="p"><!----></div>
<ol type="1">
<li> To end a Maxima session, type <tt>quit();</tt>.
<div class="p"><!----></div>
</li>
<li> To abort a computation without leaving Maxima, type <tt>^C</tt>.
(Here <tt>^</tt> stands for the control key, so
that <tt>^C</tt> means first press the key marked control and hold it down while pressing the C key.)
It is important for you to
know how to do this in case, for example, you begin a computation which is taking too long.
For example:
<pre>
(%i1) sum (1/x^2, x, 1, 100000)$
^C
Maxima encountered a Lisp error:
Interactive interrupt at #x7FFFF74A43C3.
Automatically continuing.
To enable the Lisp debugger set *debugger-hook* to nil.
(%i2)
</pre>
<div class="p"><!----></div>
</li>
<li> In order to tell Maxima that you have finished your command, use
the semicolon (<tt>;</tt>), followed by a return. Note that the return
key alone does not signal that you are done with your input.
<div class="p"><!----></div>
</li>
<li> An alternative input terminator to the semicolon (<tt>;</tt>) is
the dollar sign (<tt>$</tt>), which, however, supresses the display of
Maxima's computation. This is useful if you are computing some long
intermediate result, and you don't want to waste time having it
displayed on the screen.
<div class="p"><!----></div>
</li>
<li> If you wish to repeat a command which you have already given,
say on line <tt>(%i5)</tt>, you may do so without typing it over again
by preceding its label with two single quotes (<tt>"</tt>), i.e., <tt>
"%i5</tt>. (Note that simply inputing <tt>%i5</tt> will not do the job
- try it.)
<div class="p"><!----></div>
</li>
<li> If you want to refer to the immediately preceding result
computed by Maxima, you can either use its <tt>o</tt> label, or you can
use the special symbol percent (<tt>%</tt>).
<div class="p"><!----></div>
</li>
<li> The standard quantities e (natural log base), i (square root
of <font face="symbol">-</font
>1) and <font face="symbol">p</font
> (3.14159<font face="symbol">¼</font
>) are respectively referred to as
<tt>%e</tt>, <tt>%i</tt>,
and <tt>%pi</tt>. Note that the use of <tt>%</tt> here as a prefix
is completely unrelated to the use of <tt>%</tt> to refer to the
preceding result computed.
<div class="p"><!----></div>
</li>
<li> In order to assign a value to a variable, Maxima uses the colon
(<tt>:</tt>), not the equal sign. The equal sign is used for
representing equations.
<div class="p"><!----></div>
</li>
</ol>
<div class="p"><!----></div>
<h2><a name="tth_sEc3">
3</a> Arithmetic <a name="sec:arithmetic">
</a></h2>
<div class="p"><!----></div>
The common arithmetic operations are
<dl compact="compact">
<dt><b><tt>+</tt></b></dt>
<dd> addition</dd>
<dt><b><tt>-</tt></b></dt>
<dd> subtraction</dd>
<dt><b><tt>*</tt></b></dt>
<dd> scalar multiplication</dd>
<dt><b><tt>/</tt></b></dt>
<dd> division</dd>
<dt><b><tt>^</tt></b></dt>
<dd> or <tt>**</tt> exponentiation</dd>
<dt><b><tt>.</tt></b></dt>
<dd> matrix multiplication</dd>
<dt><b><tt>sqrt(x)</tt></b></dt>
<dd> square root of <tt>x</tt>.</dd>
</dl>
Maxima's output is characterized by exact (rational) arithmetic. For example,
<pre>
(%i1) 1/100 + 1/101;
201
(%o1) -----
10100
</pre>
If irrational numbers are involved in a computation, they are kept in symbolic form:
<pre>
(%i2) (1 + sqrt(2))^5;
5
(%o2) (sqrt(2) + 1)
(%i3) expand (%);
7/2
(%o3) 3 2 + 5 sqrt(2) + 41
</pre>
However, it is often useful to express a result in decimal notation.
This may be accomplished by following the expression you want expanded
by "<tt>,numer</tt>":
<pre>
(%i4) %, numer;
(%o4) 82.01219330881977
</pre>
Note the use here of <tt>%</tt>
to refer to the previous result. In this version of Maxima, <tt>
numer</tt> gives 16 significant figures, of which the last is often
unreliable. However, Maxima can offer <em>arbitrarily high
precision</em> by using the <tt>bfloat</tt> function:
<pre>
(%i5) bfloat (%o3);
(%o5) 8.201219330881976b1
</pre>
The number of significant figures displayed is controlled by the
Maxima variable <tt>fpprec</tt>, which has the default value of 16:
<pre>
(%i6) fpprec;
(%o6) 16
</pre>
Here we reset <tt>fpprec</tt> to yield 100 digits:
<pre>
(%i7) fpprec: 100;
(%o7) 100
(%i8) ''%i5;
(%o8) 8.20121933088197564152489730020812442785204843859314941221\
2371240173124187540110412666123849550160561b1
</pre>
Note the use of two single quotes (<tt>"</tt>) in <tt>(%i8)</tt> to repeat
command <tt>(%i5)</tt>. Maxima can handle very large numbers without
approximation:
<pre>
(%i9) 100!;
(%o9) 9332621544394415268169923885626670049071596826438162146859\
2963895217599993229915608941463976156518286253697920827223758251\
185210916864000000000000000000000000
</pre>
<div class="p"><!----></div>
<h2><a name="tth_sEc4">
4</a> Algebra <a name="sec:algebra">
</a></h2>
<div class="p"><!----></div>
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:
<pre>
(%i1) (x + 3*y + x^2*y)^3;
2 3
(%o1) (x y + 3 y + x)
(%i2) expand (%);
6 3 4 3 2 3 3 5 2 3 2
(%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
</pre>
Now suppose we wanted to substitute <tt>5/z</tt> for <tt>x</tt> in the above
expression:
<div class="p"><!----></div>
<table border="0"><tr><td></td><td><table border="0"><tr><td></td><td width="1000">
<pre>
(%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
</pre>
</td></tr></table><!--vbox-->
</td><td></td></tr></table><!--hboxt-->The Maxima function <tt>ratsimp</tt> will place this over a common denominator:
<pre>
(%i4) ratsimp (%);
3 6 2 5 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
</pre>
Expressions may also be <tt>factor</tt>ed:
<pre>
(%i5) factor (%);
2 3
(3 y z + 5 z + 25 y)
(%o5) ----------------------
6
z
</pre>
Maxima can obtain exact solutions to systems of nonlinear algebraic
equations. In this example we <tt>solve</tt> three equations in the
three unknowns <tt>a</tt>, <tt>b</tt>, <tt>c</tt>:
<pre>
(%i6) a + b*c = 1;
(%o6) b c + a = 1
(%i7) b - a*c = 0;
(%o7) b - a c = 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
</pre>
Note that the display consists of a "list", i.e., some expression
contained between two brackets <tt>[ ... ]</tt>, which itself contains
two lists. Each of the latter contain a distinct solution to the
simultaneous equations.
<div class="p"><!----></div>
Trigonometric identities are easy to manipulate in Maxima. The
function <tt>trigexpand</tt> uses the sum-of-angles formulas to make the
argument inside each trig function as simple as possible:
<pre>
(%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))
</pre>
The function <tt>trigreduce</tt>, on the other hand, converts an
expression into a form which is a sum of terms, each of which contains
only a single <tt>sin</tt> or <tt>cos</tt>:
<pre>
(%i12) trigreduce (%o10);
sin(v + 4 u) + sin(v - 2 u) 3 sin(v + 2 u) + 3 sin(v)
(%o12) --------------------------- + -------------------------
8 8
</pre>
The functions <tt>realpart</tt> and <tt>imagpart</tt> will return the real
and imaginary parts of a complex expression:
<pre>
(%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)
</pre>
<div class="p"><!----></div>
<h2><a name="tth_sEc5">
5</a> Calculus <a name="sec:calculus">
</a></h2>
<div class="p"><!----></div>
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 <tt>f</tt> to be the
following function of <tt>x</tt>:
<pre>
(%i1) f: x^3 * %e^(k*x) * sin(w*x);
3 k x
(%o1) x %e sin(w x)
</pre>
We compute the derivative of <tt>f</tt> with respect to <tt>x</tt>:
<pre>
(%i2) diff (f, x);
3 k x 2 k x
(%o2) k x %e sin(w x) + 3 x %e sin(w x)
3 k x
+ w x %e cos(w x)
</pre>
Now we find the indefinite integral of <tt>f</tt> with respect to <tt>x</tt>:
<pre>
(%i3) integrate (f, x);
6 3 4 5 2 7 3
(%o3) (((k w + 3 k w + 3 k w + k ) x
6 2 4 4 2 6 2
+ (3 w + 3 k w - 3 k w - 3 k ) x
4 3 2 5 4 2 2 4
+ (- 18 k w - 12 k w + 6 k ) x - 6 w + 36 k w - 6 k )
k x 7 2 5 4 3 6 3
%e sin(w x) + ((- w - 3 k w - 3 k w - k w) x
5 3 3 5 2
+ (6 k w + 12 k w + 6 k w) x
5 2 3 4 3 3 k x
+ (6 w - 12 k w - 18 k w) x - 24 k w + 24 k w) %e
8 2 6 4 4 6 2 8
cos(w x))/(w + 4 k w + 6 k w + 4 k w + k )
</pre>
A slight change in syntax gives definite integrals:
<pre>
(%i4) integrate (1/x^2, x, 1, inf);
(%o4) 1
(%i5) integrate (1/x, x, 0, inf);
defint: integral is divergent.
-- an error. To debug this try: debugmode(true);
</pre>
Next we define the simbol <tt>g</tt> in terms of <tt>f</tt> (previously
defined in <tt>%i1</tt>) and the hyperbolic sine function, and find its
Taylor series expansion (up to, say, order 3 terms) about the point
<tt>x = 0</tt>:
<div class="p"><!----></div>
<table border="0"><tr><td></td><td><table border="0"><tr><td></td><td width="1000">
<pre>
(%i6) g: f / sinh(k*x)^4;
3 k x
x %e sin(w x)
(%o6) -----------------
4
sinh (k x)
(%i7) taylor (g, x, 0, 3);
2 3 2 2 3 3
w w x (w k + w ) x (3 w k + w ) x
(%o7)/T/ -- + --- - -------------- - ---------------- + . . .
4 3 4 3
k k 6 k 6 k
</pre>
</td></tr></table><!--vbox-->
</td><td></td></tr></table><!--hboxt-->The limit of <tt>g</tt> as <tt>x</tt> goes to 0 is computed as follows:
<pre>
(%i8) limit (g, x, 0);
w
(%o8) --
4
k
</pre>
Maxima also permits derivatives to be represented in unevaluated form
(note the quote):
<pre>
(%i9) 'diff (y, x);
dy
(%o9) --
dx
</pre>
The quote operator in <tt>(%i9)</tt> means "do not evaluate". Without
it, Maxima would have obtained 0:
<pre>
(%i10) diff (y, x);
(%o10) 0
</pre>
Using the quote operator we can write differential equations:
<pre>
(%i11) 'diff (y, x, 2) + 'diff (y, x) + y;
2
d y dy
(%o11) --- + -- + y
2 dx
dx
</pre>
Maxima's <tt>ode2</tt> function can solve first and second order ODE's:
<pre>
(%i12) ode2 (%o11, y, x);
- x/2 sqrt(3) x sqrt(3) x
(%o12) y = %e (%k1 sin(---------) + %k2 cos(---------))
2 2
</pre>
<div class="p"><!----></div>
<h2><a name="tth_sEc6">
6</a> Matrix calculations <a name="sec:matrix">
</a></h2>
<div class="p"><!----></div>
Maxima can compute the determinant, inverse and eigenvalues and
eigenvectors of matrices which have symbolic elements (i.e., elements
which involve algebraic variables.) We begin by entering a matrix <tt>
m</tt> element by element:
<pre>
(%i1) m: entermatrix (3, 3);
Is the matrix 1. Diagonal 2. Symmetric 3. Antisymmetric 4. General
Answer 1, 2, 3 or 4 :
4;
Row 1 Column 1:
0;
Row 1 Column 2:
1;
Row 1 Column 3:
a;
Row 2 Column 1:
1;
Row 2 Column 2:
0;
Row 2 Column 3:
1;
Row 3 Column 1:
1;
Row 3 Column 2:
1;
Row 3 Column 3:
0;
Matrix entered.
[ 0 1 a ]
[ ]
(%o1) [ 1 0 1 ]
[ ]
[ 1 1 0 ]
</pre>
Next we find its transpose, determinant and inverse:
<pre>
(%i2) transpose (m);
[ 0 1 1 ]
[ ]
(%o2) [ 1 0 1 ]
[ ]
[ a 1 0 ]
(%i3) determinant (m);
(%o3) a + 1
(%i4) invert (m), detout;
[ - 1 a 1 ]
[ ]
[ 1 - a a ]
[ ]
[ 1 1 - 1 ]
(%o4) -----------------
a + 1
</pre>
In <tt>(%i4)</tt>, the modifier <tt>detout</tt> keeps the determinant
outside the inverse. As a check, we multiply <tt>m</tt> by its inverse
(note the use of the period to represent matrix multiplication):
<pre>
(%i5) m . %o4;
[ - 1 a 1 ]
[ ]
[ 1 - a a ]
[ 0 1 a ] [ ]
[ ] [ 1 1 - 1 ]
(%o5) [ 1 0 1 ] . -----------------
[ ] a + 1
[ 1 1 0 ]
(%i6) expand (%);
[ a 1 ]
[ ----- + ----- 0 0 ]
[ a + 1 a + 1 ]
[ ]
[ a 1 ]
(%o6) [ 0 ----- + ----- 0 ]
[ a + 1 a + 1 ]
[ ]
[ a 1 ]
[ 0 0 ----- + ----- ]
[ a + 1 a + 1 ]
(%i7) factor (%);
[ 1 0 0 ]
[ ]
(%o7) [ 0 1 0 ]
[ ]
[ 0 0 1 ]
</pre>
In order to find the eigenvalues and eigenvectors of <tt>m</tt>, we use the function <tt>
eigenvectors</tt>:
<div class="p"><!----></div>
<table border="0"><tr><td></td><td><table border="0"><tr><td></td><td width="1000">
<pre>
(%i8) eigenvectors (m);
sqrt(4 a + 5) - 1 sqrt(4 a + 5) + 1
(%o8) [[[- -----------------, -----------------, - 1],
2 2
sqrt(4 a + 5) - 1 sqrt(4 a + 5) - 1
[1, 1, 1]], [[[1, - -----------------, - -----------------]],
2 a + 2 2 a + 2
sqrt(4 a + 5) + 1 sqrt(4 a + 5) + 1
[[1, -----------------, -----------------]], [[1, - 1, 0]]]]
2 a + 2 2 a + 2
</pre>
In <tt>%o8</tt>, the first triple gives the eigenvalues of <tt>m</tt> and
the next gives their respective multiplicities (here each is
unrepeated). The next three triples give the corresponding
eigenvectors of <tt>m</tt>. In order to extract from this expression
one of these eigenvectors, we may use the <tt>part</tt> function:
<pre>
(%i9) part (%o23, 2, 1, 1);
sqrt(4 a + 5) - 1 sqrt(4 a + 5) - 1
(%o9) [1, - -----------------, - -----------------]
2 a + 2 2 a + 2
</pre>
</td></tr></table><!--vbox-->
</td><td></td></tr></table><!--hboxt--> <h2><a name="tth_sEc7">
7</a> Programming in Maxima <a name="sec:programming">
</a></h2>
<div class="p"><!----></div>
So far, we have used Maxima in the interactive mode, rather like a
calculator. However, for computations which involve a repetitive
sequence of commands, it is better to execute a program. Here we
present a short sample program to calculate the critical points of a
function <tt>f</tt> of two variables <tt>x</tt> and <tt>y</tt>. The program
cues the user to enter the function <tt>f</tt>, then it computes the
partial derivatives <tt>f</tt><sub><tt>x</tt></sub> and <tt>f</tt><sub><tt>y</tt></sub>, and then it
uses the Maxima command <tt>solve</tt> to obtain solutions to
<tt>f</tt><sub><tt>x</tt></sub><tt> = </tt><tt>f</tt><sub><tt>y</tt></sub><tt> = </tt><tt>0</tt>. The program is written outside of Maxima
with a text editor, and then loaded into Maxima with the <tt>batch</tt>
command. Here is the program listing:
<pre>
/* --------------------------------------------------------------------------
this is file critpts.max:
as you can see, comments in maxima are like comments in C
Nelson Luis Dias, nldias@simepar.br
created 20000707
updated 20000707
--------------------------------------------------------------------------- */
critpts():=(
print("program to find critical points"),
/* ---------------------------------------------------------------------------
asks for a function
--------------------------------------------------------------------------- */
f:read("enter f(x,y)"),
/* ---------------------------------------------------------------------------
echoes it, to make sure
--------------------------------------------------------------------------- */
print("f = ",f),
/* ---------------------------------------------------------------------------
produces a list with the two partial derivatives of f
--------------------------------------------------------------------------- */
eqs:[diff(f,x),diff(f,y)],
/* ---------------------------------------------------------------------------
produces a list of unknowns
--------------------------------------------------------------------------- */
unk:[x,y],
/* ---------------------------------------------------------------------------
solves the system
--------------------------------------------------------------------------- */
solve(eqs,unk)
)$
</pre>
The program (which is actually a function with no argument) is called
<tt>critpts</tt>. Each line is a valid Maxima command which could be
executed from the keyboard, and which is separated by the next command
by a comma. The partial derivatives are stored in a variable named
<tt>eqs</tt>, and the unknowns are stored in <tt>unk</tt>. Here is a sample
run:
<pre>
(%i1) batch ("critpts.max");
batching #p/home/robert/tmp/maxima-clean/maxima/critpts.max
(%i2) critpts() := (print("program to find critical points"),
f : read("enter f(x,y)"), print("f = ", f),
eqs : [diff(f, x), diff(f, y)], unk : [x, y], solve(eqs, unk))
(%i3) critpts ();
program to find critical points
enter f(x,y)
%e^(x^3 + y^2)*(x + y);
2 3
y + x
f = (y + x) %e
(%o3) [[x = .4588955685487001 %i + .3589790871086935,
y = .4942017368275118 %i - .1225787367783657],
[x = .3589790871086935 - .4588955685487001 %i,
y = - .4942017368275118 %i - .1225787367783657],
[x = .4187542327234816 %i - .6923124204420268,
y = 0.455912070111699 - .8697262692814121 %i],
[x = - .4187542327234816 %i - .6923124204420268,
y = .8697262692814121 %i + 0.455912070111699]]
</pre>
<div class="p"><!----></div>
<h2><a name="tth_sEc8">
8</a> A partial list of Maxima functions</h2>
<div class="p"><!----></div>
See the Maxima reference manual <tt>doc/html/maxima_toc.html</tt> (under
the main Maxima installation directory). From Maxima itself, you can
use <tt>describe(<i>function name</i>)</tt>.
<div class="p"><!----></div>
<dl compact="compact">
<dt><b><tt>allroots(a)</tt></b></dt>
<dd> Finds all the (generally complex) roots of
the polynomial equation <tt>A</tt>, and lists them in <tt>numer</tt>ical
format (i.e. to 16 significant figures).</dd>
<dt><b><tt>append(a,b)</tt></b></dt>
<dd> Appends the list <tt>b</tt> to the list <tt>a</tt>,
resulting in a single list.</dd>
<dt><b><tt>batch(a)</tt></b></dt>
<dd> Loads and runs a program with filename <tt>a</tt>.</dd>
<dt><b><tt>coeff(a,b,c)</tt></b></dt>
<dd> Gives the coefficient of <tt>b</tt> raised to
the power <tt>c</tt> in expression <tt>a</tt>.</dd>
<dt><b><tt>concat(a,b)</tt></b></dt>
<dd> Creates the symbol <tt>ab</tt>.</dd>
<dt><b><tt>cons(a,b)</tt></b></dt>
<dd> Adds <tt>a</tt> to the list <tt>b</tt> as its first element.</dd>
<dt><b><tt>demoivre(a)</tt></b></dt>
<dd> Transforms all complex exponentials in <tt>
a</tt> to their trigonometric equivalents.</dd>
<dt><b><tt>denom(a)</tt></b></dt>
<dd> Gives the denominator of <tt>a</tt>.</dd>
<dt><b><tt>depends(a,b)</tt></b></dt>
<dd> Declares <tt>a</tt> to be a function of <tt>
b</tt>. This is useful for writing unevaluated derivatives, as in
specifying differential equations.</dd>
<dt><b><tt>desolve(a,b)</tt></b></dt>
<dd> Attempts to solve a linear system <tt>a</tt> of
ODE's for unknowns <tt>b</tt> using Laplace transforms.</dd>
<dt><b><tt>determinant(a)</tt></b></dt>
<dd> Returns the determinant of the square
matrix <tt>a</tt>.</dd>
<dt><b><tt>diff(a,b1,c1,b2,c2,...,bn,cn)</tt></b></dt>
<dd> Gives the mixed partial
derivative of <tt>a</tt> with respect to each <tt>bi</tt>, <tt>ci</tt> times.
For brevity, <tt>diff(a,b,1)</tt> may be represented by <tt>
diff(a,b)</tt>. <tt>'diff(...)</tt> represents the unevaluated
derivative, useful in specifying a differential equation.</dd>
<dt><b><tt>eigenvalues(a)</tt></b></dt>
<dd> Returns two lists, the first being the
eigenvalues of the square matrix <tt>a</tt>, and the second being their
respective multiplicities.</dd>
<dt><b><tt>eigenvectors(a)</tt></b></dt>
<dd> Does everything that <tt>eigenvalues</tt>
does, and adds a list of the eigenvectors of <tt>a</tt>.</dd>
<dt><b><tt>entermatrix(a,b)</tt></b></dt>
<dd> Cues the user to enter an <tt>a</tt> × <tt>b</tt> matrix, element by element.</dd>
<dt><b><tt>ev(a,b1,b2,...,bn)</tt></b></dt>
<dd> Evaluates <tt>a</tt> subject to the
conditions <tt>bi</tt>. In particular the <tt>bi</tt> may be equations,
lists of equations (such as that returned by <tt>solve</tt>), or
assignments, in which cases <tt>ev</tt> "plugs" the <tt>bi</tt> into
<tt>a</tt>. The <tt>Bi</tt> may also be words such as <tt>numer</tt> (in
which case the result is returned in numerical format), <tt>detout</tt>
(in which case any matrix inverses in <tt>a</tt> are performed with the
determinant factored out), or <tt>diff</tt> (in which case all
differentiations in <tt>a</tt> are evaluated, i.e., <tt>'diff</tt> in <tt>
a</tt> is replaced by <tt>diff</tt>). For brevity in a manual command
(i.e., not inside a user-defined function), the <tt>ev</tt> may be
dropped, shortening the syntax to <tt>a,b1,b2,...,bn</tt>.</dd>
<dt><b><tt>expand(a)</tt></b></dt>
<dd> Algebraically expands <tt>a</tt>. In particular
multiplication is distributed over addition.</dd>
<dt><b><tt>exponentialize(a)</tt></b></dt>
<dd> Transforms all trigonometric functions
in <tt>a</tt> to their complex exponential equivalents.</dd>
<dt><b><tt>factor(a)</tt></b></dt>
<dd> Factors <tt>a</tt>.</dd>
<dt><b><tt>freeof(a,b)</tt></b></dt>
<dd> Is true if the variable <tt>a</tt> is not part
of the expression <tt>b</tt>.</dd>
<dt><b><tt>grind(a)</tt></b></dt>
<dd> Displays a variable or function <tt>a</tt> in a
compact format. When used with <tt>writefile</tt> and an editor
outside of Maxima, it offers a scheme for producing <tt>batch</tt>
files which include Maxima-generated expressions.</dd>
<dt><b><tt>ident(a)</tt></b></dt>
<dd> Returns an <tt>a</tt> × <tt>a</tt>
identity matrix.</dd>
<dt><b><tt>imagpart(a)</tt></b></dt>
<dd> Returns the imaginary part of <tt>a</tt>.</dd>
<dt><b><tt>integrate(a,b)</tt></b></dt>
<dd> Attempts to find the indefinite integral
of <tt>a</tt> with respect to <tt>b</tt>.</dd>
<dt><b><tt>integrate(a,b,c,d)</tt></b></dt>
<dd> Attempts to find the indefinite
integral of <tt>a</tt> with respect to <tt>b</tt>. taken from
<tt>b</tt><tt>=</tt><tt>c</tt> to <tt>b</tt><tt>=</tt><tt>d</tt>. The limits of integration <tt>c</tt>
and <tt>d</tt> may be taken is <tt>inf</tt> (positive infinity) of <tt>
minf</tt> (negative infinity).</dd>
<dt><b><tt>invert(a)</tt></b></dt>
<dd> Computes the inverse of the square matrix <tt>
a</tt>.</dd>
<dt><b><tt>kill(a)</tt></b></dt>
<dd> Removes the variable <tt>a</tt> with all its
assignments and properties from the current Maxima environment.</dd>
<dt><b><tt>limit(a,b,c)</tt></b></dt>
<dd> Gives the limit of expression <tt>a</tt> as
variable <tt>b</tt> approaches the value <tt>c</tt>. The latter may be
taken as <tt>inf</tt> of <tt>minf</tt> as in <tt>integrate</tt>.</dd>
<dt><b><tt>lhs(a)</tt></b></dt>
<dd> Gives the left-hand side of the equation <tt>a</tt>.</dd>
<dt><b><tt>loadfile(a)</tt></b></dt>
<dd> Loads a disk file with filename <tt>a</tt> from
the current default directory. The disk file must be in the proper
format (i.e. created by a <tt>save</tt> command).</dd>
<dt><b><tt>makelist(a,b,c,d)</tt></b></dt>
<dd> Creates a list of <tt>a</tt>'s (each of
which presumably depends on <tt>b</tt>), concatenated from
<tt>b</tt><tt>=</tt><tt>c</tt> to <tt>b</tt><tt>=</tt><tt>d</tt></dd>
<dt><b><tt>map(a,b)</tt></b></dt>
<dd> Maps the function <tt>a</tt> onto the
subexpressions of <tt>b</tt>.</dd>
<dt><b><tt>matrix(a1,a2,...,an)</tt></b></dt>
<dd> Creates a matrix consisting of the rows <tt>ai</tt>, where each
row <tt>ai</tt> is a list of <tt>m</tt> elements, <tt>[b1, b2, ..., bm]</tt>.</dd>
<dt><b><tt>num(a)</tt></b></dt>
<dd> Gives the numerator of <tt>a</tt>.</dd>
<dt><b><tt>ode2(a,b,c)</tt></b></dt>
<dd> Attempts to solve the first- or second-order
ordinary differential equation <tt>a</tt> for <tt>b</tt> as a function of
<tt>c</tt>.</dd>
<dt><b><tt>part(a,b1,b2,...,bn)</tt></b></dt>
<dd> First takes the <tt>b1</tt>th part
of <tt>a</tt>, then the <tt>b2</tt>th part of that, and so on.</dd>
<dt><b><tt>playback(a)</tt></b></dt>
<dd> Displays the last <tt>a</tt> (an integer)
labels and their associated expressions. If <tt>a</tt> is omitted,
all lines are played back. See the Manual for other options.</dd>
<dt><b><tt>ratsimp(a)</tt></b></dt>
<dd> Simplifies <tt>a</tt> and returns a quotient of
two polynomials.</dd>
<dt><b><tt>realpart(a)</tt></b></dt>
<dd> Returns the real part of <tt>a</tt>.</dd>
<dt><b><tt>rhs(a)</tt></b></dt>
<dd> Gives the right-hand side of the equation <tt>a</tt>.</dd>
<dt><b><tt>save(a,b1,b2,..., bn)</tt></b></dt>
<dd> Creates a disk file with
filename <tt>a</tt> in the current default directory, of variables,
functions, or arrays <tt>bi</tt>. The format of the file permits it to
be reloaded into Maxima using the <tt>loadfile</tt> command.
Everything (including labels) may be <tt>save</tt>d by taking <tt>b1</tt>
equal to <tt>all</tt>.</dd>
<dt><b><tt>solve(a,b)</tt></b></dt>
<dd> Attempts to solve the algebraic equation <tt>
a</tt> for the unknown <tt>b</tt>. A list of solution equations is
returned. For brevity, if <tt>a</tt> is an equation of the form
<tt>c</tt><tt> = </tt><tt>0</tt>, it may be abbreviated simply by the expression
<tt>c</tt>.</dd>
<dt><b><tt>string(a)</tt></b></dt>
<dd> Converts <tt>a</tt> to Maxima's linear notation
(similar to Fortran's) just as if it had been typed in and puts <tt>
a</tt> into the buffer for possible editing. The <tt>string</tt>'ed
expression should not be used in a computation.</dd>
<dt><b><tt>stringout(a,b1,b2,...,bn)</tt></b></dt>
<dd> Creates a disk file with
filename <tt>a</tt> in the current default directory, of variables
(e.g. labels) <tt>bi</tt>. The file is in a text format and is not
reloadable into Maxima. However the strungout expressions can be
incorporated into a Fortran, Basic or C program with a minimum of
editing.</dd>
<dt><b><tt>subst(a,b,c)</tt></b></dt>
<dd> Substitutes <tt>a</tt> for <tt>b</tt> in <tt>c</tt>.</dd>
<dt><b><tt>taylor(a,b,c,d)</tt></b></dt>
<dd> Expands <tt>a</tt> in a Taylor series in
<tt>b</tt> about <tt>b</tt><tt>=</tt><tt>c</tt>, up to and including the term
<tt>(</tt><tt>b</tt><font face="symbol">-</font
><tt>c</tt><tt>)</tt><sup><tt>d</tt></sup>. Maxima also supports Taylor expansions in more
than one independent variable; see the Manual for details.</dd>
<dt><b><tt>transpose(a)</tt></b></dt>
<dd> Gives the transpose of the matrix <tt>a</tt>.</dd>
<dt><b><tt>trigexpand(a)</tt></b></dt>
<dd> Is a trig simplification function which
uses the sum-of-angles formulas to simplify the arguments of
individual <tt>sin</tt>'s or <tt>cos</tt>'s. For example, <tt>
trigexpand(sin(x+y))</tt> gives <tt>cos(x) sin(y) + sin(x) cos(y)</tt>.</dd>
<dt><b><tt>trigreduce(a)</tt></b></dt>
<dd> Is a trig simplification function which
uses trig identities to convert products and powers of <tt>sin</tt> and
<tt>cos</tt> into a sum of terms, each of which contains only a single
<tt>sin</tt> or <tt>cos</tt>. For example, <tt>trigreduce(sin(x)^2)</tt>
gives <tt>(1 - cos(2x))/2</tt>.</dd>
<dt><b><tt>trigsimp(a)</tt></b></dt>
<dd> Is a trig simplification function which
replaces <tt>tan</tt>, <tt>sec</tt>, etc., by their <tt>sin</tt> and <tt>
cos</tt> equivalents. It also uses the identity <tt>sin</tt><tt>(</tt><tt>)</tt><sup><tt>2</tt></sup> <tt>+</tt> <tt>cos</tt><tt>(</tt><tt>)</tt><sup><tt>2</tt></sup><tt> = </tt><tt>1</tt>.</dd>
</dl>
<div class="p"><!----></div>
<hr /><h3>Footnotes:</h3>
<div class="p"><!----></div>
<a name="tthFtNtAAB"></a><a href="#tthFrefAAB"><sup>1</sup></a>Adapted from "Perturbation Methods, Bifurcation Theory and Computer Algebra"
by Rand and Armbruster, Springer, 1987.
Adapted to <span class="roman">L</span><sup><span class="roman">A</span></sup><span class="roman">T</span><sub><span class="roman">E</span></sub><span class="roman">X</span> and HTML by Nelson L. Dias (nldias@simepar.br),
SIMEPAR Technological Institute and Federal University of ParanĂ¡, Brazil.
Updated by Robert Dodier, August 2005.
<br /><br /><hr /><small>File translated from
T<sub><font size="-1">E</font></sub>X
by <a href="http://hutchinson.belmont.ma.us/tth/">
T<sub><font size="-1">T</font></sub>H</a>,
version 3.85.<br />On 26 Apr 2010, 00:45.</small>
</html>
|