Maxima Book Chapter 1
Maxima Book Chapter 1
http://maxima.sourceforge.net/
Read the description of Maxima shown in this page. The page also includes a number of
links including a Download link. Download and install Maxima in your computer as
indicated in the download page.
The Maxima web page also includes a Documentation link with a number of tutorials on the
use of Maxima.
You will notice that there are two possible instances of Maxima called XMaxima and
wxMaxima. While both allow the user access to the Maxima commands, the difference is
in the graphic user interface (GUI) used to communicate with Maxima.
XMaxima
An example of the XMaxima interface is shown in Figure 1.1. The top of the GUI is the
input window for Maxima commands. The lower part is a display of a Maxima Primer
document providing the user with some information about getting started with Maxima. In
between the top and lower part of the display you will find buttons labeled File, Back,
file:/C:/PROGRA~/MAXIMA~1.0/share/maxima/514~1.0/xmaxima/INTRO~1.HTM
file:/C:/Program Files/Maxima-5.14.0/share/maxima/5.14.0/xmaxima/intro.html
The XMaxima GUI abbreviates some of the sub-folders in the first file specification
producing the reference shown above, which could be a bit confusing. The full file
specification shows the location of the file being shown in the bottom window of the
XMaxima GUI. This html file is located in the Maxima installation as indicated above.
Double-click on the integrate command shown in the Maxima Primer to see Maxima in
action in the XMaxima window. The top window will now show the following operation:
Notice that there are two input locations labeled (%i1), or input 1, and (%i2), or input 2.
Input 1 (%i1) is missing any input. This is so, because by double-clicking the integrate line
The full mathematical operation calculated in this example can be, on paper, written as
dx
1x 3 =
2
ln x x1
tan1
2x 1
3
log x1 .
6 3 3
The user is invited to continue reading the Maxima Primer document and double-click on
the different examples listed to learn the basic operation of Maxima. Following those
exercises, one may notice, for example, that in the XMaxima interface, the mathematical
constant (the ratio of the length of a circumference to its diameter) is referred to as
%pi. Also, infinity () is referred to as inf.
The Maxima Primer examples include also plots that are produced in their own separate
graphics window, e.g., the commands
plot2d(sin(x),[x,0,2*%pi])
plot3d(x^2-y^2,[x,-2,2],[y,-2,2],[grid,12,12])
wxMaxima
wxMaxima uses an interface as shown in Figure 1.2, below.
This interface is more sophisticated than that of XMaxima for the following reasons:
http://wxmaxima.sourceforge.net/wiki/index.php/Main_Page
http://wxmaxima.sourceforge.net/wiki/index.php/Howto
NOTE: Because of the additional features available in wxMaxima, we will use this GUI
exclusively to present the examples contained in this and subsequent chapters. We will not
be using XMaxima anymore in this or subsequent chapters.
wxMaxima menus
Take some time to explore the different menus in the wxMaxima GUI:
The File menu contains items typically found in windows-based applications such as
Open, Read file, Save, Save As..., Export to HTML, Select File, Print, and Exit. Some
items in the File menu, such as Load package, Batch file, and Monitor File, are
proper of wxMaxima.
The Edit menu contains typical commands such as Copy, Cut, and Paste, as well as
others that are proper for wxMaxima.
The Maxima menu contains items that allow the user to control the operation of
Maxima.
The Equations, Algebra, Calculus, Simplify, Plotting, and Numeric menus provide
mathematical functions that are entered using dialogues.
The Help menu contains several items of interest such as:
Maxima help: opens the Maxima Manual window with description and examples of
Maxima commands.
Describe: produces a dialogue where the user can enter the name of a specific
command. Try, for example, plot3d, and press OK. The dialogue will access the
section of the Maxima Manual corresponding to the requested command.
Example: enters a series of examples of applications of the requested command
into the wxMaxima interface. Try, for example, integrate, and press OK.
Apropos: use this dialogue to enter a keyword to search for a command that is
similar to the keyword. For example, if you were seeking information on
integration, you could enter the word integra, to get a listing of commands that
may be related to integra. Then, you can use Describe or Example with one of
the commands listed.
Show tip: shows tips on the use of Maxima.
Build info: provides information on the current version of Maxima.
Bug report: provides a web site where users can report errors in the operation of
Maxima, or unexpected results of some operations. These bugs are reported
to the programming team and solutions to them (if available) get incorporated in
the new versions of the software.
About: provides the current version of wxMaxima. Notice that the versions of
Maxima and vxMaxima are not necessarily the same. My installation, at the
Variable or function names must start with a letter, and may include letters,
numbers, and undersign, e.g.,
Some pre-defined functions: Some of the common pre-defined functions in Maxima include:
log x
log 10 x =
log 10
sin(2.5*%e);float(sin(2.5*%e));
floor(%pi);ceiling(%pi);
log(5);float(log(5));
k:float(log(3)/log(10));
float(10^k);abs(-2);fix(3.3);fix(-3.2);
Notice that Maxima will tend to give symbolic results (i.e., results including fractions,
square roots, unevaluated trigonometric, exponential, or logarithmic functions) rather than
floating-point (or numerical) results. Use function float, as in the examples above, to get
floating-point solutions.
Automatic parentheses. Whenever you enter an opening parenthesis in the INPUT line, a
closing parenthesis is added automatically. If you are not used to this feature, you may
end up entering more closing parentheses than needed. This situation will result in an
error that is easy to spot.
exp(-2.5)*sin(3*%pi/11);float(%);exp(-3);float(%);log(5);float(%);
To access the second-to-last commans use %2, the third-to-last, use %3, and so on.
Here are some examples to try (in some examples we use function is to check whether
comparisons of numbers are true or false):
float(%phi);float(%pi);float(%e);%gamma;
is(3>2);is(3<2);is(x<3);
integrate(exp(-x^2/2),x,-inf,inf);integrate(exp(-x^2/2),x,minf,inf);
z1:3+5*%i; z2:-2+6*%i;z1+z2;z1-z2;expand(z1*z2);expand(z1^2);
cabs(z1);arg(z1);
z2;-z2;conjugate(z2);expand(z2*conjugate(z2));
rectform(z1/z2);rectform(sqrt(z1));polarform(z1);polarform(z2);
Buttons (1) through (4), and (7) through (10) operate on an expression typed in the INPUT
line before pressing the corresponding button. Buttons (5), (6), (11), and (12) trigger
dialogues to performed the associated operations. The operation of the buttons, with
appropriate examples, is shown next.
(2) Simplify(r): simplifies expressions containing logs, exponentials, and radicals, e.g.,
(%e^x-1)/(%e^(x/2)+1); [Simplify(r)]
(11)Solve ODE...: solves a 1st order or 2nd order ordinary differential equation, e.g.,
dn y
Note: Derivatives are written using 'diff(y,x,n) to represent n .
dx
Press [ OK ] in this message form, and then [ OK ] again in the wxMaxima configuration
window, and click off wxMaxima. The Full button panel will not be active until you re-start
wxMaxima.
When you re-start wxMaxima, the bottom part of the interface will show the Full button
panel:
which now includes 20 buttons, instead of the 12 buttons of the Basic button panel. The
new buttons are shown in the following figure, labeled (13) to (20), with labels shown in
boldface letters (no all the buttons are shown):
http://www.drshirley.org/fonts/SPIonic.ttf
After installing the font in your computer, you need to select it to show Greek characters in
your wxMaxima interface. Proceed as follows:
To enter Greek letters type the English name of the letter in an expression, or precede the
name with the percentage symbol (%), e.g.,
factor(beta^2-1);
rectform(1/(%alpha+%beta*%i);
expand((alpa-1)*(beta+gamma));
expand((%alpha-1)*(%beta+%gamma));
Notice the difference between typing gamma and %gamma in the last two examples. Typing
gamma (without %) produces the upper-case Greek letter which represents the Gamma
function from mathematics, whereas, %gamma produces Euler constant , defined, as the
limit as n , of the quantity
n
1k ln n .
k =1
gamma(2.5);
plot2d(gamma(x),[x,0.5,3.0]);
Eliminate variable ... See the example available in the Maxima Manual by selecting
the menu option Help > Example..., and type eliminate:
Solve ODE... This is the same as pressing the button [Solve ODE...]. Equivalent to:
ode2('diff(y,x,2)+y=sin(x), y, x);
Initial value problem (1) ... Initial value problem for first-order ODE. Uses two
steps, first Solve ODE ..., then Initial value problem (1). Equivalent to:
Boundary value problem ... Boundary value problem for second-order ODE. Uses two
steps: first Solve ODE ..., then Boundary value problem. Equivalent to:
ode2('diff(x,t,2)+x=sin(t),x,t); ic2(%,t=0,x=1,'diff(x,t)=-1);
Outputs are shown by the prompt (%o...) with an associated number, e.g.,
Thus, references such as %i1, %o1, etc., act like variable names that can be operated upon
as any other variable. An alternative would be to actually assign variable names to the
expressions entered. To try this approach we will also illustrate the use of the command
history for performing operations.
Then, use the left-arrow key to move the cursor to the left of the first parentheses, and
type:
a:
then press [ENTER], or click on the Enter command button: . The result is the
following:
Now, we can refer to variable a for performing operations on this expression, e.g.,
The command history can be accessed, therefore, through the use of the up- and down-
arrow keys in your keyboard. Once a command is accessed this way, you can either press
[ENTER] to repeat it, or edit it in the INPUT line in order to perform a different operation.
End-of-line characters
It was mentioned earlier that every Maxima command ends in a semi-colon (;), and that if
one fails to enter that end-of-line character, wxMaxima will enter it automatically. The
fact is that, besides the semi-colon, there is also a supress-output character, namely, the
dollar sign ($), which can be used as end-of-line character. Using the dollar sign ($) to end
a Maxima statement suppresses the output of the command. However, the command gets
executed in memory. For example, try the following commands:
The use of the dollar sign ($) as end-of-line character saves space in the wxMaxima
interface as illustrated in the following example:
Notice that the dollar sign ($) in input (%i14) suppresses the output for the differential
equation myODE1. Also, notice the use of the Greek character omega () as a coefficient
in the differential equation myODE1. Furthermore, notice that, in attempting a solution
for myODE1, Maxima doesn't know a-priori what the value of is. So, Maxima asks from
the user whether is zero or nonzero. In this example, the user types nonzero, and
Maxima returns the solution.
The file storing the session will be located in the folder ../Documents/MAXIMA/, and will be
named myFirstMaximaSession.wxm.
In this case, Maxima opens the file and executes every command, stopping at input (%i15)
where it asks again about the value of coefficient w in variable myODE1. Repeating the
response nonzero allows Maxima to continue evaluating the file to recover the entire
session saved.
Interrupting a calculation
If, for some reason, wxMaxima seems to be hung up in a calculation, you can interrupt the
processing by using the menu item Maxima > Interrupt, or type Cntl-G. Alternatively, use
the interrupt button in the menu bar:
Select [OK] if you don't want to save your current session. Otherwise, press [Cancel], save
your session as indicated above, and exit wxMaxima once more.
Text lines contained in saved session files get loaded with the rest of the commands when
using File > Open or File > Read file.
To insert a section use the menu item Edit > Insert > Section. This operation is also similar
to inserting text, except that the text is provided in a larger font and with an underline.
The following example shows a title and a section insertion in a wxMaxima session.
If you enter a new command in the INPUT line, then the statement in front of the input
prompt remains unevaluated. However, if you click on the input prompt statement, thus
selecting it, and do a right-click, you can evaluate the command by selecting the option
Re-evaluate input. In this case, the input gets evaluated as follows:
The following example shows the definition of variables and functions and the listing of
their names:
The option Show definition is used next to find the definition of function f2:
To delete functions f1 and f2 we enter those names in the dialogue. The result is shown
below:
To delete functions x1 and x2 we enter those names in the dialogue. The result is shown
below:
An alternative way to delete user-defined functions or variables is to use function kill. This
function basically clears any value or definition associated with a variable or function
name. For example, to clear the contents of variable y1, use:
In order to create a batch file we need to edit the session file using a text editor. In this
example I will use the Notepad++ text editor to open the session file. Notepad++ is
available at
http://notepad-plus.sourceforge.net/uk/site.htm .
When opened with Notepad ++, the file myFirstMaximaSession.wxm looks as follows:
Notice that you are warned in the very first line of the file to not edit the file by hand.
This is for the wmx file. If you change anything in the file it may not be readable by
wxMaxima again. The way to proceed is to save the file as a batch file, with the .mac
suffix. Save it, for example, as myFirstMaximaBatchFile.mac, and edit it to look as shown
below. This is the batch file that includes a number of comment lines (text between /*
and */), and Maxima commands.
A batch file can also be created from scratch. Simply type the Maxima commands in a text
file and save it with the suffix .mac. Here is an example of a batch file created from
scratch:
In the first expression, using 'diff(x,t,2) produces as output the derivative thus indicated.
However, in the second expression, Maxima evaluates the required derivatives. Since
function x(t) has not been defined, the derivatives in the second expression evaluate to
zero, and the result is x = e-t.
Applications of ev
Function ev evaluates an expression in a given environment determined by a number of
arguments. For complete information on function ev, use the menu item Help > Describe,
and enter the name ev in the dialogue form. In this document we will present only some
specific examples of the use of function ev.
Derivative and integral calculations can be forced with the option nouns:
These examples illustrates how to list an expression and their evaluation in the same
line. It also introduces the idea of nouns in Maxima evaluation.
Read this section in the Manual to understand the idea of verbs and nouns, as well how to
convert form one to the other.
Online help
In an earlier section we presented the different options available in the Help menu. A
quick way to obtain help is by using the ?? operator. For example, if you are interested in
finding information about the function eval, use:
Maxima reply by listing a number of entries that include the particle eval, and requesting
additional input from the user. At this point, the user can enter a particular number
referring to the 7 options listed, or enter the particles all or none. Enter none to stop the
online help process.