File: intromax.ltx

package info (click to toggle)
maxima 5.10.0-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 44,268 kB
  • ctags: 17,987
  • sloc: lisp: 152,894; fortran: 14,667; perl: 14,204; tcl: 10,103; sh: 3,376; makefile: 2,202; ansic: 471; awk: 7
file content (741 lines) | stat: -rw-r--r-- 32,508 bytes parent folder | download | duplicates (3)
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
\setlength{\voffset}{-2.54cm}
\setlength{\hoffset}{-2.54cm}
\documentclass[a4paper,12pt]{article}
\setlength{\evensidemargin}{1.5cm}
\setlength{\oddsidemargin}{1.5cm}
% ------------------------------------------------------------
% distncias verticais ------------> 29.7
% -----------------------------------------------------------
\setlength{\topmargin}{2.0cm}   % -> 28.7
\setlength{\headheight}{0.50cm} % -> 28.2
\setlength{\headsep}{0.5cm}     % -> 27.7
\setlength{\textheight}{24.7cm} % -> 03.0
\setlength{\footskip}{1.0cm}    % -> 01.5
\setlength{\textwidth}{18cm}                                                                                   
\usepackage[latin1]{inputenc}




\title{Introduction to Maxima}
\author{Richard H. Rand\\ Dept. of Theoretical and Applied Mechanics, Cornell University
\thanks{Adapted from ``Perturbation Methods, Bifurcation Theory and Computer Algebra''
by Rand and Armbruster, Springer, 1987.
Adapted to \LaTeX\ and HTML by Nelson L. Dias (nldias@simepar.br), 
SIMEPAR Technological Institute and Federal University of Paran, Brazil.
Updated by Robert Dodier, August 2005.}}
\date{\empty}


\begin{document}
\maketitle

\tableofcontents

\section{Introduction \label{sec:introduction}}

To invoke Maxima in Linux, type
\begin{verbatim}
maxima <enter>
\end{verbatim}


The computer will display a greeting of the sort:
\begin{verbatim}
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)
\end{verbatim}

The {\tt (\%i1)} 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} labels denote your commands and {\tt o} labels
denote displays of the machine's response.  \emph{Never use variable names like {\tt \%i1} or {\tt
\%o5}, as these will be confused with the lines so labeled}.

Maxima distinguishes lower and upper case.
All built-in functions have names which are lowercase only
({\tt sin}, {\tt cos}, {\tt save}, {\tt load}, etc).
Built-in constants have lowercase names ({\tt \%e}, {\tt \%pi}, {\tt inf}, etc).
If you type {\tt SIN(x)} or {\tt Sin(x)},
Maxima assumes you mean something other than the built-in {\tt sin} function.
User-defined functions and variables can have names which are lower or upper case or both.
{\tt foo(XY)}, {\tt Foo(Xy)}, {\tt FOO(xy)} are all different.


\section{Special keys and symbols \label{sec:keys}}

\begin{enumerate}
\item To end a Maxima session, type {\tt quit();}.

\item To abort a computation without leaving Maxima, type \verb+^C+.
(Here \verb+^+ stands for the control key, so
that \verb+^C+ 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:
% sum (1/x^2, x, 1, 10000);
% ^C
\begin{verbatim}
(%i1) sum (1/x^2, x, 1, 10000);

Maxima encountered a Lisp error:

 Console interrupt.

Automatically continuing.
To reenable the Lisp debugger set *debugger-hook* to nil.
(%i2)
\end{verbatim}

\item In order to tell Maxima that you have finished your command, use the semicolon ({\tt ;}),
followed by a return.  Note that the return key alone does not signal that you are done with your
input.

\item An alternative input terminator to the semicolon ({\tt ;}) is the dollar sign ({\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.

%\item If you want to completely delete the current input line (and start this line fresh from the
%beginning), type a double question mark ({\tt ??}).

\item If you wish to repeat a command which you have already given, say on line {\tt (\%i5)}, you may
do so without typing it over again by preceding its label with two single quotes ({\tt ''}), i.e., {\tt
''\%i5}. (Note that simply inputing {\tt \%i5} will not do the job --- try it.)

\item If you want to refer to the immediately preceding result computed my Maxima, you can either
use its {\tt o} label, or you can use the special symbol percent   ({\tt \%}).

\item The standard quantities $e$ (natural log base), $i$ (square root of $-1$) and $\pi$
($3.14159\ldots$) are respectively referred to as \verb+%e+, \verb+%i+,
and \verb+%pi+.  Note that the use of {\tt \%} here as a prefix
is completely unrelated to the use of {\tt \%} to refer to the preceding result computed.

\item In order to assign a value to a variable, Maxima uses the colon ({\tt :}), not the equal
sign.  The equal sign is used for representing equations.
\end{enumerate}

\section{Arithmetic \label{sec:arithmetic}}

The common arithmetic operations are
\begin{description}
   \item [{\tt +}] addition
   \item [{\tt -}] subtraction
   \item [{\tt *}] scalar multiplication
   \item [{\tt /}] division
   \item [{\tt \^}]  or {\tt **} exponentiation
   \item [{\tt .}] matrix multiplication
   \item [{\tt sqrt(x)}] square root of {\tt x}.
\end{description}
Maxima's output is characterized by exact (rational) arithmetic.  E.g.,
% 1/100 + 1/101;
\begin{verbatim}
(%i1) 1/100 + 1/101;
                               201
(%o1)                         -----
                              10100
\end{verbatim}
If irrational numbers are involved in a computation, they are kept in symbolic form:
% (1 + sqrt(2))^5;
% expand (%);
\begin{verbatim}
(%i2) (1 + sqrt(2))^5;
                                      5
(%o2)                    (sqrt(2) + 1)
(%i3) expand (%);
(%o3)                    29 sqrt(2) + 41
\end{verbatim}
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}'':
% %, numer;
\begin{verbatim}
(%i4) %, numer;
(%o4)                   82.01219330881976
\end{verbatim}
Note the use here of \verb+%+ 
to refer to the previous result.  In this version of Maxima, {\tt numer} gives 16 significant
figures, of which the last is often unreliable.  However, Maxima can offer \emph{arbitrarily high
precision} by using the {\tt bfloat} function:
% bfloat (%o3);
\begin{verbatim}
(%i5) bfloat (%o3);
(%o5)                  8.201219330881976B1
\end{verbatim}
The number of significant figures displayed is controlled by the Maxima variable {\tt fpprec}, which
has the default value of 16:
% fpprec;
\begin{verbatim}
(%i6) fpprec;
(%o6)                          16
\end{verbatim}
Here we reset {\tt fpprec} to yield 100 digits:
% fpprec: 100;
% ''%i5;
\begin{verbatim}
(%i7) fpprec: 100;
(%o7)                          100
(%i8) ''%i5;
(%o8) 8.20121933088197564152489730020812442785204843859314941221#
2371240173124187540110412666123849550160561B1
\end{verbatim}
Note the use of two single quotes ({\tt ''}) in {\tt (\%i8)} to repeat command {\tt (\%i5)}.  Maxima can
handle very large numbers without approximation:
% 100!;
\begin{verbatim}
(%i9) 100!;
(%o9) 9332621544394415268169923885626670049071596826438162146859#
2963895217599993229915608941463976156518286253697920827223758251#
185210916864000000000000000000000000
\end{verbatim}

\section{Algebra \label{sec:algebra}}

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:
% (x + 3*y + x^2*y)^3;
% expand (%);
\begin{verbatim}
(%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
\end{verbatim}
Now suppose we wanted to substitute {\tt 5/z} for {\tt x} in the above expression:

\noindent\begin{minipage}{\textwidth}
% %o2, x=5/z;
\begin{verbatim}
(%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
\end{verbatim}
\end{minipage}
The Maxima function {\tt ratsimp} will place this over a common denominator:
% ratsimp (%);
\begin{verbatim}
(%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
\end{verbatim}
Expressions may also be {\tt factor}ed:
% factor (%);
\begin{verbatim}
(%i5) factor (%);
                           2              3
                     (3 y z  + 5 z + 25 y)
(%o5)                ----------------------
                                6
                               z
\end{verbatim}
Maxima can obtain exact solutions to systems of nonlinear algebraic equations.  In this example we
{\tt solve} three equations in the three unknowns {\tt a}, {\tt b}, {\tt c}:
% a + b*c = 1;
% b - a*c = 0;
% a + b = 5;
% solve ([%o6, %o7, %o8], [a, b, c]);
\begin{verbatim}
(%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
\end{verbatim}
Note that the display consists of a ``list'', i.e., some expression contained between two brackets
{\tt [ \ldots ]}, which itself contains two lists.  Each of the latter contain a distinct solution
to the simultaneous equations.

Trigonometric identities are easy to manipulate in Maxima.  The function {\tt trigexpand} uses the
sum-of-angles formulas to make the argument inside each trig function as simple as possible:
% sin(u + v) * cos(u)^3;
% trigexpand (%);
\begin{verbatim}
(%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))
\end{verbatim}
The function {\tt trigreduce}, 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} or {\tt cos}:
% trigreduce (%o10);
\begin{verbatim}
(%i12) trigreduce (%o10);
       sin(v + 4 u) + sin(v - 2 u)   3 sin(v + 2 u) + 3 sin(v)
(%o12) --------------------------- + -------------------------
                    8                            8
\end{verbatim}
The functions {\tt realpart} and {\tt imagpart} will return the real and imaginary parts of a
complex expression:
% w: 3 + k*%i;
% w^2 * %e^w;
% realpart (%);
\begin{verbatim}
(%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)
\end{verbatim}

\section{Calculus \label{sec:calculus}}

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} to be the
following function of {\tt x}:
% f: x^3 * %e^(k*x) * sin(w*x);
\begin{verbatim}
(%i1) f: x^3 * %e^(k*x) * sin(w*x);
                         3   k x
(%o1)                   x  %e    sin(w x)
\end{verbatim}
We compute the derivative of {\tt f} with respect to {\tt x}:
% diff (f, x);
\begin{verbatim}
(%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)
\end{verbatim}
Now we find the indefinite integral of {\tt f} with respect to {\tt x}:
% integrate (f, x);
\begin{verbatim}
(%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 )
\end{verbatim}
A slight change in syntax gives definite integrals:
% integrate (1/x^2, x, 1, inf);
% integrate (1/x, x, 0, inf);
\begin{verbatim}
(%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);
\end{verbatim}
Next we define the simbol {\tt g} in terms of {\tt f} (previously defined in {\tt \%i1}) and the
hyperbolic sine function, and find its Taylor series expansion (up to, say, order 3 terms) about the
point {\tt x = 0}:

\noindent\begin{minipage}{\textwidth}
% g: f / sinh(k*x)^4;
% taylor (g, x, 0, 3);
\begin{verbatim}
(%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
\end{verbatim}
\end{minipage}
The limit of {\tt g} as {\tt x} goes to 0 is computed as follows:
% limit (g, x, 0);
\begin{verbatim}
(%i8) limit (g, x, 0);
                               w
(%o8)                          --
                                4
                               k
\end{verbatim}
Maxima also permits derivatives to be represented in unevaluated form (note the quote):
% 'diff (y, x);
\begin{verbatim}
(%i9) 'diff (y, x);
                               dy
(%o9)                          --
                               dx
\end{verbatim}
The quote operator in {\tt (\%i9)} means ``do not evaluate''.  Without it, Maxima would have obtained
0:
% diff (y, x);
\begin{verbatim}
(%i10) diff (y, x);
(%o10)                          0
\end{verbatim}
Using the quote operator we can write differential equations:
% 'diff (y, x, 2) + 'diff (y, x) + y;
\begin{verbatim}
(%i11) 'diff (y, x, 2) + 'diff (y, x) + y;
                           2
                          d y   dy
(%o11)                    --- + -- + y
                            2   dx
                          dx
\end{verbatim}
Maxima's {\tt ode2} function can solve first and second order ODE's:
% ode2 (%o11, y, x);
\begin{verbatim}
(%i12) ode2 (%o11, y, x);
             - x/2          sqrt(3) x            sqrt(3) x
(%o12) y = %e      (%k1 sin(---------) + %k2 cos(---------))
                                2                    2
\end{verbatim}


\newpage
\section{Matrix calculations \label{sec:matrix}}

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} element by element:
% m: entermatrix (3, 3);
\begin{verbatim}
(%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 ]
\end{verbatim}
Next we find its transpose, determinant and inverse:
% transpose (m);
% determinant (m);
% invert (m), detout;
\begin{verbatim}
(%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
\end{verbatim}
In {\tt (\%i4)}, the modifier {\tt detout} keeps the determinant outside the inverse.  As a check, we
multiply {\tt m} by its inverse (note the use of the period to represent matrix multiplication):
% m . %o4;
% expand (%);
% factor (%);
\begin{verbatim}
(%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 ]
\end{verbatim}
In order to find the eigenvalues and eigenvectors of {\tt m}, we use the function {\tt
eigenvectors}:

\noindent\begin{minipage}{\textwidth}
% eigenvectors (m);
\begin{verbatim}
(%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
\end{verbatim}
In {\tt \%o8}, the first triple gives the eigenvalues of {\tt m} and the next gives their respective
multiplicities (here each is unrepeated).  The next three triples give the corresponding
eigenvectors of {\tt m}.  In order to extract from this expression one of these eigenvectors, we may
use the {\tt part} function:
% part (%, 2);
\begin{verbatim}
(%i9) part (%, 2);
                sqrt(4 a + 5) - 1    sqrt(4 a + 5) - 1
(%o9)     [1, - -----------------, - -----------------]
                     2 a + 2              2 a + 2
\end{verbatim}
\end{minipage}

\section{Programming in Maxima \label{sec:programming}}

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} of two
variables {\tt x} and {\tt y}.  The program cues the user to enter the function {\tt f}, then it
computes the partial derivatives $\mathtt{f_x}$ and $\mathtt{f_y}$, and then it uses the Maxima
command {\tt solve} to obtain solutions to $\mathtt{f_x = f_y = 0}$.  The program is written outside
of Maxima with a text editor, and then loaded into Maxima with the {\tt batch} command.  Here is the
program listing:
\begin{verbatim}
/* -------------------------------------------------------------------------- 
   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)   
)$
\end{verbatim}
The program (which is actually a function with no argument) is called {\tt critpts}. 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}, and the
unknowns are stored in {\tt unk}.  Here is a sample run:
% batch ("critpts.max");
% critpts ();
\begin{verbatim} 
(%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 = 0.4588955685487 %i + 0.35897908710869, 
y = 0.49420173682751 %i - 0.12257873677837], 
[x = 0.35897908710869 - 0.4588955685487 %i, 
y = - 0.49420173682751 %i - 0.12257873677837], 
[x = 0.41875423272348 %i - 0.69231242044203, 
y = 0.4559120701117 - 0.86972626928141 %i], 
[x = - 0.41875423272348 %i - 0.69231242044203, 
y = 0.86972626928141 %i + 0.4559120701117]]
\end{verbatim}

\section{A partial list of Maxima functions}

See the Maxima reference manual {\tt doc/html/maxima\_toc.html} (under the main Maxima installation directory).
From Maxima itself, you can use {\tt describe(\textit{function name})}.

\begin{description}
   \item[{\tt allroots(a)}] Finds all the (generally complex) roots of the polynomial equation {\tt
   A}, and lists them in {\tt numer}ical format (i.e. to 16 significant figures).
   \item[{\tt append(a,b)}] Appends the list {\tt b} to the list {\tt a}, resulting in a single
   list.
   \item[{\tt batch(a)}] Loads and runs a program with filename {\tt a}.
   \item[{\tt coeff(a,b,c)}] Gives the coefficient of {\tt b} raised to the power {\tt c} in
   expression {\tt a}.
   \item[{\tt concat(a,b)}] Creates the symbol {\tt ab}.
   \item[{\tt cons(a,b)}] Adds {\tt a} to the list {\tt b} as its first element.
   \item[{\tt demoivre(a)}] Transforms all complex exponentials in {\tt a} to their trigonometric
   equivalents. 
   \item[{\tt denom(a)}] Gives the denominator of {\tt a}.
   \item[{\tt depends(a,b)}] Declares {\tt a} to be a function of {\tt b}.  This is useful for
   writing unevaluated derivatives, as in specifying differential equations.
   \item[{\tt desolve(a,b)}] Attempts to solve a linear system {\tt a} of ODE's for unknowns {\tt b}
   using Laplace transforms.
   \item[{\tt determinant(a)}] Returns the determinant of the square matrix {\tt a}.
   \item[{\tt diff(a,b1,c1,b2,c2,\ldots,bn,cn)}] Gives the mixed partial derivative of {\tt a} with
   respect to each {\tt bi}, {\tt ci} times.  For brevity, {\tt diff(a,b,1)} may be represented by
   {\tt diff(a,b)}.  {\tt 'diff(\ldots)} represents the unevaluated derivative, useful in specifying
   a differential equation.
   \item[{\tt eigenvalues(a)}] Returns two lists, the first being the eigenvalues of the square
   matrix {\tt a}, and the second being their respective multiplicities.
   \item[{\tt eigenvectors(a)}] Does everything that {\tt eigenvalues} does, and adds a list of the
   eigenvectors of {\tt a}.
   \item[{\tt entermatrix(a,b)}] Cues the user to enter an $\mathtt{a} \times\, \mathtt{b}$ matrix,
   element by element.
   \item[{\tt ev(a,b1,b2,\ldots,bn)}] Evaluates {\tt a} subject to the conditions {\tt bi}.  In
   particular the {\tt bi} may be equations, lists of equations (such as that returned by {\tt
   solve}), or assignments, in which cases {\tt ev} ``plugs'' the {\tt bi} into {\tt a}.  The {\tt
   Bi} may also be words such as {\tt numer} (in which case the result is returned in numerical
   format), {\tt detout} (in which case any matrix inverses in {\tt a} are performed with the
   determinant factored out), or {\tt diff} (in which case all differentiations in {\tt a} are
   evaluated, i.e., {\tt 'diff} in {\tt a} is replaced by {\tt diff}).  For brevity in a manual
   command (i.e., not inside a user-defined function), the {\tt ev} may be dropped, shortening the
   syntax to {\tt a,b1,b2,\ldots,bn}.
   \item[{\tt expand(a)}] Algebraically expands {\tt a}.  In particular multiplication is
   distributed over addition.
   \item[{\tt exponentialize(a)}] Transforms all trigonometric functions in {\tt a} to their complex
   exponential equivalents.
   \item[{\tt factor(a)}] Factors {\tt a}.
   \item[{\tt freeof(a,b)}] Is true if the variable {\tt a} is not part of the expression {\tt b}.
   \item[{\tt grind(a)}] Displays a variable or function {\tt a} in a compact format.  When used
   with {\tt writefile} and an editor outside of Maxima, it offers a scheme for producing {\tt
   batch} files which include Maxima-generated expressions.
   \item[{\tt ident(a)}] Returns an $\mathtt{a} \times\, \mathtt{a}$ identity matrix.
   \item[{\tt imagpart(a)}] Returns the imaginary part of {\tt a}.
   \item[{\tt integrate(a,b)}] Attempts to find the indefinite integral of {\tt a} with respect to
   {\tt b}.
   \item[{\tt integrate(a,b,c,d)}] Attempts to find the indefinite integral of {\tt a} with respect to
   {\tt b}. taken from $\mathtt{b=c}$ to $\mathtt{b=d}$.  The limits of integration {\tt c} and {\tt
   D} may be taken is {\tt inf} (positive infinity) of {\tt minf} (negative infinity).
   \item[{\tt invert(a)}] Computes the inverse of the square matrix {\tt a}.
   \item[{\tt kill(a)}] Removes the variable {\tt a} with all its assignments and properties from
   the current Maxima environment.
   \item[{\tt limit(a,b,c)}] Gives the limit of expression {\tt a} as variable {\tt b} approaches
   the value {\tt c}.  The latter may be taken as {\tt inf} of {\tt minf} as in {\tt integrate}.
   \item[{\tt lhs(a)}] Gives the left-hand side of the equation {\tt a}.
   \item[{\tt loadfile(a)}] Loads a disk file with filename {\tt a} from the current default
   directory.  The disk file must be in the proper format (i.e. created by a {\tt save} command).
   \item[{\tt makelist(a,b,c,d)}] Creates a list of {\tt a}'s (each of which presumably depends on
   {\tt b}), concatenated from $\mathtt{b=c}$ to $\mathtt{b=d}$
   \item[{\tt map(a,b)}] Maps the function {\tt a} onto the subexpressions of {\tt b}.
   \item[{\tt matrix(a1,a2,\ldots,an)}] Creates a matrix consisting of the rows {\tt ai}, where each
   row {\tt ai} is a list of {\tt m} elements, {\tt [b1, b2, \ldots, bm]}.
   \item[{\tt num(a)}] Gives the numerator of {\tt a}.
   \item[{\tt ode2(a,b,c)}] Attempts to solve the first- or second-order ordinary differential
   equation {\tt a} for {\tt b} as a function of {\tt c}.
   \item[{\tt part(a,b1,b2,\ldots,bn)}] First takes the {\tt b1}th part of {\tt a}, then the {\tt
   B2}th part of that, and so on.
   \item[{\tt playback(a)}] Displays the last {\tt a} (an integer) labels and their associated
   expressions.  If {\tt a} is omitted, all lines are played back.  See the Manual for other
   options.
   \item[{\tt ratsimp(a)}] Simplifies {\tt a} and returns a quotient of two polynomials.
   \item[{\tt realpart(a)}] Returns the real part of {\tt a}.
   \item[{\tt rhs(a)}] Gives the right-hand side of the equation {\tt a}.
   \item[{\tt save(a,b1,b2,\ldots, bn)}] Creates a disk file with filename {\tt a} in the current
   default directory, of variables, functions, or arrays {\tt bi}.  The format of the file permits
   it to be reloaded into Maxima using the {\tt loadfile} command.  Everything (including labels)
   may be {\tt save}d by taking {\tt b1} equal to {\tt all}.
   \item[{\tt solve(a,b)}] Attempts to solve the algebraic equation {\tt a} for the unknown {\tt b}.  A
   list of solution equations is returned.  For brevity, if {\tt a} is an equation of the form
   $\mathtt{c = 0}$, it may be abbreviated simply by the expression {\tt c}.
   \item[{\tt string(a)}] Converts {\tt a} to Maxima's linear notation (similar to Fortran's) just as if
   it had been typed in and puts {\tt a} into the
    buffer for possible editing.  The {\tt string}'ed expression should not be used in a computation. 
   \item[{\tt stringout(a,b1,b2,\ldots,bn)}] Creates a disk file with filename {\tt a} in the current
   default directory, of variables (e.g. labels) {\tt bi}.  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.
   \item[{\tt subst(a,b,c)}] Substitutes {\tt a} for {\tt b} in {\tt c}.
   \item[{\tt taylor(a,b,c,d)}] Expands {\tt a} in a Taylor series in {\tt b} about $\mathtt{b=c}$,
   up to and including the term $\mathtt{(b-c)^d}$.  Maxima also supports Taylor expansions in more
   than one independent variable; see the Manual for details.
   \item[{\tt transpose(a)}] Gives the transpose of the matrix {\tt a}.
   \item[{\tt trigexpand(a)}] Is a trig simplification function which uses the sum-of-angles
   formulas to simplify the arguments of individual {\tt sin}'s or {\tt cos}'s.  For example, 
   {\tt trigexpand(sin(x+y))} gives {\tt cos(x) sin(y) + sin(x) cos(y)}.
   \item[{\tt trigreduce(a)}] Is a trig simplification function which uses trig identities to
   convert products and powers of {\tt sin} and {\tt cos} into a sum of terms, each of which
   contains only a single {\tt sin} or {\tt cos}.  For example, \verb+trigreduce(sin(x)^2)+ gives
   {\tt (1 - cos(2x))/2}.
   \item[{\tt trigsimp(a)}] Is a trig simplification function which replaces {\tt tan}, {\tt sec},
   etc., by their {\tt sin} and {\tt cos} equivalents.  It also uses the identity 
   $\mathtt{sin()^2 +   cos()^2 = 1}$.
\end{description}



\end{document}