MST124 Computer Algebra Guide
MST124 Computer Algebra Guide
Essential mathematics 1
SUP 03061 0
1.1
Contents
Contents
Introduction 5
1 Installing Maxima 7
3 Algebra 30
3.1 Algebraic manipulations 31
3.2 Equations and their solutions 33
3.3 Plotting graphs 38
4 Functions 41
7 Plotting circles 55
8 Differentiation 60
9 Integration 64
10 Matrices 70
10.1 Matrix algebra 70
10.2 Determinants and inverses 76
12 Taylor polynomials 85
13 Complex numbers 87
13.1 Working with complex numbers 87
13.2 Solving polynomial equations 90
Acknowledgements 180
Index 181
Introduction
Introduction
Throughout this module you will use computer software called Maxima to
investigate mathematical concepts and perform calculations that may be
too laborious or difficult to do by hand. Maxima is a computer algebra
system (often abbreviated to CAS); that is, a computer program that
can perform algebraic manipulations, such as expanding brackets,
factorising expressions and solving equations, as well as performing
numerical calculations and plotting graphs. It is typical of the type of
computer software used by mathematicians today.
This Guide explains how to use Maxima for some of the mathematics in
MST124. It is designed to be read in conjunction with the main study
texts and is not meant to be read all at once because its later sections use
mathematical concepts that you may not have yet met. As you work
through the main study texts in Books A–D, you will come across sections
or activities marked with the icon shown here. Some of these ask you to
study part of this Guide. Other activities ask you to solve a problem using
Maxima commands that you have previously learned. While the
mathematical answers to such activities are included within the
appropriate book, the computer methods needed to solve them are given in
the section ‘Computer methods for CAS activities in Books A–D’ towards
the end of this Guide.
The final section of this Guide contains a summary of all the Maxima
commands introduced. This should be useful for reference, both as you
work through the module and afterwards.
Note that this Guide does not attempt to describe all the features of
Maxima. If you need more information, please consult the extensive
documentation provided on the Maxima website at
maxima.sourceforge.net or use Maxima’s help system, which is
described in Subsection 2.8 of this Guide.
The ‘Maxima accessibility guide’ (see page 94) is primarily aimed at those
who may have difficulty using Maxima because of a disability, and provides
some advice and suggestions.
5
Introduction
A word of warning
Using a computer algebra system is not a substitute for learning the
mathematical techniques taught in this module! You need to become
proficient at using the methods taught so that you can apply them in the
examination and in your future studies, and also to help you develop your
mathematical understanding and intuition.
Maxima is not intelligent – it is just a tool, similar to your calculator. You
need to use your own mathematical skills to guide it and interpret its
results critically.
Conventions
Here are the various computing terms used in this Guide, and how they
should be interpreted on Microsoft Windows and Apple Mac computers. “Rather than learning how to solve that,
shouldn’t I be learning how to operate
software that can solve that?”
Computer terminology
Term Microsoft Windows Apple Mac
Click Click the left mouse/touchpad button Click the mouse/touchpad button
Right click Click the right mouse/touchpad button Hold the ctrl key while clicking
the mouse/touchpad button
Ctrl-Q Hold down ctrl while pressing Q Hold down command while pressing Q
Etc. Etc. Etc. – but there are exceptions to this
pattern that we’ll mention as they arise.
6
1 Installing Maxima
1 Installing Maxima
Maxima can be used on many different types of computer, and there are
several different intermediary systems, known as interfaces or
front-ends, that provide a means of communication between you, the
user, and the Maxima system itself. This is illustrated in Figure 1. The
interfaces enable you to enter commands that are then processed by
Maxima, and they display the results obtained.
7
1 Installing Maxima
wxMaxima, then you should try to achieve all the outcomes shown in this
Guide using your chosen interface.
All the Maxima commands mentioned in this Guide can be used with any
interface to Maxima, unless indicated otherwise.
If you use a screenreader the basic command-line interface shown in
Figure 3 may be the easiest interface for you to use.
There are more details on choosing an interface, configuring the
wxMaxima interface to meet your needs and using the command-line
interface in the ‘Maxima accessibility guide’ (see page 94). If you think
you need this advice, you should read that section now.
If you are studying within a prison or other closed institution, you can
install Maxima from the Offline resources disc.
8
2 Getting started with Maxima and wxMaxima
Start wxMaxima on your computer, and keep it open to work with as you
study this section.
If you cannot remember how to do this on your computer, see the
OU Maxima website: learn1.open.ac.uk/site/maxima.
9
2 Getting started with Maxima and wxMaxima
10
2 Getting started with Maxima and wxMaxima
3. Press Shift-Enter, that is, hold down the Shift key while pressing
Enter . (Remember: if, as on some Macs, your keyboard has
separate Enter and Return keys, then you should hold down the
Shift key while pressing Return .)
11
2 Getting started with Maxima and wxMaxima
The result is displayed under the input line, preceded by the label
(%o1). The o stands for ‘output’, so this label identifies the line as
output line 1. It gives the output corresponding to input line 1.
Throughout each Maxima session the line numbering starts at 1 and
then increases by one for each new input (and output).
In wxMaxima, matching input and output lines form a cell. Each cell is
identified with the marker shown in Figure 5.
12
2 Getting started with Maxima and wxMaxima
3. Click part of the cell marker other than the top triangle to highlight
it, then press the Delete keyboard key.
13
2 Getting started with Maxima and wxMaxima
3. Tick the ‘Open a cell when Maxima expects input’ box in the
Configuration window by clicking it.
Troubleshooting Maxima
If you are using Maxima and it does not seem to be responding, try the
following suggestions.
If you encounter other problems, check the Frequently asked questions on
the OU Maxima website: learn1.open.ac.uk/site/maxima.
Troubleshooting Maxima
Cell Marker Status message Comments
Boxed: Ready for user input Maxima is waiting for you to type
something before continuing.
14
2 Getting started with Maxima and wxMaxima
Closing wxMaxima
When you have finished using Maxima, you can close Maxima and the
wxMaxima interface by using one of the following methods.
• Select Exit from the File menu (or Quit wxMaxima from the
wxMaxima menu on an Apple Mac computer).
• Press Ctrl-Q. (Here, Q stands for quit.)
• On a Windows computer, click the usual small cross button at the top
right-hand corner of the wxMaxima window.
You may be asked if you want to save your changes to the worksheet
before closing. At this stage, click ‘No’. You will learn how to save your
work in Subsection 2.7.
In this Guide, we will use ∧ for powers. Note that many Maxima
commands take the form of a command name, such as sqrt or abs,
followed by a pair of round brackets containing one or more objects, such
as numbers, that the command operates on. Such an object is called an
argument of the command. In the summary tables in this Guide,
15
2 Getting started with Maxima and wxMaxima
Maxima generally ignores all spaces that you type while entering a
calculation or command, so you can use spaces to make a command easier
to read. You can also enter line breaks, using Shift-Enter, which are
similarly ignored by Maxima.
Whenever you enter an opening bracket, the wxMaxima interface
automatically adds a closing one for you. This behaviour can be turned off
by unticking Match parenthesis in text controls in the Configuration
window. (See Computer activity 5 for how to open the Configuration
window.)
You can calculate roots other than square roots, such as cube roots, by
using the index laws.
16
2 Getting started with Maxima and wxMaxima
The name of the command float arises from the fact that the method
used by computers to store decimal numbers internally using the binary
digits 0 and 1 is called a floating-point representation. The float
command instructs Maxima to convert a number stored symbolically as a
17
2 Getting started with Maxima and wxMaxima
For each of the following expressions, use Maxima to simplify it and then
find a decimal approximation for it.
8 92/3
√ 8
(a) 147 (b) (c) 2500
5
The expression in part (c) doesn’t involve decimal numbers and so the
result is evaluated exactly. Notice, however, that the middle 91 digits
of the answer are not displayed because the system does not expect
you to read them all!
The decimal form of the result, 3.2733906078961419 10150 , is given
in wxMaxima’s way of displaying scientific notation. It means
3.2733906078961419 × 10150 .
As with the input and output line labels, the ‘%’ symbol indicates the
name of a quantity built into Maxima.
When displaying mathematics in an output line, wxMaxima displays %pi
as π.
18
2 Getting started with Maxima and wxMaxima
As you do this the cell marker will turn red and you will see a small
flashing vertical line (the editing cursor) appear in the expression.
19
2 Getting started with Maxima and wxMaxima
Should you click in the space between two cells, a horizontal cursor will be
shown, as in Figure 7. This indicates the position at which a new cell will
be created, if you begin typing here. This is also shown as you move
between cells using the up and down keyboard arrow keys.
(c) Edit the line where you typed 6+2;, change it to 6*2; and re-evaluate
the cell by pressing Enter .
Notice that the cell number and output of the line you edited is
updated, but the result of 3+%; does not change. This is because
when the 3+%; cell was evaluated, the symbol % represented the result
of the old version of the edited command.
20
2 Getting started with Maxima and wxMaxima
(d) From the Cell menu, select the Evaluate All Visible Cells
option, or press Ctrl-R.
Re-evaluating a worksheet
Selecting the Evaluate All Visible Cells option from the Cell
menu re-evaluates all visible cells in the worksheet, in the order in
which they appear.
This can also be achieved using Ctrl-R.
21
2 Getting started with Maxima and wxMaxima
Warning
You cannot use = to assign a value to a variable. This symbol is used
for equations, as you will see later.
Variable names can be any combination of letters and numbers that begins
with a letter. For example, Maxima will accept any of the following
variable names.
a A solution solution2 x2b
(b) Enter a;
√
(c) Assign the value of a 2 to b.
√
Don’t forget to include a multiplication sign when typing a 2.
The value of b is simplified when displayed.
√ √
(d) Edit the line where you assigned 8 to a, so that the value 7
becomes assigned to a.
22
2 Getting started with Maxima and wxMaxima
Notice that the value of b has not changed. The variable b was
defined when a had its original value.
(f) Enter values; to list the names of all the variables that are currently
assigned values.
b is still defined.
Notice that in Computer activity 12(d), when the value of a was changed,
the value of b was not affected, since it was defined when a had its original
value. If you want to update the value of b using a different value of a,
then you should enter a new value of a then re-evaluate the line defining b
(by selecting the line and pressing Enter ), or re-evaluate the whole
worksheet by selecting the option Evaluate All Visible Cells from the
Cell menu.
Working with variables
Operation Command Example
Assign a value to a variable : a:23;
Display the value of a variable variable a;
List all user assigned variables values values;
Remove an assigned variable kill( variable ) kill(a);
Remove all assigned variables kill(all) kill(all);
Note: here the placeholder variable represents any variable name.
23
2 Getting started with Maxima and wxMaxima
You can reset the values of fpprintprec and all other system variables to
their original values by using the reset() command. Try entering
reset(); followed by float(%pi); and check that the value of π is
displayed to 16 significant figures.
24
2 Getting started with Maxima and wxMaxima
Note that the list of variables displayed when you enter values; does not
include any system variables. If one of your variables does not appear in
the list displayed by values;, then you have probably used a variable
name that is also the name of a system variable and hence changed the
value of that system variable. In extreme circumstances this may change
the behaviour of Maxima, which can be restored by resetting all system
variables as described above.
25
2 Getting started with Maxima and wxMaxima
To enter text into your worksheet, first you need to create a suitable cell in
which to type. To do this first you position the cursor, then you select the
appropriate one of the following commands from the Cell menu.
• Insert Text cell
• Insert Title cell
• Insert Section cell
• Insert Subsection cell
The new cell will be created under the cell in which the editing cursor
appears, or between two existing cells at the position indicated by the
horizontal cursor, if shown. Remember, the horizontal cursor appears
whenever you click between two cells, or move within the worksheet using
the up and down keyboard arrow keys.
As you type your text, to start a new line within the cell press Enter .
When you have finished typing the text, click elsewhere on the worksheet
or use the up or down keyboard arrow keys to move out of the text cell. If
your text cell is at the bottom of the worksheet, and you click or move
below it, an input prompt may not be shown until you start typing again.
Section and Subsection cells are automatically numbered.
(a) Create the worksheet shown in Figure 8. Use a Title cell for the title
‘Circles’ and Text cells for the remaining text. Remember to click
elsewhere on the worksheet or move position with the up or down
keyboard arrow keys when you have finished entering each piece of
text.
After evaluating a Maxima command, you will need to correctly
position the horizontal cursor before inserting the next text cell.
(b) Use your worksheet to find the circumference and area of a circle of
radius 5. (Remember to re-evaluate the worksheet, for example, by
using Ctrl-R, after changing the value of r.)
Each Title cell, Section cell and Subsection cell has a small square in its
top left corner. Clicking this square hides (or reveals) the contents of the
worksheet from that point onward, until the next cell of the same type.
26
2 Getting started with Maxima and wxMaxima
You can open a saved wxMaxima worksheet by using the Open option from
the File menu, or by double-clicking on the saved file on your computer.
Save your current worksheet then reload it, by following these steps.
(a) Select Save As from the File menu.
(b) In the window that appears:
(i) Choose the folder in which to save your work. You might like to
save it in the folder that you created in Computer activity 1.
(ii) Choose a name for the file in which the worksheet will be saved.
(iii) Make sure the file type is set to wxMaxima xml document
(*.wxmx).
(iv) Click ‘Save’.
(c) Close wxMaxima, by selecting Exit from the File menu, or typing
Ctrl-Q, or clicking the small ‘x’ at the top right of the window. (On a
Mac select Quit wxMaxima from the wxMaxima menu or hold down the
command key while pressing Q .)
27
2 Getting started with Maxima and wxMaxima
You can print a wxMaxima worksheet by selecting Print from the File
menu.
Alternatively, you can obtain an image of the entire wxMaxima window by
taking a ‘screenshot’. To do this on a Microsoft Windows computer, first
click on the wxMaxima window, then press Alt-PrintScreen (that is,
hold down the Alt keyboard key while pressing the PrintScreen key,
which may be labelled PrtScr , Prt Scrn or something similar). This stores
the image, which you can then paste into a suitable application.
If you are using Windows Vista, Windows 7 or Windows 8, you might like
to use the ‘Snipping Tool’, available by typing ‘snip’ into the Start menu.
To take a screenshot on an Apple Mac computer, press Cmd-Ctrl-Shift-4
(that is, hold down the command , ctrl and ⇑ keyboard keys while pressing
the 4 key). Next press the space bar, move the camera pointer over the
wxMaxima window and click. This stores the image which you can then
paste into a suitable application. You may also like to use the Grab
application from the Utilities folder.
If you want to copy a single output line from your worksheet into, for
example, a word-processed document, then you can select that part of the
worksheet, and choose Copy As Image from the menu obtained by right
clicking on what you have selected. You can then paste the resulting image
into a suitable application.
28
2 Getting started with Maxima and wxMaxima
(a) Enter ? float; to show the help for the float command.
Note the space between the ? and float, which is needed. This is one
of the few times in Maxima when spaces matter!
The help information for the command may include more detail than
you need!
After giving the help information, Maxima displays the output true.
This means that the command you entered was successful.
29
3 Algebra
(b) Suppose that you cannot remember the Maxima command for square
root, but you do remember that it was something like sqr.
Type ?? sqr; to list all the help information titles that contain the
letter sequence ‘sqr’.
A list of possible titles is displayed.
Title number 1 is what you were looking for, so enter 1; to display the
relevant information.
Help commands
Operation Command Example
Get help on a command ? command ? float;
or, describe( command ) describe(float);
3 Algebra
In Section 2 of this Guide you used Maxima to perform numerical
calculations. Much of the power of Maxima, however, lies in its ability to
perform algebraic operations. In this section, you will learn how to do this.
30
3 Algebra
(a) Enter
expand( (2+x)*(3*x+4)∧3 );
to expand the expression (2 + x)(3x + 4)3 .
(b) Enter
factor( 2*x∧3-7*x∧2-10*x+24 );
to factorise the expression 2x3 − 7x2 − 10x + 24.
x3 + 1
(c) Define p to be the expression .
x+1
(d) Enter
fullratsimp(p);
to simplify the expression assigned to the variable p.
31
3 Algebra
(e) Enter
subst(3,x,p);
to find the value of the expression p (defined above) when x = 3.
32
3 Algebra
33
3 Algebra
34
3 Algebra
You saw in Computer activity 20 that the output of the solve command is
a list. In Maxima, a list is a collection of individual elements separated
by commas and enclosed within square brackets. You can learn more
about using lists in the following activity.
(a) Assign the list containing the first five prime numbers to the variable A
by entering
A: [2,3,5,7,11];
(b) Display the fourth element of the list by entering
A[4];
(iii) Display the exact value of the first solution by entering the
command
rhs(solns[1]);
The command √ solns[1] refers to the first element of the list solns
5-1
which is x=- .
2
This is an equation. The value needed is the right-hand side of this,
which is extracted using the rhs command.
35
3 Algebra
You can also use the solve command to change the subject of an
equation: you solve the equation for the variable that you want to be the
subject, as shown in the next activity.
36
3 Algebra
Here, the second argument of the solve command is the variable that
you want to solve for; that is, the variable that you want to be the
subject of the equation.
Maxima might reorder the terms of the equations when displaying the
output.
37
3 Algebra
(b) Solve the pair of equations (eq1 and eq2) for the two unknowns
(x and y) by entering
solve( [eq1, eq2], [x,y] );
Plot the graph of the equation y = 4x2 − 8x + 2 for values of x such that
−1 ≤ x ≤ 2, as described below.
(a) Enter the command
wxplot2d( 4*x∧2-8*x+2, [x,-1,2]);
38
3 Algebra
(c) Change the colour of the curve to green, by including the additional
argument [color, green] after the other arguments of the wxplot2d
command, but before the closing round bracket.
You can plot multiple graphs in the same diagram by including a list of
expressions as the first argument of the command, as shown in the
following activity.
Suppose that the displacements s1 and s2 (in km) of two cars along a
straight road from a given starting point are given by s1 = 15t3 + 10t and
s2 = 60t respectively, where t is the time (in hours) and 0 ≤ t ≤ 2.
(a) Plot graphs of the displacement of the cars for 0 ≤ t ≤ 2 by entering
wxplot2d( [15*t∧3+10*t, 60*t], [t,0,2] );
39
3 Algebra
(b) Change the colours of the curves by adding the following additional
argument to the command used above: [color, green, magenta].
That is, change the command to
wxplot2d( [15*t∧3+10*t, 60*t], [t,0,2], [color, green, magenta]);
Maxima uses the first colour listed for the graph of the first
expression listed and so on. If you do not include enough colours,
Maxima starts using the listed colours again.
(c) Now change the labelling within the legend to be the variable names
given to the expressions in the question, rather than the expressions
themselves. Do this by including another argument
[legend, "s1" ,"s2"]
in a similar way to the colour argument; that is, within the round
brackets of the wxplot2d command and separated from the other
arguments by a comma.
(d) Finally, change the labelling of the horizontal and vertical axes, by
adding two more arguments to the command:
[xlabel, "time, t (h)"]
and
[ylabel, "displacement, s (km)"].
The different ways in which you can use the wxplot2d command are
summarised as follows, along with some of the optional arguments. If you
are using a different interface to Maxima, you can use the plot2d
command in the same ways.
40
4 Functions
Plotting graphs
Operation Command Example
Plot a graph wxplot2d( expression , wxplot2d(x∧2, [x,0,1]);
horizontal range ,...) which plots the graph of x2
for x between 0 and 1.
wxplot2d(x∧2,[x,0,1],[y,0,2]);
which plots the graph of x2
for x between 0 and 1, and with
vertical axis values between 0 and 2.
Note: for a full list of the possible options, view the Maxima help for
plot2d, using the ? plot2d; command.
4 Functions
You can define a function in Maxima using the := operator, as shown in
the following activity.
41
4 Functions
(a) Define the function f in Maxima, with the rule f (x) = x5 − 3x2 + 4,
by entering the following command. (Use the characters : followed
by = to type the := operator.)
f(x):=x∧5-3*x∧2+4;
42
4 Functions
You can plot the graph of a function using the wxplot2d command
introduced in Subsection 3.3 of this Guide, as demonstrated in the next
activity.
(a) Plot the function f defined in Computer activity 27 over the range
−2 ≤ x ≤ 2, by entering
wxplot2d(f(x), [x,-2,2]);
Note that the first argument must be f (x) rather than just f .
(b) Plot the function g defined in Computer activity 27 over the range
−5 ≤ x ≤ 5.
Notice the vertical scale of the graph, and the large spike near x = 2.
x−1
The function g has the rule g(x) = , so it is not defined at
x−2
x = 2. Maxima has evaluated it at values of x close to 2, obtained
large values and attempted to join up the corresponding points.
To obtain a better graph, you should restrict the range of the vertical
axis. You are asked to do this next.
If you began studying this section from Unit 3, Activity 11, now return to
the unit to continue your study of functions.
43
5 Exponential functions and logarithms
44
5 Exponential functions and logarithms
The Maxima commands for the exponential function and logarithms are
summarised below. Maxima has no command ln( ); remember that the
command for a natural logarithm is log( ).
Exponentials and logarithms
Operation Syntax Example
Exponential, for example e3 %e∧ %e∧3;
or exp( ) exp(3);
Natural logarithm, ln log( ) log(8);
The name of the radcan command arises from the fact that it converts
expressions involving radicals, that is, roots, powers and logarithms into a
canonical (or standard) form.
These commands are demonstrated in the following activity.
45
5 Exponential functions and logarithms
Can you simplify this expression and obtain the same answer by
hand?
If you began studying this section from Unit 3, Activity 48, now return to
the unit to continue your study of functions.
46
6 Trigonometry
6 Trigonometry
The Maxima commands for the trigonometric functions are given below.
Like many computer systems, Maxima assumes that all angles are
measured in radians. Notice that the names of the inverse trigonometric
functions sin−1 , cos−1 and tan−1 in Maxima are asin, acos and atan
respectively. This notation is used by many computer systems; it is short
for arcsin, arccos and arctan, the alternative names often used for sin−1 ,
cos−1 and tan−1 .
Trigonometric functions
Function Syntax Example
sin sin( ) sin(1);
cos cos( ) cos(3*%pi/2);
tan tan( ) tan(%pi/4);
47
6 Trigonometry
π
Remember to convert the angle to radians, by multiplying 45◦ by .
180
1√ 4
3
(d) sin−1
2
!π;
(e) cosec
7
! π;
(f) tan −
12
48
6 Trigonometry
49
6 Trigonometry
50
6 Trigonometry
You know from Unit 2 that the solutions of an equation of the form
f (x) = 0 are the x-coordinates of the points at which the graph of
y = f (x) crosses the x-axis, as illustrated in Figure 10.
51
6 Trigonometry
(ii) Next, plot the graph of f (x) over the interval −2 ≤ x ≤ 2, say.
This will help you to find an interval that contains a solution.
52
6 Trigonometry
(b) Using similar methods, find a solution of the equation sin2 (x + 2) = 3x.
(a) Enter
trigreduce( sin(x)∧2 );
53
6 Trigonometry
(b) Enter
trigexpand( % );
(c) Enter
trigsimp( % );
54
7 Plotting circles
You can use these commands, and others that you learned previously, in
the final activity of this section.
If you began studying this section from Activity 37 of Unit 4, this now
completes your study of the Unit.
7 Plotting circles
In this section you will learn how to use Maxima to plot circles.
In Subsection 3.3 of this Guide, you learned how to use the wxplot2d
command to plot curves. You can use this command to plot a curve only if
the equation of the curve is in explicit form; that is, only if it is written in
the form y = f (x), where f is a function.
To plot a curve represented by an equation in implicit form, such as
x2 + y 2 = 1, you can use the wximplicit plot command. This is
demonstrated in Computer activity 37.
The wximplicit plot command is not part of the basic Maxima collection
of commands, so you have to add it by loading an additional Maxima
package, the implicit plot package, which was installed on your
computer when you installed Maxima. The Maxima command to load an
additional package is load, which is also demonstrated in Computer
activity 37. Each package needs to be loaded only once per Maxima
session.
If you are using a Maxima interface other than wxMaxima, then you
should use the implicit plot command instead of the wximplicit plot
command. You load and use it in exactly the same way as
wximplicit plot.
55
7 Plotting circles
56
7 Plotting circles
Plot the circle (x − 1)2 + y 2 = 3, using equal scales on the x- and y-axes as
follows.
(a) Tell Maxima to always use equal scales on the x- and y-axes by
entering
set plot option([gnuplot preamble, "set size ratio -1"])$
57
7 Plotting circles
(b) Plot the line and circle on axes with equal scales by entering
wximplicit plot([line, circle], [x,0,5], [y,0,5]);
58
7 Plotting circles
Circles are not the only type of curve that can be represented by equations
in implicit form. In the next activity you will plot some other equations of
this type and see the curves that they represent.
59
8 Differentiation
Plot the curves represented by the following equations, using equal axis
scales for each curve. Make sure you use suitable ranges of x and y.
If you began studying this section from Activity 16 of Unit 5, now return to
the unit to continue your study.
8 Differentiation
The Maxima command for differentiating an expression is diff, which is
demonstrated in the following activity. This command finds derivatives by
using the derivatives of standard functions together with the sum rule,
constant multiple rule, product rule, quotient rule and chain rule.
Sometimes Maxima may give the result in a different, but equivalent, form
to the expression that you might obtain when differentiating by hand. If
this happens, then you might like to check that the two answers are
equivalent. You can do this by finding the difference between the two
answers and checking that it simplifies to zero. A rougher check is to use
Maxima to plot graphs of the two answers and check they appear to be the
same.
60
8 Differentiation
t2
(b) Define the variable p to be equal to , and then find its
sin(4t)
derivative with respect to t by entering
diff(p,t);
(Remember, to assign a value to a variable you use a colon (:).)
Using diff in this way can help you check the expression to be
differentiated has been entered correctly before you differentiate it.
(c) Define the function g(u) = (u2 + 3) ln(u2 ), and find its derivative using
diff(g(u),u);
(Remember, to define a function you use :=, and the Maxima
command for natural logarithms is log.)
Notice that the first argument given here is g(u), not just g.
(d) Find the second derivative of the expression p defined above, by using
diff(p,t,2);
The third argument of diff specifies the number of times that the
expression is to be differentiated.
61
8 Differentiation
The diff command is summarised in the following box. You can practise
using it in the next activity.
Differentiation
Operation Command Example
Differentiate diff( , variable ) diff(sin(x∧2),x);
You can use the diff command to assign the derivative of a function to
another named function. This is useful when you want to evaluate the
derivative at a particular input value, for example.
The next activity shows you how to do this – unfortunately it’s not
completely straightforward. In the activity, the original function is denoted
by f and its derivative is denoted by df, rather than by f’. This is
because you cannot use f’ as a function name in Maxima.
62
8 Differentiation
The problem is that when you enter this command, Maxima does not
perform the differentiation. Instead, it just notes that df(x) means
diff(f(x),x). Then, when you enter df(3), Maxima understands
this to mean diff(f(3),3), which is meaningless, as you cannot
differentiate with respect to a particular number.
To force Maxima to perform the differentiation, you can use the
syntax ''( ) (which contains two single quotation marks, not a
double quotation mark, and a pair of round brackets). This is
demonstrated below. You need to use this syntax whenever you want
to assign the result of a Maxima command to a function.
Remember that '' is two separate quotation marks. Use the upright
quotation mark on your keyboard ('), not the sloping one (`). Don’t
forget to include the outer round brackets too.
Notice that this time the output line shows that df(x) is defined to
be the result of differentiating f(x).
63
9 Integration
If you began studying this section from Activity 22 of Unit 7, now return to
the unit to continue your study.
9 Integration
The Maxima command to integrate an expression is integrate. This is
demonstrated in the following activity.
As with differentiation, the results that you obtain from integrating using
Maxima might be in a different algebraic form to the expression that you
might obtain when integrating by hand. To show that the two answers are
equivalent integrals, you could find the difference between the two answers
and check that it simplifies to a constant. A rougher check is to use
Maxima to plot graphs of the two answers (taking the arbitrary constant
to be zero, for example) and check they seem to be vertical translations of
each other.
64
9 Integration
integrate(2*x∧2+exp(3*x), x);
& 3
1
(b) Evaluate the definite integral dx by entering
2 x
integrate(1/x, x, 2, 3);
The third and fourth arguments of integrate are the lower and
upper limits of integration respectively.
Notice that, as usual, Maxima returns an exact result. Use the float
command to find a decimal approximation if required.
x
(c) Define the function p(x) = , and define q(x) to be an
x2 + 1
antiderivative of p.
65
9 Integration
Integration
Operation Command Example
Integrate integrate( , variable ) integrate(x∧2,x);
(find an antiderivative)
You can practice using the integrate command in the following activity.
67
9 Integration
(iii) Enter
facts();
to see all the additional facts about variables known to Maxima.
This lists all such facts. The only one shown should be the one you
gave earlier.
(v) Type facts(); again to see all the facts now known.
68
9 Integration
69
10 Matrices
& 1
2
(c) Find an approximate value for the definite integral e−t dt.
0
If you began studying this section from Activity 47 of Unit 8, now return to
the unit to continue your study.
10 Matrices
In this section, you will learn how to use Maxima for matrices.
70
10 Matrices
(b) If you are using wxMaxima, you can also input a matrix using an
on-screen form. Use this form to assign the matrix
1 2 3 4
4 1 2 3 to the variable B as follows.
2 4 1 3
(i) From the Algebra menu select Enter Matrix...
71
10 Matrices
(ii) The matrix given above has size 3 × 4, so enter 3 as the number
of rows and 4 as the number of columns, replacing the default
values shown.
This has the effect of including a matrix input line in your worksheet,
followed by the appropriate output.
Entering matrices
Operation Command Example
Specify a matrix matrix( row , row ,...) A:matrix([1,2],[3,4]);
Note: matrices can also be entered using the Enter Matrix... option
of the Algebra menu.
Once a matrix has been input, you can obtain its size and individual
elements by using the commands demonstrated in the following activity.
72
10 Matrices
The output is a list containing the number of rows and the number of
columns of the matrix.
(b) Extract the element in the third row and second column of B by
entering
B[3,2];
(d) Change the element in the third row and second column of B to be 0
by entering
B[3,2]:0;
then display the revised matrix by entering
B;
You can use commands of this type to correct any errors that you
might make when entering a matrix.
Using matrices
Operation Command Example
Size of a matrix matrix size( matrix ) matrix size(A);
Row of a matrix matrix [ row ] A[2];
Element of a matrix matrix [ row , column ] A[3,4];
or matrix [ row ][ column ] A[3][4];
The syntax to use for matrix operations in Maxima is given in the
following box. You can practice using them in Computer activity 53.
73
10 Matrices
Matrix operations
Operation Syntax Example
Matrix addition + A+B;
where A and B are matrices of the same size
Matrix subtraction - A-B;
where A and B are matrices of the same size
Scalar multiplication * 2*A;
Matrix multiplication . A.B;
where A and B are matrices of appropriate sizes
Matrix powers ∧∧
A∧∧3;
where A is a square matrix
Warning
Remember to use . (not *) for matrix multiplication and ∧∧
(not ∧)
to find the power of a matrix.
If you use the symbol * when multiplying two matrices or the symbol
∧
to find the power of a matrix, then Maxima may return an answer,
but in general it will be the wrong answer. (It will be an answer
found using a different matrix operation.)
(c) Find P − R.
The matrices P and R are not the same size, so this calculation is not
possible. Maxima gives an error message:
fullmap: arguments must have same formal structure.
-- an error. To debug this try: debugmode(true);
74
10 Matrices
(i) Find R2 .
75
10 Matrices
(j) Enter
R∧2;
(k) Enter
P*Q;
The result is not PQ, since this product does not exist!
Here the * symbol was used and Maxima multiplied corresponding
elements of P and Q together.
76
10 Matrices
(c) Find the inverse of A, and assign the result to the variable C by
entering
C:invert(A);
Another command that is sometimes useful when you are working with
matrices is ident,
2 which
= specifies an identity matrix. For example,
1 0
ident(2) gives , the 2 × 2 identity matrix.
0 1
Matrix operations
Operation Syntax Example
Determinant (of a square matrix) determinant( matrix ) determinant(A);
Matrix inverse (of a square matrix) invert( matrix ) invert(A);
or matrix ∧∧(-1) A∧∧(-1);
Identity matrix ident( size ) ident(2);
77
11 Sequences and series
If you began studying this section from Activity 24 of Unit 9, now return to
the unit to continue your study.
This command defines the general term an of the sequence using the
same define operator (:=) as is used when defining functions.
Notice that you type the subscript n of the general term within square
brackets, but the Maxima output uses a properly formatted subscript.
78
11 Sequences and series
Notice that when you defined the sequence in Computer activity 56 you
did not need to enter the range of values of n. In fact, Maxima places no
restriction on the values of n that you can use when calculating terms in a
sequence defined by a closed form. For instance, for the sequence (an )
defined in Computer activity 56 it is possible to calculate values for
a[3.5] and a[-4] using Maxima.
However, these numbers are not terms of the sequence (an ), which are
defined only for integer values of n greater than or equal to 1.
(a) Define this sequence in Maxima by entering the two commands below.
b[1]:1;
b[n]:=2*b[n-1]+1;
Notice that you assign the value of the first term, b[1], using the :
operator that is used to assign values to variables, and you specify the
recurrence relation using the := operator that is used to define
functions.
Unlike for a sequence defined using a closed form, Maxima can
calculate a term of a sequence defined using a recurrence relation only
when the term number is an integer greater than or equal to the
starting value, which in this case is 1.
79
11 Sequences and series
The commands for defining and working with sequences are summarised as
follows.
Sequences
Operation Command Example
Define a sequence sequence [n]:= expression in n a[n]:=n∧2;
using a closed form
80
11 Sequences and series
(b) Create a list of the coordinates of the points to be plotted; that is, the
points (1, c1 ), (2, c2 ) and (3, c3 ) and assign it to a variable, say, pts
(for ‘points’), by entering
pts:[ [1,c[1]], [2,c[2]], [3,c[3]] ];
Notice that you type the coordinates of each point as a list in square
brackets. The variable pts is a list of lists.
Do not use the variable name points for your list of points – this is a
word used by Maxima to set plot styles, as you will see next.
81
11 Sequences and series
Create a list of these points, and assign the list to the variable pts,
using the command
pts:makelist([n,d[n]], n, 1, 15);
82
11 Sequences and series
(c) Plot the points in the list pts by using the command
wxplot2d([discrete, pts], [style, points], [xlabel, "n"], [ylabel, "d[n]"]);
as seen earlier.
As you know from your study of Unit 10, a sequence can have infinitely
many terms. Such a sequence is called an infinite sequence. Since
Maxima cannot plot an infinite number of points, when plotting a graph of
an infinite sequence, you need to restrict the number of points to a large,
but finite, number. Try to choose a number that is large enough to reveal
the long-term behaviour of the sequence.
If you began studying this section from Activity 17 of Unit 10, now return
to the unit to continue your study, and in particular learn about the
long-term behaviour of sequences.
83
11 Sequences and series
(a) Find the sum of the squares of the first 100 integers, that is
100
:
n2 ,
n=1
by entering
sum(n∧2, n, 1, 100);
The first argument of the sum command is the general term of the
series to be summed, which in this case is expressed in terms of the
index variable n. The second argument is the index variable itself and
the third and fourth arguments are the lower and upper limits of the
summation.
84
12 Taylor polynomials
(d) Set the system variable simpsum to have the value true by entering
simpsum:true;
∞
: 1
Now try to calculate again.
4n
n=1
:∞
1
(e) Find .
n=1
n2
Infinity
Constant Syntax Example
∞ inf sum(1/n∧2,n,1,inf);
If you began studying this section from Activity 32 of Unit 10, now return
to the unit to continue your study.
12 Taylor polynomials
You could use Maxima to find a Taylor polynomial for a function by using
the diff command to calculate the required derivatives and then
combining these to form the required polynomial. However, Maxima also
has a command for calculating Taylor polynomials more efficiently. This is
demonstrated in the following activity.
85
12 Taylor polynomials
(a) Find the cubic Taylor polynomial about π/6 for the function
f (x) = cos x, by entering
taylor(cos(x), x, %pi/6, 3);
(b) Define p to be the quintic Taylor polynomial about 0 for the function
f (x) = tan x, by entering
p(x):=''(taylor(tan(x), x, 0, 5));
(c) Express the Taylor polynomial p(x) found above in terms of the
variable y by typing
p(y);
86
13 Complex numbers
(d) Find the decimal value of p(x) when x = 0.1. Also find the difference
between p(x) and tan x at x = 0.1.
If you began studying this section from Activity 21 of Unit 11, now return
to the unit to continue your study.
13 Complex numbers
In this section you will learn how to use Maxima to work with complex
numbers.
87
13 Complex numbers
The sum and difference are displayed in simplified form, but the
product and quotient are not.
To simplify the result of a calculation and display it in Cartesian form
(or rectangular form, as Maxima calls it) use the command
rectform.
88
13 Complex numbers
Notice that the abs command is the same command that you used
earlier to find the magnitude (also called the modulus, or the absolute
value) of a real number.
The name of the carg command is short for ‘complex argument’. The
argument calculated is the principal argument, that is, the argument
in the interval (−π, π].
As you saw in Unit 12, any non-zero complex number can be expressed in
polar form r(cos θ + i sin θ), where r is the modulus and θ is one of its
arguments. The next activity uses this form.
If you began studying this section from Activity 27 of Unit 12, now return
to the unit to continue your study.
89
13 Complex numbers
(a) Use the solve command to find the solutions of the equation
z 3 + z + 1 = 0,
and assign the result to the variable solns.
(b) Express the solutions found in part (a) in Cartesian form, with each
real number, and the real and imaginary parts of each complex
number, correct to two decimal places.
(c) Find, in Cartesian form, all the solutions of
z 4 − 20z 3 + 171z 2 − 626z + 962 = 0.
You may have noticed that in Computer activity 66 all the non-real
complex solutions occur in complex conjugate pairs. In other words, for
each of the equations, if a particular non-real complex number z is a
solution, then so is its complex conjugate z. You saw in Unit 12 that this
property holds for any quadratic equation that has real coefficients. In
fact, it holds for any polynomial equation that has real coefficients. It
doesn’t hold for polynomial equations that don’t have real coefficients,
however. For example, the solutions of the polynomial equation
z 2 − 2i = 0
are 1 + i and −1 − i, which are not complex conjugates of each other.
90
13 Complex numbers
(b) Create a second list containing just the solutions of the equation
(without the z=) and assign it to the variable v, by entering
v:makelist(rhs(s[k]), k, 1, length(s));
91
13 Complex numbers
(c) Create a list of the coordinates of the points to be plotted and assign
it to the variable pts, by entering
pts:makelist([realpart(v[k]),imagpart(v[k])],k,1,length(s));
This command plots a set of discrete points. The first two arguments
of this wxplot2d command are the options that you used to plot
graphs of sequences in Subsection 11.1 of this Guide. The final two
arguments specify that the axis labels are to be left blank.
Notice that since the complex solutions of polynomial equations with
real coefficients occur in conjugate pairs, the points plotted are
symmetric about the horizontal axis.
Length of a list
Operation Command Example
Find the length of a list length( list ) length(A);
92
13 Complex numbers
If you began studying this section from Activity 35 of Unit 12, now return
to the unit to continue your study.
93
Maxima accessibility guide
Alternatively, select Configure from the Edit menu (or, on an Apple Mac,
select Preferences from the wxMaxima menu).
In the configuration window that opens, select the following ‘Style’ icon.
94
Maxima accessibility guide
You can then change the colour, style, and sometimes the font and size, of
individual elements of the wxMaxima interface by first choosing the
appropriate element from the ‘Styles’ list, and then selecting your
preferred settings.
Where a selected element has a greyed out font button this is usually
because it shares its font with other elements of the interface. For
example, those elements that form part of the mathematical output of the
interface share a font that you can change by first clicking on the Math
font ‘choose font’ button and then selecting your preferred font and size.
Most of the remaining elements with a greyed out font button share a font
that you can change in a similar way by clicking on the Default font
‘choose font’ button.
Unfortunately the Configuration window is not keyboard accessible, and so
if you only use a keyboard you may need the assistance of a non-medical
helper to initially configure the system. If you choose a large font size,
some horizontal scrolling may be necessary to read all the text displayed in
a worksheet.
The Configuration window does not change the colours and fonts used in
graphs produced by Maxima. The ‘Changing graph properties’ subsection
below explains how to change the colours, fonts and line thickness used in
graphs. You should read this subsection when you study Subsection 3.3 of
this Guide, where plotting graphs is introduced.
95
Maxima accessibility guide
Typing this additional argument each time you want to plot a graph can
be cumbersome, so you might like to assign this argument to a variable
that you can reuse. For example, to assign your preferred style to the
variable thick enter
thick: [style, [lines, 3]];
Then you can plot graphs using commands such as
wxplot2d(2*x, [x, 0, 1], thick);
To change the colour of a curve, you can include an argument of the form
[color, red] as described in Subsection 3.3. Alternatively, you can add a
further element to the styles argument described above. For example,
including
[style, [lines, 3, 5]]
produces curves with thickness 3 and colour number 5, which is black. The
colour number codes used by the style argument are given in the table
below.
style argument colour numbers
Number Colour
1 blue
2 red
3 green
4 magenta
5 black
6 cyan
Note that the value of any variable you define to help set curve properties
(such as thick above) will be lost when you close Maxima at the end of a
session unless you save your session. The style argument also only
changes properties of the curve plotted, not other aspects of the graph
such as the axes and labels.
Changing the axes and labels, and ensuring such changes are automatically
used each time Maxima is started is more complicated. A computer file is
provided in the Accessibility section of the OU Maxima website
learn1.open.ac.uk/site/maxima which you can download and configure
96
Maxima accessibility guide
to set the graph properties to your needs. These settings will then be
automatically used for each graph in every Maxima session. Details of how
to download and use this are given in the Accessibility section of the OU
Maxima website.
Using Maxima
The text you type will appear next to the input line number (%i1), as
indicated by a flashing horizontal line known as the editing cursor.
3. Press Enter .
If you forget to type the semicolon (;) at the end of the command,
the editing cursor simply moves to the next line, waiting for you to
type more. Maxima will continue to do this until you indicate you
have reached the end of the command by typing a semicolon. So if
you forgot the semicolon, then type it now and press Enter again.
Pressing Enter instructs Maxima to calculate the expression. This
is known as evaluating the expression.
The result is displayed under the input line, preceded by the label
(%o1). The o stands for ‘output’, so this label identifies the line as
output line 1. It gives the output corresponding to input line 1.
Throughout each Maxima session the line numbering starts at 1 and
then increases by one for each new input (and output).
98
Maxima accessibility guide
Maxima then displays another input line number, ready for you to
enter your next command.
You should end all Maxima commands with either a semicolon (;) (as you
saw in Computer activity 3) or a dollar sign ($). Ending a command with
a dollar sign tells Maxima to perform the instruction, but not to display
the answer.
The result of the calculation in Computer activity 3 was displayed as
formatted mathematics over several lines, replicating how mathematics is
usually written. This can, however, cause problems if you are using a
screenreader. The display behaviour can be changed for every Maxima
session as described in the following activity.
99
Maxima accessibility guide
Troubleshooting Maxima
If you are using Maxima and it does not seem to be responding, try the
following suggestions. If you encounter other problems, check the
Frequently asked questions on the OU Maxima website:
learn1.open.ac.uk/site/maxima.
Troubleshooting Maxima
If Maxima does not seem to be responding, the following might be
helpful.
• Check you have ended your previous command with either a
semicolon (;) or a dollar ($). Maxima will not do anything
without them!
• Check that Maxima is not waiting for you to type something. Is
a question being displayed that you have not yet answered?
• If Maxima is taking too long to evaluate a command, you can
interrupt it by typing Ctrl-C.
If you do this, you may see the following output, or something
similar, which you can safely ignore.
Maxima encountered a Lisp error:
Console interrupt.
Automatically continuing.
100
Maxima accessibility guide
Closing wxMaxima
When you have finished using Maxima, close it by using one of the
following methods.
• Enter quit();
• On a Windows computer, click the usual small cross button at the top
right-hand corner of the Maxima window.
In this Guide, we will use ∧ for powers. Note that many Maxima
commands take the form of a command name, such as sqrt or abs,
followed by a pair of round brackets containing one or more objects, such
as numbers, that the command operates on. Such an object is called an
argument of the command.
In the summary tables in this Guide, arguments of commands are often
represented by , as illustrated in the table above.
101
Maxima accessibility guide
Maxima generally ignores all spaces that you type while entering a
calculation or command, so you can use spaces to make a command easier
to read. You can calculate roots other than square roots, such as cube
roots, by using the index laws.
102
Maxima accessibility guide
The name of the command float arises from the fact that the method
used by computers to store decimal numbers internally using the binary
digits 0 and 1 is called a floating-point representation. The float
command instructs Maxima to convert a number stored symbolically as a
mathematical expression to one stored using a floating-point
representation.
Maxima usually displays decimal numbers to 16 significant figures (though
it suppresses trailing zeros at the end of the decimal part of a number; for
example 0.125 is displayed simply as 0.125 rather than as
0.1250000000000000). This is also the precision to which Maxima
performs decimal calculations. You will see later how to change the
number of significant figures displayed.
103
Maxima accessibility guide
For each of the following expressions, use Maxima to simplify it and then
find a decimal approximation for it.
8 92/3
√ 8
(a) 147 (b) (c) 2500
5
The expression in part (c) doesn’t involve decimal numbers and so the
result is evaluated exactly. The decimal form of the result
3.2733906078961419E+150, is given in the command-line interface’s
way of displaying scientific notation. It means
3.2733906078961419 × 10150 .
As with the input and output line labels, the ‘%’ symbol indicates the
name of a quantity built into Maxima.
Notice that in the exact answer, Maxima displays π and e in the form
they were entered: %pi and %e.
You can access all the commands you have previously entered in your
Maxima session using the up and down keyboard arrow keys.
2. Edit the expression by moving the editing cursor using the left
and right keyboard arrow keys, typing new text and using the
←− (backspace) or Delete key to make deletions.
3. Press Enter .
105
Maxima accessibility guide
Warning
You cannot use = to assign a value to a variable. This symbol is used
for equations, as you will see later.
Variable names can be any combination of letters and numbers that begin
with a letter. For example, Maxima will accept any of the following
variable names.
a A solution solution2 x2b
106
Maxima accessibility guide
(b) Enter a;
√
(c) Assign the value of a 2 to b.
√
Don’t forget to include a multiplication sign when typing a 2.
The value of b is simplified when displayed.
√ √
(d) Edit the line where you assigned 8 to a, to assign the value 7 to a.
(e) Enter b; to display the value of b.
Notice that the value of b has not changed. The variable b was
defined when a had its original value.
(f) Enter values; to list the names of all the variables that are currently
assigned values.
b is still defined.
107
Maxima accessibility guide
Notice that in Computer activity 12(e), when the value of a was changed,
the value of b was not affected, since it was defined when a had its original
value. If you want to update the value of b using a different value of a,
then you should enter a new value of a then use the up and down
keyboard arrow keys to obtain the line defining b and then press Enter
to re-evaluate it.
Working with variables
Operation Command Example
Assign a value to a variable : a:23;
Display the value of a variable variable a;
List all user assigned variables values values;
Remove an assigned variable kill( variable ) kill(a);
Remove all assigned variables kill(all) kill(all);
Note: here the placeholder variable represents any variable name.
System variables
There are some variables built into Maxima whose values affect the
behaviour of the system. These are called system variables. You met
one system variable in Computer activity 12; the variable values holds a
list of the names of all the variables you have defined.
Another system variable, fpprintprec, specifies the number of significant
figures of decimal numbers that are displayed. The name fpprintprec is
an abbreviation of ‘floating point print precision’.
To change the system behaviour so that, for example, only 4 significant
figures are displayed, use the command fpprintprec:4; to assign the
value 4 to the variable fpprintprec.
You can set the variable fpprintprec to any value between 2 and 16.
Also, setting it to 0 restores the default behaviour of displaying 16
significant figures. The value of fpprintprec sets the requested number of
significant figures, but Maxima does not always exactly meet the request.
108
Maxima accessibility guide
You can reset the values of fpprintprec and all other system variables to
their original values by using the reset() command. Try entering
reset(); followed by float(%pi); and check that the value of π is
displayed to 16 significant figures.
Resetting system variables
Operation Command Example
Reset all system variables reset() reset();
109
Maxima accessibility guide
110
Maxima accessibility guide
(ii) Enter
playback();
This command redisplays each of the input and output lines of your
session, and when used in conjunction with the writefile command
results in a copy of these lines being stored in your chosen file.
To playback only a selection of the lines from your session, you can
use a command of the form
playback([ first line number , last line number ]);
which plays back only those lines within the given range.
(iii) Enter
closefile();
111
Maxima accessibility guide
The file contains a copy of the input and output lines from your
session. (When opened in some text editors the file may appear all on
one long line.)
(b) Save your current session then reload it, by following these steps.
(i) Enter
save("C:/Users/bill/Documents/maxima/mysession.txt", all);
replacing the pathname with one appropriate to you and your
system.
This tells Maxima to restore the state of the system to that saved in
the specified file.
The error
assignment: cannot assign to gf data(characteristic,
exponent, reduction, primitive, cardinality, order,
factors of order)
-- an error. To debug this try: debugmode(true);
might be given, which can be ignored.
112
Maxima accessibility guide
(v) Enter
values;
to display the names of all known variables.
You should see that all the variables from your previous session are
known. You might like to check their values are as expected too.
113
Maxima accessibility guide
Getting help
Maxima includes commands that you can use to obtain help. These are
demonstrated in the following activity and summarised in the table that
follows.
(a) Enter ? float; to show the help for the float command.
Note the space between the ? and float, which is needed. This is one
of the few times in Maxima when spaces matter!
The help information for the command may include more detail than
you need!
After giving the help information, Maxima displays the output true.
This means that the command you entered was successful.
(b) Suppose that you cannot remember the Maxima command for square
root, but you do remember that it was something like sqr.
Type ?? sqr; to list all the help information titles that contain the
letter sequence ‘sqr’.
A list of possible titles is displayed.
Title number 1 is what you were looking for, so enter 1 to display the
relevant information.
114
Maxima accessibility guide
Help commands
Operation Command Example
Get help on a command ? command ? float;
or, describe( command ) describe(float);
115
Computer methods for CAS Activities in Books A–D
This line is ended with $ to prevent the display of the output of the
command.
(a) Assign the equation representing the parabola and the equation
representing the circle to the variables p and c respectively.
(%i3) p:y=2* x∧2-10*x+14;
(%o3) y=2 x2 -10 x+14
(%i4) c:x∧2-6*x+y∧2-8*y+22=0;
(%o4) y2 -8 y+x2 -6x+22=0
Now plot the two curves. Appropriate axis ranges are chosen to ensure
the whole of the circle is shown.
(%t5)
(%o5)
116
Computer methods for CAS Activities in Books A–D
(b) To find the points of intersection of the parabola and circle, we solve
the equations representing each simultaneously, for x and y. The
equations have previously been assigned to the variables p and c
respectively.
(%i6) solve([p,c], [x,y]);
(%o6) [[x=1.304970075461879,y=4.356193142057383],
[x=1.664051355206847,y=2.897620365246265],
[x=3.121372031662269,y=2.272207016670814],
[x=3.909606299212598,y=5.473980309423348]]
So, to 2 d.p., the four points of intersection are
(1.30, 4.36), (1.66, 2.90), (3.12, 2.27) and (3.91, 5.47).
(%t2)
(%o2)
117
Computer methods for CAS Activities in Books A–D
(c) The value of x that gives the minimum value of f (x) seems to be
about 0.6.
(d) The derivative of f can be found and assigned to df(x) as follows.
(%i3) df(x):=''(diff(f(x),x));
x 1
(%o3) df(x):= √ -
2
8 x +1 16
x 1
So the derivative of f is f ! (x) = √ − .
8 x + 1 16
2
(e) First, we try to use the solve command to find the solution of
df(x)=0.
(%i4) solve(df(x)=0);
√
x2 +1
(%o4) [x= ]
2
118
Computer methods for CAS Activities in Books A–D
(%t2)
(%o2)
119
Computer methods for CAS Activities in Books A–D
(d) The area between the graph of f and the x-axis, between the two
x-intercepts is
& 8.162... 2
x − 10x + 15
− √ dx.
1.837... 1+ x+1
So
& 8.162...
f (x) dx = −12.4 (to 3 s.f.).
1.837...
The value of the definite integral is 0.939 (to 3 s.f.). So the volume of
plastic required to make one metre of the edging is approximately 93.9 cm3 .
120
Computer methods for CAS Activities in Books A–D
Assign the coefficient matrix to the variable A, and the vector formed
by the right-hand sides of the equations to b.
(%i1) A:matrix([2,2,3],[2,3,4],[4,7,10]);
2 2 3
(%o1) 2 3 4
4 7 10
(%i2) b:matrix([2],[-1],[3]);
2
(%o2) -1
3
So we have
−1 1 1
2 2 3 1 2 −2
2 3 4 = −2 4 −1 .
4 7 10 1 −3 1
121
Computer methods for CAS Activities in Books A–D
Therefore
1 1
x 1 2 −2 2
y = −2 4 −1 −1 .
z 1 −3 1 3
This can be calculated using
(%i4) invert(A).b;
0
(%o4) -11
8
Assign the coefficient matrix to the variable A, and the vector formed
by the right-hand sides of the equations to b.
(%i6) A:matrix([3,2,1],[4,3,1],[7,5,1]);
3 2 1
(%o6) 4 3 1
7 5 1
(%i7) b:matrix([1],[2],[1]);
1
(%o7) 2
1
So we have
−1
3 2 1 2 −3 1
4 3 1 = −3 4 −1 .
7 5 1 1 1 −1
122
Computer methods for CAS Activities in Books A–D
Therefore
x 2 −3 1 1
y = −3 4 −1 2 .
z 1 1 −1 1
123
Computer methods for CAS Activities in Books A–D
(%t3)
(%o3)
124
Computer methods for CAS Activities in Books A–D
(%t6)
(%o6)
125
Computer methods for CAS Activities in Books A–D
(%t9)
(%o9)
(%t3)
(%o3)
126
Computer methods for CAS Activities in Books A–D
(%t6)
(%o6)
127
Solutions to Computer activities
128
Solutions to Computer activities
(%i6) float(2∧500);
(%o6) 3.2733906078961419 10150
So 2500 ≈ 3.2733906078961419 × 10150 .
129
Solutions to Computer activities
(b) (%i2) a;
(%o2) 23/2
(d) (%i4) a:
√ sqrt(7);
(%o4) 7
(e) (%i5) b;
(%o5) 4
(h) (%i8) a;
(%o8) a
(i) (%i9) b;
(%o9) 4
130
Solutions to Computer activities
132
Solutions to Computer activities
5-1 5+1
(%o3) [x=- , x= ]
2 2√ √
5−1 5+1
So the solutions are x = − and x = .
2 2
(ii) (%i4) float(solns);
(%o4) [x=-0.61803398874989, x=1.618033988749895]
So decimal approximations to the solutions are
x = −0.61803398874989 and x = 1.618033988749895.
(iii) (%i5) rhs(solns[1]);
√
5-1
(%o5) -
2
133
Solutions to Computer activities
(%t1)
(%o1)
134
Solutions to Computer activities
(%t2)
(%o2)
(c)
(%i3) wxplot2d( 4*x∧2-8*x+2, [x,-1,2], [y,-5,5], [color, green]);
plot2d: some values were clipped.
(%t3)
(%o3)
(%t1)
(%o1)
135
Solutions to Computer activities
(b)
(%i2) wxplot2d( [15*t∧3+10*t, 60*t], [t,0,2], [color, green, magenta]);
(%t2)
(%o2)
(c)
(%i3) wxplot2d( [15*t∧3+10*t, 60*t], [t,0,2], [color, green, magenta],
[legend, "s1", "s2"] );
(%t3)
(%o3)
136
Solutions to Computer activities
(d)
(%i4) wxplot2d( [15*t∧3+10*t, 60*t], [t,0,2], [color, green, magenta],
[legend, "s1", "s2"], [xlabel, "time, t (h)"], [ylabel, "displacement, s (km)"] );
(%t4)
(%o4)
137
Solutions to Computer activities
(%t8)
(%o8)
(%t9)
(%o9)
138
Solutions to Computer activities
(%t10)
(%o10)
139
Solutions to Computer activities
140
Solutions to Computer activities
141
Solutions to Computer activities
(%t2)
(%o2)
(%t5)
(%o5)
142
Solutions to Computer activities
(If you chose an interval other than (−2, 2) then your graph will look
different from the one given above. If, in particular, your graph does
not cross the x-axis, then you will need to plot the graph of g again
using a larger interval.)
(%i6) find root(g(x), x, 0, 1);
(%o6) 0.21356701730612
So a solution of sin2 (x + 2) = 3x is x = 0.214 (to 3 s.f.).
sin(4x)
So, = 2 cos(3x) + 2 cos(x).
sin(x)
143
Solutions to Computer activities
(%t3)
(%o3)
The two graphs appear identical, which suggests the two expressions
are equal.
(The output from this command is the location of the package on your
computer system, and may differ from that shown here.)
(b) (%i2) wximplicit plot(x∧2+y∧2=1, [x,-2,2], [y,-2,2]);
(%t2)
(%o2)
144
Solutions to Computer activities
(%t1)
(%o1)
(%t2)
(%o2)
145
Solutions to Computer activities
(%t3)
(%o3)
146
Solutions to Computer activities
(%t1)
(%o1)
(%t2)
(%o2)
147
Solutions to Computer activities
(%t3)
(%o3)
(%t4)
(%o4)
148
Solutions to Computer activities
(%t5)
(%o5)
(f)
(%i6) wximplicit plot((x∧2+y∧2-1)∧3=x∧2*y∧3, [x,-2,2], [y,-2,2]);
(%t6)
(%o6)
149
Solutions to Computer activities
(%i3) diff(p,t);
2t 4 t2 cos(4 t)
(%o3) -
sin(4 t) sin(4 t)2
t2 2t 4t2 cos (4t)
So the derivative of is − .
sin(4t) sin(4t) sin2 (4t)
(c) (%i4) g(u):=(u∧2+3)*log(u∧2);
(%o4) g(u):=(u2 +3)log(u2 )
(%i5) diff(g(u),u);
2(u2 +3)
(%o5) 4 u log(u)+
u + $
2 2
2 u2 + 3
So the derivative of (u + 3) ln(u ) is 4u ln (u) + .
u
(d) (%i6) diff(p,t,2);
16 t2 2 16 t cos(4 t) 32 t2 cos(4 t)2
(%o6) + − +
sin(4 t) sin(4 t) sin(4 t)2 sin(4 t)3
t2
So the second derivative of is
sin(4t)
16t2 2 16tcos (4t) 32t2 cos2 (4t)
+ − + .
sin (4t) sin (4t) sin2 (4t) sin3 (4t)
(e) (%i7) diff(g(u),u,3);
4 (u2 +3)
(%o7)
u3 + $
2 2
4 u2 + 3
So the third derivative of (u + 3) ln(u ) is .
u3
150
Solutions to Computer activities
151
Solutions to Computer activities
(%i5) q(x):=''(integrate(p(x),x));
log(x2 +1)
(%o5) q(x):=
& 2
ln(x2 + 1)
So p dx = + c.
2
152
Solutions to Computer activities
153
Solutions to Computer activities
So
& 8 9
1 1 x
2
dx = √ tan−1 √ + c,
x +a a a
where a > 0.
154
Solutions to Computer activities
& 1
2
So e−t dt = 0.747 (to 3 s.f.).
0
155
Solutions to Computer activities
(d) (%i6)B[3,2]:0;
(%o6)0
(%i7)B;
1 2 3 4
(%o7) 4 1 2 3
2 0 1 3
(%i2)
Q:matrix([0,3],[5,-4],[1,3]);
0 3
(%o2) 5 -4
1 3
(%i3) R:matrix([1,3],[2,4]);
2 =
1 3
(%o3)
2 4
(%i4) S:matrix([1],[2]);
2 =
1
(%o4)
2
(%i5) T:matrix([3,4]);
3 <
(%o5) 3 4
156
Solutions to Computer activities
157
Solutions to Computer activities
(j) (%i14) R
2 2; =
∧
1 9
(%o14)
4 16
8 9
1 9
Maxima returns the matrix whose elements are the squares
4 16
of corresponding elements of R.
(k) (%i15) P*Q;
0 0
(%o15) 15 4
-4 18
0 0
Maxima returns the matrix 15 4 whose elements are the
−4 18
products of corresponding elements of P and Q.
We have
2 −1 1
det 2 0 1 = −2,
4 2 1
so this matrix is invertible.
Now find the inverse.
(%i3) invert(A);
1 - 32 21
(%o3) -1 1 0
-2 4 -1
−1 1
2 −1 1 1 − 32 2
So 2 0 1 = −1 1 0 .
4 2 1 −2 4 −1
(b) Again, first enter the matrix and calculate the determinant.
(%i4) B:
matrix( [-1,0,3,-2],
[4, 1/2, -1 ,0], [2,0,1,-1],[-1,2,1,-1]);
-1 0 3 -2
4 1 -1 0
(%o4) 2
2 0 1
-1
-1 2 1 -1
(%i5) determinant(B);
1
(%o5) -
2
159
Solutions to Computer activities
We have
−1 0 3 −2
4 1 −1 0
det 2 = −1,
2 0 1 −1 2
−1 2 1 −1
so this matrix is invertible.
Now find the inverse.
(%i6) invert(B);
-4 -4 7 1
-6 -6 10 2
(%o6)
-19 -20 33 5
-27 -28 46 7
−1
−1 0 3 −2 −4 −4 7 1
4 1 −1 0 −6 −6 10 2
So 2
2 0
= .
1 −1 −19 −20 33 5
−1 2 1 −1 −27 −28 46 7
160
Solutions to Computer activities
(c)
(%i3) wxplot2d([discrete, pts], [style, points], [xlabel, "n"], [ylabel, "c[n]"]);
(%t3)
(%o3)
161
Solutions to Computer activities
(c)
(%i4) wxplot2d([discrete, pts], [style, points], [xlabel, "n"], [ylabel, "d[n]"]);
(%t4)
(%o4)
(%t4)
(%o4)
The terms of the sequence seem to be getting closer and closer to the
value 5.
162
Solutions to Computer activities
(%t7)
(%o7)
(%t10)
(%o10)
163
Solutions to Computer activities
164
Solutions to Computer activities
165
Solutions to Computer activities
(%t3)
(%o3)
166
Solutions to Computer activities
(%i2) d:4*(cos(7*%pi/13)+%i*sin(7*%pi/13));
8 8 9 8 99
7π 7π
(%o2) 4 %i sin + cos
13 13
167
Solutions to Computer activities
(%i6) trigreduce(%);
12π
(%o6)
13
12π
So, |c*d| = 12 and Arg(c*d) = .
13
Similar methods can be used to find the modulus and principal
argument of c/d.
(%i7) abs(c/d);
7 8 92 8 92
5π 5π
3 sin +cos
13 13
(%o7) 7 8 92 8 92
7π 7π
4 sin +cos
13 13
(%i8) trigreduce(%);
3
(%o8)
4
(%i9) carg(c/d);
8 9 8 9
7π 5π
sin 13 sin 13
(%o9) -atan
8 9 +atan 8 9 +π
7π 5π
cos cos
13 13
(%i10) trigreduce(%);
24π
(%o10)
13
168
Solutions to Computer activities
(c)
(%i3) pts:makelist([realpart(v[k]),
√ √ √ imagpart(v[k])],
√ k, 1, length(s));
25/2 +4 25/2 -4 25/2 +4 25/2 -4
(%o3) [[- , -1], [ , - -1],
23/2 23/2 23/2 23/2
√ √ √ √
25/2 +4 25/2 -4 25/2 +4 25/2 -4
[- , 1- ], [ , +1]]
23/2 23/3 23/2 23/2
169
Solutions to Computer activities
(d)
(%i4) wxplot2d([discrete,pts], [style,points], [xlabel,""], [ylabel,""]);
(%t4)
(%o4)
4 %i π 2 %i π
- -
z=%e 7 , z=%e 7 , z=1]
The solutions are given in terms of exponential functions. You will
learn about the exponential form of complex numbers in Section 4 of
Unit 12.
The solutions can be written in Cartesian form as follows.
(%i2) float(rectform(s));
(%o2) [z=0.78183148246803 %i+0.62348980185873,
z=0.97492791218182%i-0.22252093395631,
z=0.43388373911756%i-0.90096886790242,
z=-0.43388373911756%i-0.90096886790242,
z=-0.97492791218182%i-0.22252093395631,
z=0.62348980185873-0.78183148246803%i, z=1.0]
So, to two decimal places, the seven seventh roots of unity are
z = 0.62 + 0.78i, z = −0.22 + 0.97i, z = −0.90 + 0.43i,
z = −0.90 − 0.43i, z = −0.22 − 0.97i, z = 0.62 − 0.78i
and z = 1.00.
170
Solutions to Computer activities
(%t5)
(%o5)
Notice that the complex solutions occur in conjugate pairs, and hence
lie symmetrically about the horizontal axis. The solutions also lie on
the unit circle (which does not seem circular here due to the different
axis scales used).
171
Maxima reference guide
172
Maxima reference guide
173
Maxima reference guide
Maxima commands
Operation Command Example
Get help on a command ? command ? float;
or, describe( command ) describe(float);
Find help information whose ?? ?? flo;
title contains the given text or, describe( , inexact) describe(flo, inexact);
174
Maxima reference guide
175
Maxima reference guide
Set the default plotting options set plot option( option ) set plot option(
[gnuplot preamble,
"set size ratio -1"]);
Differentiate diff( , variable ) diff(sin(x∧2),x);
Differentiate multiple times diff( , variable , diff(log(x),x,3);
positive integer )
Integrate integrate( , variable ) integrate(x∧2,x);
(find an antiderivative)
Evaluate a definite integral integrate( , variable , integrate(sin(x),x,0,1);
lower limit , upper limit )
Find an approximate value quad qags( , variable , quad qags(exp(-x∧2),x,0,1);
of a definite integral lower limit , upper limit )
176
Maxima reference guide
177
Maxima reference guide
Maxima packages
Maxima package Functions added
implicit plot Plotting curves given by equations in implicit form
178
Acknowledgements
179
Acknowledgements
Acknowledgements
Grateful acknowledgement is made to the following sources:
Every effort has been made to contact copyright holders. If any have been
inadvertently overlooked the publishers will be pleased to make the
necessary arrangements at the first opportunity.
180
Index
Index
abort calculation 14 complex numbers 34, 87
using command-line interface 100 Cartesian form 88
abs 15 argument (principal) 88
for complex numbers 89 conjugate 88
using the command-line interface 101 imaginary part 88
absolute value 15 modulus 88
using the command-line interface 101 polar form 89
accessibility 94 real part 88
acos 47 computer algebra system 5
addition 15 configure wxMaxima 13, 16
of matrices 74 conjugate 89
using the command line interface 101 conjugate of a complex number 88
approximation copy 20
numerical 50 cos 47
argument of a command 15 cosec 47
using command-line interface 101 cot 47
argument of a complex number 88 create a list using makelist 83
asin 47 csc 47
assign 21 cube roots 16
using command-line interface 106 using command-line interface 102
assume 68 cursor
assumption editing 19
about a variable 68 using command-line interface 98
equals 68 horizontal 20
forget 68
list all 68 decimal approximation 17
not equals 68 using command-line interface 103
atan 47 define see assign
definite integral 64
approximate value 69
carg 89 delete
Cartesian form of a complex number 88 function 43
CAS see computer algebra system variable 23
cell 12 variable, using command-line interface 108
marker 11, 12 derivative 60
changing a sequence 80 assign to function 63
circles second, third 61
plotting 55 determinant 76
closed form of a sequence 78 determinant of a matrix 76
closing the command-line interface 101 diff 60
closing wxMaxima 15 differentiate 60
command-line interface 8, 97 division 15
input line number 98 using the command line interface 101
closing Maxima 101
editing cursor 98 editing commands 19
evaluating an expression 98 using command-line interface 104
interrupt 100 editing cursor 19
output line number 98 using command-line interface 98
plotting graphs 115 element
reusing commands 104 index 35
saving work 110 of a list 35
scientific notation 104 of a matrix 73
181
Index
equal 68 help 29
equals 33 command-line interface 113
assumption 68 horizontal cursor 20
equations 33
changing the subject 37 ident 77
left-hand side 33 identity matrix 77
manipulating 36 imaginary numbers 34
plotting 38 imaginary part of a complex number 88
rearranging 37 imagpart 89
right-hand side 33 implicit plot package 55
simultaneous 37 indefinite integral 64
solving 33 index (of a list) 35
solving numerically 50 inf 85
trigonometric 49 infinite sequence 83
erf 66 infinity 85
evaluate input line number 11
an expression 11 using command-line interface 98
force command to 64 input prompt 11
using command-line interface 98 inputting matrices 70
exp 45 integral 64
expand 32 definite 64
expanding brackets 32 definite, approximate value 69
exponentials 44 indefinite 64
integrate 64
integrate 64
factor 32
interfaces 7
factorising 32
command-line 8, 97
facts see assumption
wxMaxima 7, 9
facts 68
interrupt calculation 14
file types 27
using command-line interface 100
find root 50
inverse of a matrix 76
float 17
inverse trigonometric functions 47
using command-line interface 103
invert 76
forget 68
forget assumption 68 keyword 39
fpprintpres 24 kill 23
using command-line interface 108 using command-line interface 108
front-ends 7
fullratsimp 32 left-hand side (of an equation) 33
functions 41 legend 39
delete 43 length 92
trigonometric 47 length of a list 92
trigonometric, inverse 47 lhs 33
functions 43 line number
input 11
gamma incomplete 67 using command-line interface 98
gnuplot 56 output 12
graphs using command-line interface 98
using command-line interface 115 list 35
colour 39 assumptions 68
legend 39 create using makelist 83
plotting 38 element of 35
vertical range 39 index 35
length of 92
182
Index
load 55 plotting
loading packages 55 changing default behaviour 57
log 45 circles 55
logarithms 44 complex numbers 91
equations in implicit form 55
graphs 38
magnitude 15 points 80
using the command-line interface 101 sequences 80
makelist 83 using command-line interface 115
manipulating using equal scales 56
equations 36 point, plotting 80
trigonometric expressions 53 polar form of a complex number 89
mathematical operations 15 polynomial, Taylor 85
using the command-line interface 101 powers 15
matrix 70 matrix 74
addition 74 using the command-line interface 101
determinant 76 principal argument of a complex number 88
element 73 printing 28
identity 77 using command-line interface 110
input 70 prompt 11
inverse 76
multiplicaton 74 quad qags 70
powers 74 quadrature 70
row 73 re-evaluating a worksheet 21
scalar multiplication 74 real part of a complex number 88
size 73 realpart 89
subtraction 74 rearranging an equation 37
matrix 70 rectform 89
matrix size 73 recurrence relation for a sequence 79
menus 10 reset 24
modulus of a complex number 88 using command-line interface 109
multiplication 15 resetting system variables 24
matrix 74 using command-line interface 109
scalar and matrix 74 reusing commands 19
using the command line interface 101 using command-line interface 104
revising a sequence 80
rhs 33
not equals right-hand side (of an equation) 33
assumption 68 roots
notequal 68 cube 16
numerical approximation to a solution 50 cube, using command-line interface 102
numerical solution 50 square 15
square, using the command-line interface 101
row of a matrix 73
output line number 12
using command-line interface 98 saving your work 27
using command-line interface 110
scalar multiplication
packages 55 matrix 74
implicit plot 55 scientific notation 18
loading 55 using command-line interface 104
paste 20 screenshot 28
plot2d 38 using command-line interface 113
using command-line interface 115 sec 47
183
Index
184