0% found this document useful (0 votes)
195 views184 pages

MST124 Computer Algebra Guide

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
195 views184 pages

MST124 Computer Algebra Guide

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 184

MST124

Essential mathematics 1

Computer algebra guide


This publication forms part of an Open University module. Details of this and other
Open University modules can be obtained from the Student Registration and Enquiry Service, The
Open University, PO Box 197, Milton Keynes MK7 6BJ, United Kingdom (tel. +44 (0)845 300 6090;
email [email protected]).
Alternatively, you may visit the Open University website at www.open.ac.uk where you can learn
more about the wide range of modules and packs offered at all levels by The Open University.
To purchase a selection of Open University materials visit www.ouw.co.uk, or contact Open
University Worldwide, Walton Hall, Milton Keynes MK7 6AA, United Kingdom for a brochure
(tel. +44 (0)1908 858779; fax +44 (0)1908 858787; email [email protected]).

The Open University, Walton Hall, Milton Keynes, MK7 6AA.


First published 2014.
c 2014 The Open University
Copyright !
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, transmitted
or utilised in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without
written permission from the publisher or a licence from the Copyright Licensing Agency Ltd. Details of such
licences (for reprographic reproduction) may be obtained from the Copyright Licensing Agency Ltd, Saffron
House, 6–10 Kirby Street, London EC1N 8TS (website www.cla.co.uk).
Open University materials may also be made available in electronic formats for use by students of the
University. All rights, including copyright and related rights and database rights, in electronic materials and
their contents are owned by or licensed to The Open University, or otherwise used by The Open University as
permitted by applicable law.
In using electronic materials and their contents you agree that your use will be solely for the purposes of
following an Open University course of study or otherwise as licensed by The Open University or its assigns.
Except as permitted above you undertake not to copy, store in any medium (including electronic storage or
use in a website), distribute, transmit or retransmit, broadcast, modify or show in public such electronic
materials in whole or in part without the prior written consent of The Open University or in accordance with
the Copyright, Designs and Patents Act 1988.
Edited, designed and typeset by The Open University, using the Open University TEX System.
Printed in the United Kingdom by Latimer Trend and Company Ltd, Plymouth.

SUP 03061 0
1.1
Contents

Contents
Introduction 5

1 Installing Maxima 7

2 Getting started with Maxima and wxMaxima 9


2.1 Using wxMaxima 9
2.2 Basic calculations using Maxima 15
2.3 Reusing and editing commands 19
2.4 Assigning values to variables 21
2.5 System variables 24
2.6 Annotating your wxMaxima worksheet 25
2.7 Saving and printing your work 27
2.8 Getting help 29

3 Algebra 30
3.1 Algebraic manipulations 31
3.2 Equations and their solutions 33
3.3 Plotting graphs 38

4 Functions 41

5 Exponential functions and logarithms 44


6 Trigonometry 47

7 Plotting circles 55

8 Differentiation 60

9 Integration 64
10 Matrices 70
10.1 Matrix algebra 70
10.2 Determinants and inverses 76

11 Sequences and series 78


11.1 Plotting graphs of sequences 78
11.2 Summing series 84

12 Taylor polynomials 85

13 Complex numbers 87
13.1 Working with complex numbers 87
13.2 Solving polynomial equations 90

Maxima accessibility guide 94


Contents

Computer methods for CAS Activities in Books A–D 116

Solutions to Computer activities 128

Maxima reference guide 172

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.

Maxima’s origins lie in a system called Macsyma, a well-respected


computer algebra system first developed in the late 1960s at the
Massachusetts Institute of Technology and funded by the United
States Department of Energy. From 1982 until his sudden death in
2001, William (Bill) Schelter, a professor of mathematics at The
University of Texas at Austin, maintained a version of Macsyma
which we now know as Maxima. In 1998 he obtained permission from
the Department of Energy for the system to be made freely available William Schelter (1947–2001)
to all. Maxima is now dedicated to his memory.

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

Select Either click to select an option, Either click to select an option,


or select text by dragging the cursor over or select text by dragging the cursor over
the text while pressing the left mouse button the text while pressing the mouse 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.

On some computer keyboards the Enter key might be labelled Return ,


or simply ← , and the Shift key might be labelled ⇑ .
In this Guide, these keys are referred to as Enter and Shift ,
respectively.
Sometimes Enter and Return are two separate keys. For such keyboards
references in this Guide to the Enter key should be interpreted as
references to the Return key.

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.

Figure 1 Different interfaces for Maxima


This Guide concentrates on using Maxima on a Microsoft Windows
personal computer through the wxMaxima interface, which is shown in
Figure 2. This is the interface that you are recommended to use. (The
letters ‘wx’ in the name of this interface refer to the software used to
create it.)

Figure 2 The wxMaxima interface


If you need to use an interface other than wxMaxima, for example, if you
are not using a Windows computer and you are unable to install

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.

Figure 3 The command-line interface to Maxima


Before you can use Maxima, you need to install it on your computer. You
will do this in the next activity.

Computer activity 1 Installing Maxima

(a) Go to the OU Maxima website at learn1.open.ac.uk/site/maxima


and follow the instructions there to download and install Maxima on
your computer. (You can also find a link to the OU Maxima website
on the MST124 website.)
(b) Create a folder on your computer in which to store your Maxima work
for this module. You might like to put this on your computer desktop,
or in your usual documents area.

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

2 Getting started with Maxima and


wxMaxima
In this section you will learn about the basics of the wxMaxima interface
and how to use it to perform simple calculations with Maxima.
If you encounter unexpected problems when working through this section,
remember to check the Frequently asked questions (FAQ) section on the
OU Maxima website: learn1.open.ac.uk/site/maxima.
If you are using the command-line interface you should not study this
section, but study the alternative material in the ‘Maxima accessibility
guide’ (see page 94) instead. If you are using another interface, you should
make sure that you can achieve similar outcomes with that interface.

2.1 Using wxMaxima

Computer activity 2 Starting 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.

The wxMaxima interface to Maxima, illustrated in Figure 4, consists


mainly of a large white working area (called the worksheet) where you
can type Maxima commands. These commands either instruct Maxima to
perform calculations or change system settings.

9
2 Getting started with Maxima and wxMaxima

Figure 4 The initial wxMaxima window


When the software first starts, a secondary window showing the ‘Tip of the
Day’ is also displayed. You can close it by clicking the ‘Close’ button. If
you want to prevent this window from appearing the next time you start
wxMaxima, click the box in its bottom left-hand corner, so that it is no
longer ticked, before clicking ‘Close’. (You can always reinstate these
messages at any time by selecting Show tips from the Help menu.)
Along the top of the main window (or along the top of the screen in the
case of an Apple Mac) is a list of menu names, including the File menu
which allows you to save or print your work and re-open previously saved
sessions (there is more on this later). You can also close the software from
the File menu by selecting Exit. (On an Apple Mac you can do this by
selecting Quit wxMaxima from the wxMaxima menu.)
Below the row of menu names is a bar called the toolbar, containing a set
of icons that provide shortcuts to commonly-used functions.
At the bottom right-hand corner of the wxMaxima window is a message
that indicates the current status of the Maxima system. When Maxima is
waiting for instructions from you this reads ‘Ready for user input’. Other
possible messages include ‘Maxima is calculating’, or ‘Reading Maxima
output’.
The following activity shows you how to use wxMaxima to perform a
simple calculation. Follow the steps using wxMaxima as you read the
activity.

10
2 Getting started with Maxima and wxMaxima

Computer activity 3 Your first Maxima calculation

Follow these steps to use Maxima to calculate 2 + 3 × 45 .


1. Click anywhere on the large white area of the wxMaxima window, to
ensure that the text you type next is directed to the correct place.
2. Type the following exactly as it appears here:
2+3*4/5;
including the semicolon (;) at the end.

Notice that as you type your command, it is shown in


wxMaxima preceded by a red arrow: -->. This is the input prompt
and shows where commands can be typed.
To the left of the input prompt is the cell marker

which will be described in more detail later.

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 .)

If you make a mistake, try clicking elsewhere on the workspace, below


your error, and try again.
Pressing Shift-Enter instructs wxMaxima to send the expression to
Maxima to calculate. This is known as evaluating the expression.
The input prompt (-->) is now replaced by (%i1). This is how
Maxima labels lines. The i stands for ‘input’: this is input line
number 1. The percentage symbol (%) is used by Maxima to indicate
objects built into the system. You will learn more about this later.
The status in the bottom right-hand corner of the window first
changes to ‘Maxima is calculating’, then ‘Reading Maxima output’,
before the result of the calculation is displayed, as shown below.
This may take a little time for the first calculation in any session.

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.

Figure 5 The wxMaxima cell marker


The top part of the cell marker (between the upper two horizontal marks)
corresponds to the input line, and the bottom part corresponds to the
output line. The cell marker turns red while an input line is being edited,
and is shown surrounded by a box while the cell is being evaluated, as
illustrated in Figure 6.

Figure 6 The cell marker during evaluation

12
2 Getting started with Maxima and wxMaxima

Computer activity 4 Using cell markers

1. Click on the triangle at the top of the cell marker.

This collapses the cell to a single line. This can be useful if a


calculation or result is very long and so makes the worksheet difficult
to read.
The triangle at the top of the cell marker becomes filled.

2. Click the filled triangle at the top of the cell marker.

This expands the cell again.

3. Click part of the cell marker other than the top triangle to highlight
it, then press the Delete keyboard key.

This deletes the cell from the worksheet.

In Computer activity 3, you used Shift-Enter rather than Enter to


instruct Maxima to evaluate expressions, and the input prompt (-->)
appeared only once you started typing. Both these behaviours can be
disconcerting, but can be changed, as described in Computer activity 5. It
is recommended that you configure wxMaxima to work in this modified
way, and in the remainder of this Guide it is assumed that you have done
so.

Computer activity 5 Configuring wxMaxima

1. From the Edit menu, select Configure (or on an Apple Mac


computer, from the wxMaxima menu, select Preferences).
Alternatively, click the following icon on the toolbar.

This opens the ‘wxMaxima configuration’ window.

2. Tick the ‘Enter evaluates cells’ box in the Configuration window by


clicking it.

13
2 Getting started with Maxima and wxMaxima

This changes the behaviour so that pressing Enter alone evaluates


commands.

3. Tick the ‘Open a cell when Maxima expects input’ box in the
Configuration window by clicking it.

This ensures that the input prompt is shown whenever


Maxima is waiting for input.

4. Click ‘OK’ (or close the window if using an Apple Mac).

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: Maxima is calculating Maxima is evaluating a command that is


taking a long time to complete.

Boxed: Ready for user input Maxima is waiting for you to type
something before continuing.

In either case you might wish to abort the


command in one of the following ways.

• Click on the toolbar.


• Select Interrupt from the Maxima menu.
• Type Ctrl-G (on an Apple Mac hold
down the command key while pressing . ).
Maxima might take some time to respond to
this request.

Maxima process terminated Maxima (but not the wxMaxima interface)


has stopped working.
Select Restart Maxima from the Maxima
menu.

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.

2.2 Basic calculations using Maxima


In Computer activity 3 you were asked to enter a numerical expression into
Maxima using the symbols + for addition, * for multiplication and / for
division. Maxima evaluated it using the rules for the correct order of
mathematical operations; that is, the BIDMAS rules. The way in which a
calculation or a command has to be entered in Maxima is known as its
syntax.
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. When using wxMaxima, if you forget to finish your command with
a semicolon or dollar sign, then the system will add a semicolon for you.
The Maxima syntax for basic mathematical operations is summarised as
follows.
Basic mathematical operations
Operation Syntax Example
Addition + 4+3;
Subtraction - 4-3;
Multiplication * 4*3;
Division / 4/3;
Brackets ( and )
2*(3+4);
Powers, for example 23 ∧
or **
2∧3;
√ 2**3;
Square root, for example 5 sqrt( ) sqrt(5);
Magnitude (absolute value) abs( ) abs(-3);

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

arguments of commands are often represented by , as illustrated in the


previous table.

Warning: Do not omit multiplication signs!


A common error when first using Maxima is to omit multiplication
signs. For example, you might type
• 2sqrt(2) rather than 2*sqrt(2), or
• 2(3+4) rather than 2*(3+4).
Doing this will result in an error. The displayed error message might
include one of the following statements:
• parser: incomplete number; missing exponent?
• incorrect syntax: Syntax error
incorrect syntax: Too many )’s
incorrect syntax: Premature termination of input at ;.
• ... is not an infix operator
If you receive one of these error messages, first check for missing
multiplication signs!

Warning: Take care with question marks (?)


Do not type question marks when asking Maxima to evaluate an
expression. The symbol ? is a special symbol in Maxima which
provides access to underlying systems.
The one exception to this is when you are using the commands for
obtaining help from the system, which you will see in Subsection 2.8.

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

Computer activity 6 Calculating cube roots


√ 1 √
(a) Remembering that 3 27 = 27 3 , calculate 3 27 by entering the
following line into Maxima.
27∧(1/3);

Remember to press Enter to evaluate the command.

(b) What happens if you enter


27∧1/3;
instead? Can you explain this?

Maxima usually tries to calculate quantities exactly rather than


approximating them by decimal numbers. It does this by manipulating the
symbols in the expression according to the rules of mathematics. This is
sometimes known as symbolic computation. You can see an example of
this in the next activity, which also shows you two different ways to
instruct Maxima to output a decimal answer instead.

Computer activity 7 Obtaining exact and approximate answers

In Maxima, calculate 1309/3451 in three different ways, by entering each


of the following expressions in turn.
(a) 1309/3451; (b) 1309.0/3451; (c) float(1309/3451);

Maxima returns an exact answer for part (a).


Since part (b) involves a decimal number, 1309.0, Maxima returns a
decimal approximation to the answer.
In part (c), the command float instructs Maxima to return a
decimal answer.

Converting to decimal numbers


Operation Command Example
Convert to a decimal number float( ) float(sqrt(2));

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

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 in Subsection 2.5 of this Guide
how to change the number of significant figures displayed.

Computer activity 8 Simplifying and approximating numerical


expressions

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 .

Maxima knows the values of standard mathematical constants such as the


irrational numbers e and π. It treats them symbolically unless you
explicitly ask for them in floating point form.
The constants e and π
Constant Syntax Example
e %e %e∧2;
π %pi 2*%pi;

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

Computer activity 9 Working with built-in constants


π
Use Maxima to calculate the value of the expression π + + e2 , both
3
exactly and as a decimal number.

Notice that in the exact answer, %pi is displayed as π, but %e is


unchanged.

2.3 Reusing and editing commands


In Computer activity 9, you may have entered the expression twice, once
to evaluate it exactly and once for a decimal answer. This is, however, not
necessary. When you have entered and evaluated an expression, you can
edit it and then evaluate it again, as shown in the following activity.

Computer activity 10 Editing a command


√ √
(a) Calculate 2 3 + 5 27 by entering the following line into Maxima.
2*sqrt(3)+5*sqrt(27);
√ √
(b) Edit your entry in part (a) to calculate 2 3 − 5 27 as follows.
1. Click on the expression you entered in part (a), or move to it
using the up and down keyboard arrow keys.

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.

2. Edit the expression by typing new text and using the ←−


(backspace) or Delete key to make deletions.
3. Press Enter .

Pressing Enter re-evaluates the cell. When a cell is re-evaluated in


this way, the input and output line numbers are updated as if a new
cell had been added.

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.

Figure 7 The wxMaxima horizontal cursor


In wxMaxima, you can also copy and paste expressions, or parts of
expressions, as you might copy and paste when using other software; that
is, using Copy and Paste from the Edit menu, or the Ctrl-C and Ctrl-V
keyboard shortcuts.
Maxima also permits the result of one calculation to be used in another
calculation. The symbol % represents the result of the last cell evaluated.
Due to the updating of cell numbers noted above, this might not be the
last cell in the worksheet, but it will be the cell with the highest line
numbers. So, for example, if you enter sqrt(%); Maxima calculates the
square root of the last evaluated output. You can also use the output (or
input) of other cells, by typing the cell line label in a calculation. For
example, if you enter %o5∧3; Maxima calculates the cube of the expression
in output line 5.

Computer activity 11 Using and editing previous calculations with


wxMaxima
(a) Enter 6+2; into a cell at the bottom of your worksheet to evaluate it.
(b) On the following line type 3+%; and enter it.

Maxima returns 11, the sum of 3 and the previous answer.

(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.

This re-evaluates all visible cells in the worksheet, in the order in


which they appear, updating all the line numbers as it does.
Notice that the result of 3+%; has now changed. At the time it was
re-evaluated the symbol % represented the value of the last evaluation,
which was the revised version of the previous line.

(e) In a new cell at the bottom of your worksheet enter %o +5;


with replaced by the output line number corresponding to the result
of 6*2 entered earlier.

This command adds 5 to the result of the line referenced.

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.

2.4 Assigning values to variables


Maxima allows you to assign a value to a variable, and then use the
variable in further calculations.
For example, you can assign the value 23 to the variable a, and then
evaluate an expression in a, such as a2 − 3a + 2. You can also assign
expressions, both numerical and (as you will see later) algebraic, and
indeed any other Maxima object, to a variable, and use that variable in
subsequent commands.
To assign a value to a variable you use a colon (:). For example, the
command
a:23;
assigns the value 23 to the variable a. The colon can be read as ‘is
assigned the value’.

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

Variable names are case-sensitive; for example, the variable x is different


from the variable X. If a variable name is the name of a Greek letter, then
wxMaxima will display it in output lines as the proper Greek character; for
example, the variable alpha will be displayed as α.
Once a variable has been assigned a value, Maxima will remember this
value for the rest of your session. This may sometimes surprise you. It is
easy to forget that earlier in the day you assigned a value to, say, x; you
may then be confused later on when a calculation involving x gives an
unexpected result. You can, however, tell Maxima to ‘forget’ about a
variable to which you have previously assigned a value. You can also ask it
to list all the variables that you have assigned values to. These commands
are demonstrated in the following activity.

Computer activity 12 Working with variables



(a) Assign the value of 8 to the variable a by entering
a: sqrt(8);

The value of a is displayed as output, in an equivalent form.

(b) Enter a;

This displays the current value of 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

(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.

The variable names are given within square brackets, separated by


commas. This is how Maxima displays lists.

(g) Enter kill(a); to remove the variable a from the system.

You should obtain the output done .

(h) Enter a; to display the value of a.

The variable name is output, as a no longer has a value.

(i) Enter b; to display the value of b.

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 practise using variables in the following activity.

Computer activity 13 Using variables

(a) Define the variable a to have the value 42.


(b) Define the variable b to be equal to a3 − 3a + 4.
(c) Define the variable c to be the decimal approximation of the square
root of b.

2.5 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.

Computer activity 14 Displaying a specified number of significant


figures

Display the decimal approximation of π to 8 significant figures by doing


the following.
(a) Set the system variable fpprintprec to be 8.
(b) Display the decimal approximation of π.

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

Resetting system variables


Operation Command Example
Reset all system variables reset() reset();

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.

2.6 Annotating your wxMaxima worksheet


It is important to be able to clearly explain and present your mathematical
work, both so that someone else can understand it, and so you can
understand what you have done if you return to your work after some
time. To help you do this, wxMaxima allows you to enter text comments
within your worksheet, as illustrated in Figure 8.

Figure 8 Adding text to a wxMaxima worksheet

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.

Computer activity 15 Including text in a worksheet

(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

2.7 Saving and printing your work


After working with Maxima you will probably want to save your
calculations so that you can reuse or read them at a later date. You can do
this in wxMaxima using the Save or Save As options from the File menu.
There are three different formats in which you can save your work. These
are as follows.
• wxMaxima document, with the .wxm file type. This saves all your
input but not any calculated output. You have to recalculate the
output when you re-open the file.
• wxMaxima xml document, with the .wxmx file type. This saves all
the input and the output.
• Maxima batch file, with the .mac file type. This is for more
experienced users of Maxima.

It is recommended that you save your wxMaxima work as a


wxMaxima xml document, with the .wxmx file type.

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.

Computer activity 16 Saving your work

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

(d) Open your worksheet in wxMaxima again, either by


(i) double clicking on the file you just saved, or
(ii) following the steps below:
• Start wxMaxima again.
• Select Open from the File menu. Maxima will ask if you
want to save your just opened, blank worksheet. Click ‘No’.
• Find the file containing your work and click ‘Open’.

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

2.8 Getting help


There are several ways in which you can obtain help with using Maxima,
beyond this Guide.
In wxMaxima, you can access the complete Maxima manual by selecting
Maxima Help from the Help menu. This opens the window shown in
Figure 9. You can use the Contents, Index and Search tabs to look for the
information that you want.

Figure 9 The Maxima help system


Maxima also includes commands that you can use to obtain help. These
are demonstrated in the following activity and summarised in the table
that follows.

Computer activity 17 Getting help!

(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.

If more than one title is displayed in response to a ?? command, then


Maxima will not continue until you enter one of the following:
• the appropriate number, to display your chosen information
• several numbers, separated by spaces, to see help information
on several topics
• all to display the information on all topics listed, or
• none to see no information.
A box will be shown around the cell marker while Maxima is waiting
for your response.

Help 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);

Note 1 : the space after the ? is needed.


Note 2 : the second pair of commands displays a list of the titles of all
help information pages whose title contains the given text. To obtain
help on a particular topic listed, type the number corresponding to the
required title in the list, followed by a semi-colon.

There is further help with Maxima in the Frequently asked questions


section of the OU Maxima website, at learn1.open.ac.uk/site/maxima.

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

3.1 Algebraic manipulations


You can enter algebraic expressions into Maxima in a similar way to
numerical expressions, using the symbols +, -, *, / and ∧, and the
command sqrt( ) for square roots. You can also assign algebraic
expressions to variables, using the assign (:) command, in the same way as
numerical expressions.
In the next activity, you will meet some commands for manipulating
algebraic expressions.

Computer activity 18 Using algebraic expressions

(a) Enter
expand( (2+x)*(3*x+4)∧3 );
to expand the expression (2 + x)(3x + 4)3 .

The command expand multiplies out the expression that is its


argument.
Spaces have been included simply to help with the reading of the
command.

(b) Enter
factor( 2*x∧3-7*x∧2-10*x+24 );
to factorise the expression 2x3 − 7x2 − 10x + 24.

The command factor factorises, where possible, the expression that


is its argument.

x3 + 1
(c) Define p to be the expression .
x+1

Remember to use brackets as necessary when typing this expression.

(d) Enter
fullratsimp(p);
to simplify the expression assigned to the variable p.

31
3 Algebra

The command fullratsimp simplifies, where possible, the expression


that is its argument. It does this by using techniques for multiplying
out brackets, collecting terms over a common denominator and
cancelling out common factors. Simplifications requiring other
techniques may not be handled by fullratsimp in the way you would
expect.
The name fullratsimp is short for ‘full rational simplify’.

(e) Enter
subst(3,x,p);
to find the value of the expression p (defined above) when x = 3.

The command name subst is short for ‘substitute’.


The command subst(3,x,p); substitutes the value 3 for the variable
x in the expression p.

The commands introduced in the previous activity are summarised below.


Algebraic manipulation commands
Operation Command Example
Expand brackets expand( ) expand( (x+1)∧2 );
Factorise factor( ) factor( 2*x+4*x∧2 );
Simplify fullratsimp( ) fullratsimp( (2*x+4*x∧2)/x );
Substitute subst( value , variable , subst(4, x, x∧2+1);
expression ) which substitutes 4 for x in x∧2+1

It is hard for a computer to simplify algebraic expressions, because often


there is no single ‘simplest form’ for a particular expression, and the
computer has no way of knowing which form you prefer. You can use the
commands in the table above to simplify an expression in the way you
want.
You can access many of these commands from wxMaxima menus. For
example, to factorise an expression you can first enter the expression in the
worksheet, select it by highlighting the text using the mouse or clicking on
the corresponding output line number, then select Factor Expression
from the Simplify menu (or from the menu obtained by right clicking on
a highlighted output line number).
Other options on these menus, such as Substitute... open a window for
you to enter the command options. Options that work in this way are
identified by ... at the end of the option name.

32
3 Algebra

3.2 Equations and their solutions


Maxima can manipulate and solve equations. To type an equation in
Maxima, you use an equals sign in the usual way. For example, you can
type 3*x+2=4.
You can assign equations to variables in a similar way to expressions.
For example, by entering
q: 3*x+2=4;
you assign the equation 3x + 2 = 4 to the variable q.
You can extract the left- and right-hand sides of an equation by using the
lhs and rhs commands, as demonstrated in the following activity.

Computer activity 19 Working with equations

(a) Assign the equation x2 + 2x = 4 to the variable r.


(b) Extract the left-hand side of the equation by entering
lhs(r);

(c) Extract the right-hand side of the equation by entering


rhs(r);

Extracting the left- and right-hand sides of an equation


Operation Command Example
Left-hand side of an equation lhs( equation ) lhs(4*x+1=2*x-2);
Right-hand side of an equation rhs( equation ) rhs(4*x+1=2*x-2);
Note: equation indicates that the argument of the command must be
an equation, or a variable whose value is an equation.

Maxima can find the exact solution(s) of equations, as demonstrated in the


following activity.

33
3 Algebra

Computer activity 20 Solving equations

(a) Solve the equation x2 + 2x = 1, by entering


solve( x∧2+2*x=1 );

Notice that Maxima displays the two solutions of the quadratic


equation within square brackets and separated with a comma:
√ √
[x=- 2-1, x= 2-1]
This is a Maxima list.

(b) Use Maxima to solve 4x2 − 12x + 9 = 0.

Notice that although there is only one solution of this quadratic


equation, Maxima still gives it as a list, containing just one element.

(c) Use Maxima to solve 2x3 + x2 − 5x + 2 = 0.

This is a cubic equation, since the highest power of x is 3. Each


cubic equation has at most three solutions.

(d) Try to use Maxima to solve x9 + 2x − 4 = 0.

Here, Maxima returns (within a list) the equation, slightly


rearranged, but unsolved.
The solve command always tries to find an exact solution of the
equation using algebraic manipulations. If it is unable to do this, then
it returns the original equation, as here.
In Section 6 of this Guide you will see how to find approximate
solutions of such equations.

(e) Use Maxima to solve x2 − 4x + 5 = 0.

This equation has no real solutions, since the discriminant,


(−4)2 − 4 × 1 × 5 = −4, is negative.
However, Maxima finds solutions that are complex numbers. These
involve the imaginary number, usually denoted by i, whose square
is −1. Maxima denotes this number by %i.
Complex numbers were mentioned in Unit 1 and you will learn more
about them in Unit 12.

34
3 Algebra

The solve command is summarised below.


Solving an equation
Operation Command Example
Solve an equation, exactly solve( equation ) solve(2*x∧2-1=0);

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.

Computer activity 21 Working with lists

(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];

The position number of an element in a list is known as its index.


You can obtain individual elements of a list by typing the index of the
element in square brackets after the list, or after the name of a
variable to which the list is assigned.

(c) (i) Assign the solutions of the equation x2 − x − 1 = 0 to the


variable solns.
(ii) Display decimal approximations to the answers by entering the
command
float(solns);

(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

The operations introduced in the above activity are summarised below.


Lists
Operation Command Example
Form a list [ , , ... ] A: [a,b,c];
Extract an element of a list list [ index ] A[2];
Note: ... indicates the list of arguments could continue.

As well as solving equations, you can also manipulate equations using


Maxima. The next activity shows how you can do this.

Computer activity 22 Manipulating equations

(a) Assign the equation 3y + 4 = 3x2 + 9x to the variable eq.


(b) Enter the following command.
eq-4;

This subtracts 4 from both sides of the equation eq.

(c) Now divide both sides of the rearranged equation by 3, by entering


%/3;

Remember that % represents the result of the last evaluated cell.


The variable y is now alone on the left-hand side of the equation.
We have rearranged the equation to make y the subject.

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

Computer activity 23 Rearranging an equation


2a + b + 3c
(a) Assign the equation c = to the variable eqn.
a−b
(b) Rearrange the equation to make a the subject by entering
solve(eqn, a);

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.

This use of the solve command is summarised below.


Changing the subject of an equation
Operation Command Example
Solve an equation for a variable solve( equation , variable ) solve(2*a*b-3*b=0, a);

Another use of the solve command is to solve two or more simultaneous


equations. To use the command in this way, you must enter the equations
as a list, and enter the variables to be solved for as another list, as
indicated below.
Solving simultaneous equations

Operation Command Example


Solve simultaneous equations solve( list of equations , solve([2*x+y=4, 3*x-2*y=-1],
list of variables ) [x,y]);

Computer activity 24 Solving simultaneous equations

Use Maxima to solve the simultaneous equations


3x2 + 2y = 20
4x − 3y = −4
as described below.
(a) Assign the first equation to the variable eq1 and the second equation
to the variable eq2.

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] );

Maxima’s output is [[x=2, y=4] , [ x=- 26 68


9 , y=- 27 ]]
This tells you that there are two solutions to the equations: one
solution is x = 2, y = 4 and the other is x = −26/9, y = −68/27.
Notice that Maxima’s output here is a list of lists.

3.3 Plotting graphs


You can plot graphs in wxMaxima by using the wxplot2d command. This
command inserts your graph into your worksheet, as demonstrated in the
activity below. Maxima plots the graph by calculating a large number of
points on the curve and joining them up. The ‘2d’ in the name of this
command comes from the fact that its graphs are two-dimensional plots.
The ‘wx’ is because it is a wxMaxima command.
If you are using another interface to Maxima, you should use the command
plot2d instead. You use it in the same way as wxplot2d, but it will plot
the graph in a different computer window, which you then need to close
before you can create another plot.

Computer activity 25 Plotting a graph

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]);

The first argument of the command is the expression to be plotted,


and the second argument is a list that specifies the variable in the
expression together with the least and greatest values that you want
it to take in the graph.
wxMaxima displays the graph next to a line label beginning %t, such
as (%t1). This is how wxMaxima shows intermediate output, that is,
output other than the final result of the command.
The wxplot2d command has no final result, just intermediate output,
which is the graph.

38
3 Algebra

(b) Change the vertical range of the graph to be −5 ≤ y ≤ 5 by including


an additional argument [y,-5,5].
That is, change the command to
wxplot2d( 4*x∧2-8*x+2, [x,-1,2], [y,-5,5]);

Notice the warning:


plot2d: some values were clipped.
This means that some of the points on the graph with x-coordinates
between −1 and 2 could not be displayed due to the range of values of
y specified.

(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.

This argument is a list whose first element is a keyword indicating


the property to be set, in this case color (with the American
spelling!). The second element is the value of the property that you
want to choose.

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.

Computer activity 26 Plotting multiple graphs

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] );

Notice that the first argument of the command wxplot2d is a list


containing the two expressions to be plotted. In this case, the
expressions involve the variable t, so the second argument specifies
the range of values of t to be plotted.
The curves are automatically plotted in different colours, and a legend
showing which expression corresponds to which curve is included at
the top right-hand corner of the graph.

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.

In general, to change the legend text, you include an extra argument


of wxplot2d: a list that contains the keyword legend, followed by the
new pieces of text, each enclosed in double quote marks.

(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)"].

In general, to change the x-axis label, you include a further argument


of wxplot2d: a list that contains the keyword xlabel, followed by the
new label text, enclosed in double quote marks. You can change the
y-axis label in a similar way, using the keyword ylabel.

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.

Plot several graphs wxplot2d( list of expressions , wxplot2d([x∧2, 2*x], [x,0,1]);


horizontal range ,...) which plots graphs of x2 and 2x
for x between 0 and 1.

Graph plotting options


Option Argument Example
Vertical range [y, , ] [y, 0, 5]
Curve colour [color, ,...] [color, red]
Legend text [legend," ",...] [legend, "Car A"]
(a label should be listed for each curve plotted)
Turn legend off [legend, false] [legend, false]
Horizontal axis label [xlabel, " "] [xlabel, "time, t (h)"]
Vertical axis label [ylabel, " "] [ylabel, "displacement, s (km)"]

Note: for a full list of the possible options, view the Maxima help for
plot2d, using the ? plot2d; command.

If you began studying Sections 2 and 3 of this Guide from Activity 31 of


Unit 2, this now completes your study of the unit.

4 Functions
You can define a function in Maxima using the := operator, as shown in
the following activity.

41
4 Functions

Computer activity 27 Defining 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;

(b) Calculate the value of f (2), by entering f(2);


(c) Now define the function g with rule
x−1
g(x) =
x−2
and find the value of g(3).

Remember to use brackets appropriately in the rule for g.

(d) Now try to use Maxima to find g(2).

This gives an error.


This is because when Maxima tries to evaluate g(2), it finds that this
involves dividing by zero, so it returns an error message. The function
g is undefined at x = 2.

(e) Enter h(1);

Maxima returns the expression h(1), unevaluated.


Since the function h has not been defined, Maxima cannot calculate a
value. It knows only that the value is h(1).

(f) Enter functions;

This displays the value of the system variable functions, which is a


list of all the functions that you have defined in this Maxima session.

Notice the difference between defining a function, which has an argument


and which can be evaluated at different values of the argument, using :=,
and assigning an expression to a variable (which has no argument) using :.
As with variables, once you have defined a function in Maxima it is
remembered by the system for the rest of your session, unless you remove
it using the kill command that you met in Subsection 2.4 of this Guide.

42
4 Functions

Working with functions


Operation Command Example
Define a function := f(x):=2*x+3;
Evaluate a function at a value function ( ) f(1);
List all user defined functions functions functions;
Remove a defined function kill( function ) kill(f);

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.

Computer activity 28 Plotting functions

(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.

(c) Plot g again, for values of x in the range −5 ≤ x ≤ 5, but restricting


the range of the vertical axis to between −5 and 5.

Remember, to restrict the vertical range to −5 < y < 5, include the


argument [y,-5,5] in the wxplot2d command.

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

5 Exponential functions and logarithms


You saw in Subsection 2.2 of this Guide that the mathematical constant e
is represented in Maxima by %e. The % symbol indicates that this is the
name of a special quantity built into Maxima.

Computer activity 29 Working with exponentials and logarithms

(a) Find e5 using Maxima, by entering


%e∧5;

Since Maxima works symbolically, it does not return a decimal


approximation.

(b) Find a decimal approximation to e5 by entering


float(%e∧5);

(c) An alternative way to find powers of e is to use the exp function.


Find e5 by entering
exp(5);

Again, this is expressed exactly, as a power of e.

(d) The Maxima command for a natural logarithm is log( ).


Use this to find a decimal approximation for ln 8.
(e) Use the solve command introduced in Subsection 3.2 of this Guide to
solve the equation
32x = 5.

44
5 Exponential functions and logarithms

You may be surprised to see two solutions to this equation.


log(5)
One solution, , is the sort of solution that you would expect.
2 log(3) √
log(− 5)
The other solution, , involves the logarithm of a negative
log(3)
number.
You have seen that only positive numbers have logarithms, but that
applies when you are working only with real numbers. If you are
working with complex numbers, then negative numbers do have
logarithms.

log(− 5)
The solution is a complex number, as you can see more
log(3)
clearly by obtaining a decimal approximation for it. It contains the
imaginary number i, which Maxima represents as %i.
There is only one real solution to the equation.

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);

When you are working with logarithms in Maxima, the algebraic


simplification commands that you met in Section 3.1 of this Guide can be
useful. You can also use the commands shown below.
Simplifying expressions involving exponentials and logarithms
Operation Command Example
Simplify something radcan( ) radcan( log(x∧2) );
involving exponentials and
logarithms
Combine logarithms logcontract( ) logcontract(log(a)+log(b));

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

Computer activity 30 Simplifying expressions involving logarithms

Simplify the expressions


ln(x3 + 2x2 + x) − ln(x)
and ln(a) + 2 ln(b) − ln(c).
ln(x + 1)
by following these steps.
(a) Define u to be the expression
ln(x3 + 2x2 + x) − ln(x)
.
ln(x + 1)

Remember that the Maxima command for a natural logarithm is log.

(b) Simplify u using the following command.


radcan(u);

Can you simplify this expression and obtain the same answer by
hand?

(c) Define v to be the expression ln(a) + 2 ln(b) − ln(c).


(d) Simplify v by using the following command.
logcontract(v);

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);

cosec csc( ) csc(2);


sec sec( ) sec(%pi/3);
cot cot( ) cot(%pi/4);

sin−1 asin( ) asin(sqrt(3)/2);


cos−1 acos( ) acos(1/sqrt(2));
tan−1 atan( ) atan(1/2);

47
6 Trigonometry

Computer activity 31 Using trigonometric functions

Calculate the following using Maxima.


!π;
(a) cos
6

Remember that to enter the constant π in Maxima, you type %pi.


Maxima returns an exact answer, in the form of a surd. Remember
that Maxima always uses exact values where possible, rather than
decimal approximations.

(b) sin 45◦

π
Remember to convert the angle to radians, by multiplying 45◦ by .
180

(c) sec (3.4)

Here, since the angle is entered as a decimal number, Maxima returns


a decimal approximation to the answer.

1√ 4
3
(d) sin−1
2

Maxima returns an exact answer, as a multiple of π.

!π;
(e) cosec
7

There is no simple exact answer here, so Maxima leaves this


expression unevaluated.
To find a decimal approximation, you can use the command
float( csc(%pi/7) );

! π;
(f) tan −
12

Again, Maxima leaves this expression unevaluated, but it simplifies it


slightly, using the fact that tan(−θ) = − tan θ.

48
6 Trigonometry

(g) cos−1 (2.0)

Here, since the argument of the function is a decimal number,


Maxima returns a decimal approximation to the answer.
You might be surprised that it returns an answer at all, since 2.0 is
not in the domain of cos−1 .
Notice that the answer is a multiple of %i. In Maxima, %i represents
the imaginary number i whose square is −1, which you will learn
about in Unit 12. Although there is no real number y such that
cos y = 2, there is an imaginary number with this property, and
Maxima returns this value.
If you are working only with real numbers, you should ignore any
Maxima answers that contain the constant %i.

(h) cos−1 (2)

This expression is equivalent to the expression in part (g), but does


not contain a decimal number, so Maxima tries to find an exact
answer. Since there is no simple exact answer, Maxima leaves the
expression unevaluated.
This hides the fact that the answer is not a real number. You need to
take care when using inverse trigonometric functions.

You can solve equations involving trigonometric functions in Maxima,


using the solve command that you met in Subsection 3.2 of this Guide.
However, Maxima will return only one solution to such an equation, even
though many may exist. It warns you of this, as shown in the following
activity.

49
6 Trigonometry

Computer activity 32 Solving trigonometric equations

(a) Solve the equation cos(x) − 0.6 = 0 by entering


solve(cos(x)-0.6=0);

Since the solve command always tries to find exact solutions,


Maxima first converts the decimal number −0.6 to the exact
fraction − 35 . It tells you that it has done this.
It also displays the following warning to tell you that there might be
other solutions.
solve: using arc-trig functions to get a solution.
Some solutions will be lost.
Then it returns a single solution.

(b) Find a decimal approximation to the solution obtained in part (a), by


entering
float(%)

Remember, % represents the answer of the last evaluated calculation.

(c) Solve the equation sin(3x + 4) = 12 .


(d) Solve the equation cos(2x + 4) − sin(x/3) = 0.

Maxima returns the original equation, slightly rearranged but


unsolved. This is because the solve command could not find an exact
solution to this equation.

In circumstances such as Computer activity 32(d) when the solve


command fails to find the exact solution of an equation, you can use
another Maxima command, find root, to try to find an approximate
solution.
Whereas the solve command manipulates the equation mathematically to
find a solution, the find root command performs a series of numerical
calculations to find a decimal approximation to a solution. This is known
as solving the equation numerically, or finding a numerical
approximation to a solution.

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.

Figure 10 The graph of y = f (x) with the solutions of f (x) = 0 marked


The find root command uses the following property of functions. If f is a
function and [a, b] is an interval included in its domain such that one of
f (a) and f (b) is negative and the other is positive, then there is at least
one solution of the equation f (x) = 0 in the interval (a, b). Figure 11
illustrates this property for two different functions. This property holds as
long as the graph of f is continuous on the interval [a, b]; informally, this
means that you can draw the graph of f for input values in the interval
[a, b] without taking your pen off the paper.

Figure 11 There is at least one solution of f (x) = 0 in the interval (a, b)


if f (a) and f (b) have different signs
The find root command looks for a single solution of an equation of the
form f (x) = 0 that lies within an interval that you specify. The command
requires that the values of f at each endpoint of the interval have different
signs. If this is not the case, then Maxima gives an error message.

51
6 Trigonometry

Solving an equation numerically


Operation Command Example
Solve an equation numerically find root( expression , find root(2*x∧2-1,x,0,1);
variable ,
interval start value ,
interval end value )

Note 1 : the command finds a value of the variable at which the


expression is zero.
Note 2 : the values that the expression takes at the endpoints of the
interval must have different signs.

Computer activity 33 Solving equations numerically

(a) Find a numerical approximation to a solution of the equation


!x;
cos(2x + 4) − sin = 0,
3
as follows.
(i) First, define the function f in Maxima, with the rule
!x;
f (x) = cos(2x + 4) − sin .
3

Remember, to define a function use :=.

(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.

Remember, you can plot graphs using the wxplot2d command.


From the graph, you can see that f (0) < 0 and f (1) > 0, so there is a
solution in the interval (0, 1).
If there were no solution in the interval over which you plotted the
function, then you could plot the function over a larger interval, and
so on, until you find a suitable interval, if one exists.

52
6 Trigonometry

(iii) Find a numerical approximation to the solution of the equation in


the interval (0, 1) by entering
find root(f(x), x, 0, 1);

Remember to type the underscore symbol ( ) in the middle of the


command name.
Notice that the first argument of the find root command is an
expression (or a function defined by an expression) not an equation.
Maxima finds an input value at which the expression takes the
value 0.

(b) Using similar methods, find a solution of the equation sin2 (x + 2) = 3x.

Hint: Consider the function g(x) = sin2 (x + 2) − 3x and find a value


of x for which g(x) = 0.
Remember that sin2 (x + 2) means (sin(x + 2))2 . You can enter this
expression in Maxima by typing either (sin(x+2))∧2 or sin(x+2)∧2.

Maxima can use trigonometric identities to rewrite expressions involving


trigonometric functions in different forms.
These behave like the algebraic simplification commands you met in
Section 3 of this Guide. In particular, you need to guide Maxima in how to
conduct such rearrangements. Commands for doing this are demonstrated
in Computer activities 34 and 35.

Computer activity 34 Manipulating trigonometric expressions

(a) Enter
trigreduce( sin(x)∧2 );

The trigreduce command attempts to express powers of sines and


cosines of x in terms of sines and cosines of multiples of x. It reduces
the powers of the functions.

53
6 Trigonometry

(b) Enter
trigexpand( % );

Remember that % represents the result of the previous calculation.


The trigexpand command attempts to express trigonometric
functions of sums, differences and multiples of angles in terms of
trigonometric functions of the individual angles.

(c) Enter
trigsimp( % );

The trigsimp command attempts to simplify expressions involving


trigonometric functions.
This returns you to the expression that you started with!

Computer activity 35 Simplifying rational trigonometric


expressions
sin(4x)
Simplify by entering
sin(x)
trigrat( sin(4*x)/sin(x) );

The trigrat command attempts to simplify algebraic fractions


involving trigonometric functions.

Trigonometric manipulation commands


Operation Command Example
Expand trigonometric functions trigexpand( ) trigexpand(sin(A+B));
of sums, differences and
multiples of angles
Express powers of sines and trigreduce( ) trigreduce(sin(x)∧2);
cosines in terms of sines and
cosines of multiple angles
Simplify trigonometric expressions trigsimp( ) trigsimp(sin(x)∧2+cos(x)∧2);
Simplify algebraic fractions trigrat( ) trigrat((sin(2x))/cos(x));
containing trigonometric
functions

54
7 Plotting circles

You can use these commands, and others that you learned previously, in
the final activity of this section.

Computer activity 36 Finding a new trigonometric identity

(a) Find an expression for cos(5x) in terms of products of sin(x) and


cos(x).
(b) Plot the graphs of cos(5x) and the expression you found in (a), to
check that they look the same.

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

Computer activity 37 Plotting a circle

Plot the circle represented by the equation x2 + y 2 = 1, as follows.


(a) Load the implicit plot package by entering
load(implicit plot);

This package provides the wximplicit plot command.

(b) Plot the circle by entering


wximplicit plot(x∧2+y∧2=1, [x,-2,2], [y,-2,2]);

The first argument of the command is the equation to be plotted.


The second argument specifies the variable to be plotted on the
horizontal axis, and the range of values of that variable to be plotted.
The third argument specifies the variable (and its range) to be
plotted on the vertical axis. You must include this third argument.
The circle with equation x2 + y 2 = 1 has centre (0, 0) and radius 1.
So the circle lies within −2 ≤ x ≤ 2 and −2 ≤ y ≤ 2 and hence these
seem suitable ranges to use.
The curve that Maxima plots, however, does not look very circular!
This is discussed below.

Note that the first argument of the wximplicit plot command is an


equation, whereas the first argument of the wxplot2d command is an
expression.
The curve that you plotted in Computer activity 37 does not look circular
because it has different scales on the axes. Whatever ranges of x- and
y-values you specify for a plot, by default Maxima makes the y-axis appear
3
5 as long as the x-axis.
To specify equal scales, you can add the following additional argument to
the wximplicit plot command:
[gnuplot preamble, "set size ratio -1"]

Gnuplot is the underlying software that Maxima uses to plot graphs. In


general, if you set the size ratio to be −r, where r is a positive number,
then the length that represents 1 unit on the y-axis is r times as long as
the length that represents 1 unit on the x-axis. On the other hand, if you
set the size ratio to be r, where r is a positive number, then the y-axis
appears r times as long as the x-axis.

56
7 Plotting circles

Computer activity 38 Plotting a circular circle!

Plot the circle x2 + y 2 = 1, using equal scales on the x- and y-axes by


entering
wximplicit plot(x∧2+y∧2=1,[x,-2,2],[y,-2,2],[gnuplot preamble,"set size ratio -1"]);

Including the gnuplot preamble argument in the wximplicit plot


command can be tiresome if you are plotting lots of curves and need
equally scaled x- and y-axes for each. An alternative is to change the
default behaviour of Maxima so that it uses axes with equal scales for the
rest of your session. You will see how to do this in the following activity.
If you have configured Maxima to change the font and line styles used
when plotting graphs, as described in the Accessibility section of the OU
Maxima website, then the command given in the following activity will
revert these back to their original styles. To retain your graph style
settings, use
set plot option([gnu preamble, OUEqualScales]);
instead.

Computer activity 39 Plotting another circular circle!

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"])$

This sets [gnuplot preamble, "set size ratio -1"] to be a


default option for all plots during the rest of your Maxima session.
The line ends with $ to prevent the display of the output of the
command. When present this output consists of a long list of all the
current default settings, which can safely be ignored.

(b) Plot the circle by entering


wximplicit plot((x-1)∧2+y∧2=3, [x,-1,3], [y,-2,2]);

57
7 Plotting circles

In the remainder of this section, it is assumed you have changed the


default plotting behaviour as described in Computer activity 39.
To plot more than one curve you can list their equations within square
brackets as the first argument of wximplicit plot, as you did in
Subsection 3.3 of this Guide when using wxplot2d. The equations do not
necessarily have to be in implicit form. This is demonstrated in the
following activity.

Computer activity 40 Plotting a line and a circle

Plot the line y = 3x − 5 and the circle (x − 2)2 + (y − 3)2 = 2 as follows.


(a) For simplicity, assign the equation of the line to the variable line, and
the equation of the circle to the variable circle.

Remember, to assign an expression to a variable, use the colon (:)


operator. So to assign the equation of the line to the variable line,
use
line:y=3*x-5;

(b) Plot the line and circle on axes with equal scales by entering
wximplicit plot([line, circle], [x,0,5], [y,0,5]);

The first argument is a list of the equations to be plotted. Since you


have assigned the equations to variables, you can simply list the
names of the variables.

Since the circle has centre (2, 3) and radius 2 ≈ 1.41, the ranges
0 ≤ x ≤ 5 and 0 ≤ y ≤ 5 are large enough for the whole circle to be
plotted.

The commands introduced in this section are summarised as follows.


Loading additional packages
Operation Command Example
Load a package load( package name ) load(implicit plot);

58
7 Plotting circles

Plotting curves represented by equations in implicit form


Operation Command Example
Plot a curve represented wximplicit plot( equation , wximplicit plot(x∧2+y∧2=1,
by an equation in implicit horizontal range , [x,-1,1], [y,-1,1]);
form vertical range ,...)

Plot several curves wximplicit plot( wximplicit plot(


represented by equations list of equations , [x∧2+2*y∧2=4, y=x∧3],
in implicit form horizontal range , [x,-1,1], [y,-1,1]);
vertical range ,...)

Note 1 : the first argument is an equation or a list of equations.


Alternatively it can be an expression, or a list of expressions, in which
case the equation formed by setting the expression equal to zero is
plotted.
Note 2 : equations in explicit form can also be plotted using this
command.

Graph plotting options


Option Argument Example
Change the relative lengths/scales [gnuplot preamble, [gnuplot preamble,
of graph axes. "set size ratio number "] "set size ratio -1"]
(A positive number specifies the (which sets the axes to have
ratio of axis lengths, a negative equal scales)
number specifies the ratio of axis
scales.)

Setting default plotting options


Operation Command Example
Set the default plotting options set plot option( option ) set plot option(
[gnuplot preamble,
"set size ratio -1"]);

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

Computer activity 41 Plotting equations given in implicit form

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.

Remember, you can use the editing facilities of wxMaxima to avoid


having to type the whole wximplicit plot command each time.

(a) x2 + 4y 2 = 1 (b) x2 − 4y 2 = 1 (c) y 2 = x3 − 2x + 1


(d) y 2 = x3 − 2x + 5 (e) y 6 = x2 − x6 (f) (x2 + y 2 − 1)3 = x2 y 3

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

Computer activity 42 Demonstrating differentiation with Maxima

(a) Find the derivative of f (x) = x4 + 5x2 + 15, by entering


diff(x∧4+5*x∧2+15, x);

The first argument of the diff command is the expression to be


differentiated, and the second argument is the variable to differentiate
with respect to.
You must include the second argument. If you do not, then the
answer returned by Maxima will be the derivative multiplied by
del(x). This notation is outside the scope of MST124.
As you would expect, the first argument can also be a variable that
you have previously defined to be an expression, or a function you
have previously defined.

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.

(e) Find the third derivative of g(u) defined above.

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);

Differentiate diff( , variable , diff(log(x),x,3);


multiple times positive integer )

Computer activity 43 Differentiating with Maxima

Use Maxima to differentiate the following, simplifying the answer when


possible.
Remember, you can enter ex in Maxima either as %e∧x or exp(x).
5 tan(t) − t2
(a) 2x6 + (b) ln(ex + x) (c)
x et

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.

Computer activity 44 Defining a function to be the derivative of


another function
sin(x)
(a) Define the function f (x) = .
ex + 1
(b) Try to define df(x) to be the derivative of f (x), by entering
df(x):=diff(f(x),x);

62
8 Differentiation

(c) Try to find the value of the derivative of f at x = 3 by evaluating


df(x) at x = 3; that is, try entering
df(3);

This gives an error.


The cause of this error lies in the previous command:
df(x):=diff(f(x),x);

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.

(d) Define df(x) to be the result of differentiating f with respect to x, by


entering
df(x):=''(diff(f(x),x));

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).

(e) Find the value of the derivative of f at x = 3 by entering


df(3);

If you want a decimal approximation to the result, use the float


command.

(f) Use a similar approach to find the derivative of sin(x)ecos(x) at x = 1,


giving your answer as a decimal number to 3 significant figures.

The command used to force the evaluation of the derivative in Activity 44


is summarised as follows.

63
9 Integration

Forcing the evaluation of a command


Operation Command Example
Force the evaluation of a ''( ) g(x):=''(diff(x∧4,x));
command
An alternative approach to Computer activity 44 parts (d) and (e) is to
assign the derivative of f to a variable rather than use the derivative to
define a function. You can do this by entering, for example
df:diff(f(x),x);
This calculates an expression for the derivative of f at x and assigns it to
the variable df (the ''( ) command is not required).
You can then evaluate the derivative at 3 by substituting the value 3 for x,
which you can do by entering
subst(3,x,df);

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

Computer activity 45 Demonstrating integration with Maxima


&
(a) Evaluate 2x2 + e3x dx by entering

integrate(2*x∧2+exp(3*x), x);

The first argument of integrate is the expression to integrate, and


the second is the variable to integrate with respect to.
The output returned by Maxima does not include an arbitrary
constant. That is, Maxima gives an antiderivative of the expression,
not its indefinite integral. When you write down an indefinite integral
that you have found using Maxima, you need to remember to add an
arbitrary constant yourself.

& 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.

If you try to define q(x) using


q(x):=integrate(p(x),x);
then Maxima& does not actually do the integration, but just notes that
q(x) means p(x) dx.

As with differentiation, to force Maxima to perform the integration


you need to use the ''( ) command and enter
q(x):=''(integrate(p(x),x));

65
9 Integration

Integration
Operation Command Example
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 )

You can practice using the integrate command in the following activity.

Computer activity 46 Using integration

Use Maxima to find the following.


& & & π
1
(a) (x − 3)(x − 1) dx (b) √ dt (c) et sin t dt
9 − t2 0

It is not always possible to express the result of integrating a function in


terms of the mathematics functions you have previously met. The
following activity illustrates some of the things that you may encounter
when integrating functions using Maxima.

Computer activity 47 Calculating harder integrals

Try to calculate the following using Maxima.


& & & x
sin(x) −x2 e
(a) e dx (b) e dx (c) dx
x

Maxima was unable to find an antiderivative for part (a), and so


returned the integral uncalculated. In parts (b) and (c) answers were
returned containing the function erf, which is known as the Error
function, and the function gamma incomplete, the incomplete
gamma function. These are examples of what are known as special
functions in mathematics. They cannot be simply expressed in
terms of functions you have already met, but many can be defined in
terms of antiderivatives of simpler functions.

Sometimes you may want to integrate a function that contains a variable


other than
& the one you are integrating with respect to. For example, the
integral xn dx contains the variable n as well as the variable x. When
you use Maxima to find such an integral, you sometimes need to provide
66
9 Integration

information about the other variable, as demonstrated in the following


activity.

Computer activity 48 Giving Maxima more information


&
(a) Try to use Maxima to find the integral xn dx, as follows.

(i) First, ensure that n has no predefined value, by entering


kill(n);

(ii) Then, enter


integrate(x∧n, x);

Maxima asks the question: Is &n+1 zero or nonzero?


This is because the answer to xn dx depends on the value of n.
&
1
If n = −1 (so n + 1 = 0), the integral is dx, which is equal to
x
log |x| + c, whereas if n is any other value, then the integral is equal
xn+1
to + c. So Maxima cannot calculate the integral without
n+1
knowing more about n.

Enter the answer n;


(which is short for nonzero)

You could also answer the question with z;


to mean zero.

Maxima displays the expected result.


(b) An alternative approach is to give Maxima information about n before
you use the integrate command. You can do this as follows.
(i) Tell Maxima that n ,= −1 by entering
assume(notequal(n,-1));

The assume command tells Maxima information about variables. For


example, assume(a>0); tells Maxima that a is positive.
Maxima has no simple symbol for ‘not equal to’, so you have to use
the notequal command for this, as above.

67
9 Integration

(ii) Now integrate xn using


integrate(x∧n, x);

No question is asked this time, since Maxima knows all it needs to


know about n.

(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.

(iv) Tell Maxima to forget about the assumption on n by entering


forget(notequal(n,-1));

(v) Type facts(); again to see all the facts now known.

No facts are displayed, since Maxima has now forgotten the


assumption about n.

The commands introduced in the previous activity are summarised below,


together with the equal command, which is used in a similar fashion to
notequal.
Facts about variables
Operation Command Example
Make an assumption about a assume( ) assume(a>0);
variable
State two things are equal equal( , ) assume(equal(n,3));
State two things are not equal notequal( , ) assume(notequal(n,-1));
Forget a property forget( property ) forget(a>0);
List all known facts facts() facts();
List all known facts about facts( variable ) facts(a);
a particular variable

68
9 Integration

Computer activity 49 Using facts

Calculate the integral


&
1
dx, where a > 0.
x2 + a

You saw in Computer activity 47 that Maxima cannot always find an


antiderivative for a function. Even if Maxima cannot find an antiderivative
of a function f , it can still find an approximate value for a definite integral
& b
of the form f (x) dx.
a
In Unit 8, you saw how the value of the definite integral can be
approximated by breaking the area between the graph of the function and
the x-axis into a number of rectangles. Maxima uses a more sophisticated
version of this basic method to calculate approximate values of definite
integrals.
You will learn the Maxima command for this in the following activity.

Computer activity 50 Approximate values of definite integrals


& 1
(a) Try to calculate ln(cos(x2 )) dx by entering
0
integrate(log(cos(x∧2)), x, 0, 1);

The integral is returned unevaluated, since Maxima cannot


calculate it.

69
10 Matrices

(b) Find an approximate value of the integral by entering


quad qags(log(cos(x∧2)), x, 0, 1);

The quad qags command calculates an approximate value for a


definite integral.
The ‘quad’ part of the name of this command arises from the fact the
process of finding the value of a definite integral (or any area) is
sometimes called quadrature. The letters q, a, g and s in the second
half of the name specify the particular method Maxima uses to find
the approximate value of the definite integral. This method gives
good results for a wide variety of integrals.
Notice that the output of the quad qags command is a list. The first
element of the list is the approximate value of the definite integral, the
second element is an estimate of the accuracy of the approximation,
the third element is the number of values at which the function to be
integrated was evaluated during the calculation, and the final element
is an error code. An error code of 0 means that no errors occurred.

& 1
2
(c) Find an approximate value for the definite integral e−t dt.
0

Finding approximate values for definite integrals


Operation Command Example
Find an approximate value quad qags( , variable , quad qags(exp(-x∧2),x,0,1);
of a definite integral lower limit , upper limit )

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.

10.1 Matrix algebra


There are several ways to input matrices in Maxima. Some of these are
demonstrated in the following activity.

70
10 Matrices

Computer activity 51 Entering matrices

(a) Assign the matrix


8 9
1 3 5
to the variable A by entering
2 4 6
A: matrix( [1,3,5], [2,4,6] );

The matrix command allows a matrix to be defined. You give each


row of the matrix as a list (that is, within square brackets with each
element separated by a comma).
Notice that wxMaxima displays matrices using square brackets rather
than the round brackets used in the unit:
2 =
1 3 5
.
2 4 6
If you are using a different interface for Maxima, or have chosen
different display settings, matrices may be displayed as follows.
[ 1 3 5 ]
[ ]
[ 2 4 6 ]

(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...

Make sure you select Enter Matrix..., not Generate Matrix...


A window opens requesting properties of the matrix, as shown below.

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.

It is also possible to give information on the type of matrix. You have


not learned about these types in MST124, so leave this set to
general.

Finally, enter B as the variable name the matrix will be assigned


to, and click ‘OK’.

This opens a second window requesting the elements of the matrix.

(iii) Complete entry of the matrix by filling in the elements in this


second window. When you have finished, click ‘OK’.

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

Computer activity 52 Using matrices

(a) Find the size of the matrix A defined in Computer activity 51 by


entering
matrix size(A);

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];

Alternatively, B[3][2] gives the same result.


Notice the use of square brackets to reference elements of a matrix is
the same syntax as used in Section 3.2 of this Guide to obtain
individual elements of a list.

(c) Extract the third row of B by entering


B[3];

(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.)

Computer activity 53 Matrix operations

(a) Define the following matrices in Maxima


   
2 0 0 3 8 9
1 3
P =  3 −1 , Q = 5 −4 , R= ,
2 4
−4 6 1 3
8 9
1 + $
S= , T= 3 4 .
2
(b) Find P + Q.

The matrices P and Q are the same size, so this calculation is


possible.

(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

(d) Find 2P.

This is a scalar multiple of a matrix, so use the * operator.

(e) Find PR.

This is matrix multiplication, so use the . operator.


The sizes of these matrices means the calculation is possible.

(f) Find PQ.

Remember to use the . operator.


This calculation is not possible due to the sizes of the matrices.
Maxima gives an error message:
MULTIPLYMATRICES: attempt to multiply nonconformable
matrices.
-- an error. To debug this try: debugmode(true);

(g) Find PS.

The matrices P and S have sizes 3 × 2 and 2 × 1, respectively, so this


is possible and the result is a 3 × 1 matrix, that is, a column vector.

(h) Find PT.

The matrices P and T have sizes 3 × 2 and 1 × 2, respectively, so this


product should not be possible. However, Maxima does return an
answer!
Maxima does not distinguish between single row matrices (which are
sometimes called row vectors) and single column matrices (column
vectors). It considers them interchangeable as circumstances require.
You should take care to multiply only appropriately sized matrices.

(i) Find R2 .

Since R is a matrix use the matrix power operator ∧∧


.

75
10 Matrices

(j) Enter
R∧2;

The result is not the same as in part (i).


Here the ∧ symbol was used and Maxima squared each individual
element of R.

(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.

If you began studying this subsection from Activity 13 of Unit 9, now


return to the unit to continue your study.

10.2 Determinants and inverses


The Maxima commands for finding the determinant and inverse of a
matrix are demonstrated in the following activity.

Computer activity 54 Finding determinants and matrix inverses

Consider the matrices


   
1 2 0 1 2 0
A = −4 4 2 and B = 5 6 2 .
−1 2 1 2 2 1
(a) First, enter the matrices A and B into Maxima.
(b) Find the determinant of A by entering
determinant(A);

The determinant command calculates the determinant of a square


matrix.

76
10 Matrices

(c) Find the inverse of A, and assign the result to the variable C by
entering
C:invert(A);

The invert command calculates the inverse of a square matrix.


An alternative way to specify the inverse of the matrix A in Maxima
is A∧∧(-1), which accords with the notation usually used to denote a
matrix inverse.

(d) Check that C really is the inverse of A by calculating the products AC


and CA.

Remember to use the symbol . for matrix multiplication.


Both products should be the 3 × 3 identity matrix.

(e) Try to find the inverse of B.

This gives an error:


expt: undefined: 0 to a negative exponent. -- an
error. To debug this try: debugmode(true);
This matrix does not have an inverse. You can check this by
calculating its determinant.

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

Computer activity 55 Finding determinants and inverses of larger


matrices
For each of the following matrices, check whether it is invertible. If it is,
find the inverse.
 
  −1 0 3 −2
2 −1 1  4 1 −1 0
(a) 2 0 1 (b) 
 2 0
2 

4 2 1 1 −1
−1 2 1 −1

If you began studying this section from Activity 24 of Unit 9, now return to
the unit to continue your study.

11 Sequences and series


In this section you will learn how to use Maxima to work with sequences
and series.

11.1 Plotting graphs of sequences


In Subsection 3.3 of this Guide, you learned how to use the wxplot2d
command to plot the graphs of algebraic expressions. Here, you will see
how to use the same command to plot graphs of sequences. First, in
Computer activities 56 and 57, you will learn how to define and work with
sequences in Maxima.

Computer activity 56 Working with a sequence specified by a


closed form
Consider the sequence (an ) specified by the following closed form and
range of values of n:
an = 0.8n (n = 1, 2, 3, . . .).

(a) Define this sequence in Maxima, by entering


a[n]:=0.8∧n;

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

(b) Find the term a100 of the sequence by entering


a[100];

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.

Computer activity 57 Working with a sequence specified by a


recurrence relation
Consider the sequence (bn ) specified by the recurrence relation
b1 = 1, bn = 2bn−1 + 1 (n = 2, 3, 4, . . .).

(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.

(b) Find the 5th and 100th terms of this sequence.

79
11 Sequences and series

(c) Change the value of b1 to be 10, by entering


b[1]:10;
and try to find the revised value of b5 .

Notice that the value of b5 displayed is unchanged. This is because


when Maxima uses sequences, it remembers all the values of the
sequence that it has previously calculated, and bases subsequent
calculations on them. This improves the efficiency of the calculations.
However, it also means that sequences cannot be easily changed.
To change the definition of a sequence, you first need to remove the
sequence from Maxima’s memory using the kill command, and then
redefine it.

(d) Revise the sequence (bn ) correctly, by first entering


kill(b);
and then entering the two commands
b[1]:10;
b[n]:=2*b[n-1]+1;
to specify the revised sequence.
Now calculate the value of b5 .

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

Define a sequence sequence [ first term number ]: initial value b[1]:1;


using a recurrence system sequence [n]:= expression in sequence [n-1] b[n]:=2*b[n-1];

Calculate a term in sequence [ term number ] b[50];


a sequence
Note: to change the definition of a sequence, you first have to delete it
using kill.
In the following activity, you will learn how to plot a graph of a sequence.
Remember, a graph of a sequence (an ) is a set of points (n, an ) plotted for
a suitable range of values of n.

80
11 Sequences and series

Computer activity 58 Plotting the graph of a simple sequence

Plot the graph of the sequence (cn ) specified by


cn = n2 (n = 1, 2, 3)
as follows.
(a) First, define the sequence in Maxima by entering
c[n]:=n∧2;

(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.

(c) Plot the graph of the sequence using the command


wxplot2d([discrete, pts], [style, points],[xlabel, "n"], [ylabel, "c[n]"]);

Here, instead of the first argument of the wxplot2d command being


an expression, or a list of expressions to plot, it is a list containing
two elements. The first element is the keyword discrete. This tells
Maxima that a set of discrete points are to be plotted. The second
element is the list of the coordinates of the points to be plotted.
The second argument of the wxplot2d command is
[style, points].
This tells Maxima to simply plot points, and not join them with lines.
The final two arguments specify labels for the x- and y-axes. These
arguments were introduced in Subsection 3.3 of this Guide.
You can also use other standard arguments of wxplot2d that you met
earlier. For example, including [x,0,4] changes the range of the
horizontal axis to 0 ≤ x ≤ 4.

The use of wxplot2d for plotting sequences is summarised as follows.

81
11 Sequences and series

Plotting graphs of sequences


Operation Command Example
Plot a sequence wxplot2d([discrete, list of coordinate pairs ], wxplot2d([discrete,
[style, points],...) [[1,5], [2,10]]],
[style, points]);

Graph plotting options


Option Argument Example
Plot points [style, points] [style, points]
In Computer activity 58, the sequence plotted was short, so it was
relatively easy to create the list of coordinates to plot. For a longer
sequence this can be laborious, but Maxima can help by creating the list
for you. This is demonstrated in the next activity.

Computer activity 59 Plotting the graph of a longer sequence

Plot the graph of the sequence given by the recurrence relation


d1 = 0, dn = 12 (2 − dn−1 ) (n = 2, 3, 4, . . . , 15)
as follows.
(a) First define the sequence (dn ) in Maxima.
(b) To plot the sequence, we need to plot the points
(1, d1 ), (2, d2 ), (3, d3 ), . . . , (15, d15 ).

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);

The makelist command creates a list. The first argument of the


command is the general form of the elements of the list. In this case,
each element has the form [n,d[n]]; that is, it is itself a list
containing two elements: the term number and the value of the
corresponding term. These are the coordinates of a point to be
plotted. Here, the general form is expressed using the dummy
variable n.
The second argument of the makelist command is the name of the
dummy variable used, and the third and fourth arguments are the
minimum and maximum values taken by the dummy variable.
When you create a long list you may not want to see all the output!
Remember that you can end a command with a dollar sign ($) rather
than a semi-colon (;) to suppress the display of the output.

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.

The makelist command used in the previous activity is summarised as


follows.
Creating lists
Operation Command Example
Create a list makelist( general term , dummy variable , makelist(2*n,n,1,100);
start value , end value )

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.

Computer activity 60 Plotting part of some infinite sequences

Use Maxima to plot graphs of the sequences specified below, by restricting


the range of values of n to be n = 1, 2, 3, . . . , 50 in each case.
How do you think each sequence will behave as more and more terms are
considered?
(a) r1 = 1, rn = 1.5rn−1 − 0.1(rn−1 )2 (n = 2, 3, 4, . . .)
(b) sn = n3 − 10 (n = 1, 2, 3, . . .)
(c) tn = 1 − 1.1n (n = 1, 2, 3, . . .)

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

11.2 Summing series


You can calculate the sums of various series using the Maxima command
sum which is demonstrated in the following activity.

Computer activity 61 Summing 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.

(b) Write the sum


8 92 8 93 8 920
1 1 1 1
+ + + ··· +
3 3 3 3
in sigma notation, and then use the Maxima sum command to
calculate it.
:∞
1
(c) Try to calculate the sum of the infinite series by entering
n=1
4n
sum(1/(4∧n), n, 1, inf);

Maxima uses inf to represent ∞.


Notice that Maxima displays the sum (unevaluated) using sigma
notation. By default, Maxima does not attempt to calculate the sums
of infinite series.
You can, however, tell Maxima to simplify the result of a summation,
which can sometimes result in it finding a value for a sum of an
infinite series, if it exists. To do this, you change the value of the
system variable simpsum, as shown below. (simpsum is short for
‘simplify sums’.)

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

Maxima now returns the sum of the series.

:∞
1
(e) Find .
n=1
n2

The commands introduced in Computer activity 61 are summarised as


follows.
Summing series
Operation Command Example
Sum a series sum( general term , index variable , sum(n∧2,n,1,10);
lower limit , upper limit )
Simplify summations simpsum:true simpsum:true;

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

Computer activity 62 Finding 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);

The taylor command calculates a Taylor polynomial for the function


that is its first argument. Its second argument specifies the input
variable of the function.
The third argument of the command is the point about which the
Taylor polynomial is to be found, which is also known as the centre of
the polynomial. The final argument of the command is the degree of
the Taylor polynomial required.
Notice that the Maxima output ends with ..., which indicates that
more terms could have been found. Also, the output line number is
followed by /T/. This indicates that the output is a (truncated)
Taylor series.

(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));

Here, the ''( ) command is needed to force Maxima to calculate the


Taylor polynomial which is then used to define p(x).
Without the ''( ) command, p(x) would be given by the expression
taylor(tan(x), x, 0, 5). So if you tried to find, for example,
p(3), then Maxima would interpret this to mean expression
taylor(tan(3), 3, 0, 5); but this is meaningless and would
therefore produce an error.
You first met the ''( ) command in Section 8 of this Guide.

(c) Express the Taylor polynomial p(x) found above in terms of the
variable y by typing
p(y);

As soon as a Taylor polynomial is used in a further calculation or


command, the trailing ... is dropped, and the Taylor polynomial is
converted to a rational expression. This is indicated by the marker
/R/ following the output line number.

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.

Maxima warns you it has replaced certain decimal numbers with


rational approximations when calculating these values.

The taylor command is summarised as follows.


Taylor polynomials
Operation Maxima Command Maxima Example
Find a Taylor polynomial taylor( function , variable , taylor(sin(x),x,0,3);
centre , degree )

Computer activity 63 Plotting Taylor polynomials


2
Consider the function f (x) = esin(x ) .
Plot a graph of the function and the graph of its quintic Taylor polynomial
about x = 1 on the same axes over the range 0 ≤ x ≤ 2.
(Remember, you learnt how to plot more than one function on the same
graph in Subsection 3.3 of this Guide.)

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.

13.1 Working with complex numbers


The imaginary number i is represented in Maxima by %i. You saw this in
Subsection 3.2 of this Guide, when you solved equations that have complex
solutions as well as real solutions. The usual arithmetic operations work
with complex numbers in Maxima, and there are commands for finding the
real and imaginary parts of a complex number, its conjugate, its modulus
and principal argument, as demonstrated in the following activity.

87
13 Complex numbers

Computer activity 64 Using complex numbers

(a) Assign the complex number 3 + 4i to the variable a, by entering


a:3+4*%i;

When Maxima displays a complex number, it usually arranges it with


the term in i as the first term, unless the imaginary part is negative
and the real part is positive.

(b) Similarly, assign the value 2 − 2i to b.


(c) Calculate a+b, a-b, a*b and a/b.

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.

(d) Find a*b in Cartesian form, by entering


rectform(a*b);

Find a/b in Cartesian form similarly.


(e) Find the real and imaginary parts of a by entering
realpart(a);
and
imagpart(a);

(f) Find the conjugate of a by entering


conjugate(a);

(g) Find the modulus and the principal argument of b by entering


abs(b);
and
carg(b);
respectively.

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.

Computer activity 65 Working with the polar form of complex


numbers
(a) Assign the complex numbers 3 (cos (5π/13) + i sin (5π/13)) and
4 (cos (7π/13) + i sin (7π/13)) to the variables c and d respectively.
(b) Use Maxima to find the moduli and principal values of c*d and c/d.
Hint: use the trigreduce command to simplify the initial answers
given.

The commands introduced in the activities above are summarised as


follows.

Working with complex numbers


Operation Maxima Command Maxima Example
Real part of a complex number realpart( ) realpart(1+2*%i);
Imaginary part of a complex number imagpart( ) imagpart(1+2*%i);
Conjugate of a complex number conjugate( ) conjugate(1+2*%i);
Modulus of a complex number abs( ) abs(1+2*%i);
Principal argument of a complex number carg( ) carg(1+2*%i);
Express a complex number in Cartesian form rectform( ) rectform(2/%i);

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

13.2 Solving polynomial equations


In Subsection 3.2 of this Guide you met the solve command that is used to
find solutions of equations. This command tries to find all the solutions of
the equation (if they can be found using algebraic manipulation), including
solutions that are non-real complex numbers. You might remember that in
Computer activity 20(e) you solved an equation with non-real solutions.

Computer activity 66 Solving polynomial equations

(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.

Notice that the solutions are given exactly, although in a rather


unwieldy form!
It is often more useful to find decimal approximations to solutions,
expressed in Cartesian form, which you can do using the float and
rectform commands.

(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

Plotting solutions in the complex plane


It is sometimes informative to plot the solutions of an equation in the
complex plane. You can do this in Maxima using the methods that you
learned in Subsection 11.1 of this Guide for plotting the discrete points
that form the graph of a sequence.
To plot the solutions of an equation, you first need to create a list of the
points to be plotted, with the first coordinate of each point being the real
part of a solution, and the second coordinate being the corresponding
imaginary part.
The following activity shows how you can do this.

Computer activity 67 Plotting the solutions of z 4 + 4z + 5 = 0


(a) Solve the equation
z 4 + 4z + 5 = 0
and assign the list of solutions to the variable s.

Each element of the list s is an equation of the form z=value , where


value is a solution of the equation.

(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));

The k th element of the first list s is s[k], so rhs(s[k]) is the


right-hand side of this element, which is the k th solution of the
original equation.
You met the makelist command in Subsection 11.1 of this Guide.
The index variable k starts with the value 1 and ends with the value
given by length(s), which is the number of elements in list s. This
ensures that all of the the solutions of the equation are included in
the list v.

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));

The k th solution of the original equation is v[k]. The point in the


complex plane corresponding to this solution has coordinates
(Re(v[k]), Im(v[k])) ,
which can be expressed in Maxima syntax as
[realpart(v[k]), imagpart(v[k])].

The command above uses makelist to create a list of such points,


one for each solution of the equation.

(d) Finally, plot the points found by entering


wxplot2d([discrete,pts],[style,points],[xlabel,""],[ylabel,""])

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.

Computer activity 67 introduced the length command, which is


summarised as follows.

Length of a list
Operation Command Example
Find the length of a list length( list ) length(A);

92
13 Complex numbers

Computer activity 68 Finding and plotting the seventh roots


of unity

(a) Find the seventh roots of unity by solving the equation


z 7 = 1.
Give the solutions in Cartesian form, with each real number, and the
real and imaginary parts of each complex number, correct to two
decimal places.
(b) Plot the solutions in the complex plane.

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

Maxima accessibility guide


This section outlines issues associated with the use of Maxima if you
interact with a computer using only a keyboard, use a screenreader or
require different colour settings. The information should help you decide
whether the wxMaxima interface is suitable for you, or whether you should
consider using an alternative interface, such as the command-line interface.
It also explains how to configure Maxima to make it easier for you to use
and contains an alternative version of Section 2 describing how to use the
command-line interface.

Using wxMaxima with a keyboard alone


The majority of the wxMaxima interface is accessible using a keyboard
alone. On a Windows computer you can access the wxMaxima menus by
pressing and releasing the Alt key, navigating through the menus using the
keyboard arrow keys, and then pressing Enter to make your selection.
Alternatively, you can press and hold down the Alt key, and then press the
keyboard key that corresponds to the underlined letter in a menu entry to
select it. In both cases, you can leave menu navigation without making a
selection by pressing the Esc key.
On an Apple Mac you can access the wxMaxima menus by pressing and
releasing the F2 key while holding down the ctrl and fn keys (or just ctrl
on some keyboards), navigating through the menus using the keyboard
arrow keys, and then pressing Enter to make your selection. You can
leave menu navigation without making a selection by pressing the Esc key.
The wxMaxima toolbar cannot be accessed using the keyboard alone, but
this is not used extensively in this Guide and alternative typed commands
for accessing the functions are given as required.

Changing wxMaxima colours and fonts


You can change the appearance of the text used by wxMaxima as follows.
First, click on the following toolbar icon.

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.

Using a screen magnifier or screenreader


The text in wxMaxima can become pixelated when you use a screen
magnifier. An alternative is to increase the size of the text font as
described above and/or use the zooming facilities on the Edit menu, which
you can also access using Alt-I (zoom in) and Alt-O (zoom out).
The wxMaxima interface is not accessible to a screenreader. If you use a
screenreader you might wish to consider using the command-line interface
to Maxima instead of the wxMaxima interface. You should ensure your
screenreader is set to read all the punctuation. Details of using Maxima
with the command-line interface are given below. The graphs produced by
Maxima are not accessible to a screenreader. You might need assistance
when using these.

95
Maxima accessibility guide

Changing graph properties


You can change the thickness of curves plotted in graphs by including an
additional argument in the wxplot2d command, of the form
[style, [lines, 3]]
where the number indicates how thick the line should be. By default, lines
have thickness 1.
So, to plot a graph of the equation y = 2x with a thicker line, enter, for
example,
wxplot2d(2*x, [x, 0, 1], [style, [lines, 3]]);

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.

Getting started with Maxima using the


command-line interface
This section describes how to use Maxima with the command-line
interface. If you are using this interface you should read this section
instead of Section 2 of this Guide, which this replaces. Differences between
the wxMaxima interface and the command-line interface in later sections
are minor and are mentioned within those sections when necessary.
Activities in this section are numbered to match the corresponding activity
in Section 2. The format of the solutions given at the end of this Guide
may not exactly match the output you obtain using the command-line
interface.
If you encounter unexpected problems when working through this section,
remember to check the Frequently asked questions (FAQ) section on the
OU Maxima website: learn1.open.ac.uk/site/maxima.

Using Maxima

Computer activity 2 Starting Maxima

Start the command-line interface to Maxima 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

The command-line interface to Maxima is illustrated in Figure 12.

Figure 12 The initial command-line interface window


97
Maxima accessibility guide

At the top of the window is some introductory text, followed by


(%i1)
This is how Maxima labels lines. The i stands for ‘input’: this is input line
number 1 and is where you can type your first command. These commands
either instruct Maxima to perform calculations or change system settings.
The percentage symbol (%) is used by Maxima to indicate objects built
into the system. You will learn more about this later.
The following activity shows you how to use Maxima to perform a simple
calculation. Follow the steps using Maxima as you read the activity.

Computer activity 3 Your first Maxima calculation

Follow these steps to use Maxima to calculate 2 + 3 × 45 .


1. Click anywhere on the Maxima window, to ensure that the text you
type next is directed to the correct place.
2. Type the following exactly as it appears here:
2+3*4/5;
including the semicolon (;) at the end.

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.

Computer activity 5 Configuring the Maxima display of


mathematics
You should only do this activity if you wish to change how Maxima
displays mathematics.
(a) First exit Maxima by entering the command
quit();
(on some installations you may also have to close the window).
(b) Turn off the two-dimensional display of mathematics by adding the
Maxima command display2d:false; to your maxima-init.mac
configuration file, as follows.
(i) Follow the instructions in the Accessibility section of the OU
Maxima website to locate your maxima-init.mac configuration
file, or create one in the correct location as appropriate.

99
Maxima accessibility guide

(ii) Open your maxima-init.mac file in a plain text editor (such as


Notepad on a Windows computer, or TextEdit on an Apple Mac),
and add the text
display2d:false;
on a new line. There are further details on how to do this in the
Accessibility section of the OU Maxima website.
(iii) Save your modified maxima-init.mac, and close your text editor.
(c) Restart Maxima and enter the calculation from Computer activity 3
again, that is, enter
2+3*4/5;

Notice that Maxima now displays the result on a single line:


22/5

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.

To enable the Lisp debugger set *debugger-hook* to nil.

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.

Basic calculations using Maxima


In Computer activity 3 you were asked to enter a numerical expression into
Maxima using the symbols + for addition, * for multiplication and / for
division. Maxima evaluated it using the rules for the correct order of
mathematical operations; that is, the BIDMAS rules. The way in which
calculations and commands have to be entered in Maxima is known as its
syntax.
The Maxima syntax for basic mathematical operations is summarised
below.
Basic mathematical operations
Operation Syntax Example
Addition + 4+3;
Subtraction - 4-3;
Multiplication * 4*3;
Division / 4/3;
Brackets ( and )
2*(3+4);
Powers, for example 23 ∧
or **
2∧3;
√ 2**3;
Square root, for example 5 sqrt( ) sqrt(5);
Magnitude (absolute value) abs( ) abs(-3);

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

Warning: Do not omit multiplication signs!


A common error when first using Maxima is to omit multiplication
signs. For example, you might type
• 2sqrt(2) rather than 2*sqrt(2), or
• 2(3+4) rather than 2*(3+4).
Doing this will result in an error. The displayed error message might
include one of the following statements:
• parser: incomplete number; missing exponent?
• incorrect syntax: Syntax error
incorrect syntax: Too many )’s
incorrect syntax: Premature termination of input at ;.
• ... is not an infix operator
If you receive one of these error messages, first check for missing
multiplication signs!

Warning: Take care with question marks (?)


Do not type question marks when asking Maxima to evaluate an
expression. The symbol ? is a special symbol in Maxima which
provides access to underlying systems.
The one exception to this is when you are using the commands for
obtaining help from the system, which you will see later.

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.

Computer activity 6 Calculating cube roots


√ 1 √
(a) Remembering that 3 27 = 27 3 , calculate 3 27 by entering the
following line into Maxima.
27∧(1/3);

Remember to press Enter to evaluate the command.

(b) What happens if you enter


27∧1/3;
instead? Can you explain this?

102
Maxima accessibility guide

Maxima usually tries to calculate quantities exactly rather than


approximating them by decimal numbers. It does this by manipulating the
symbols in the expression according to the rules of mathematics. This is
sometimes known as symbolic computation. You can see an example of
this in the next activity, which also shows you two different ways to
instruct Maxima to output a decimal answer instead.

Computer activity 7 Obtaining exact and approximate answers

In Maxima, calculate 1309/3451 in three different ways, by entering each


of the following expressions in turn.
(a) 1309/3451; (b) 1309.0/3451; (c) float(1309/3451);

Maxima returns an exact answer for part (a).


Since part (b) involves a decimal number 1309.0, Maxima returns a
decimal approximation to the answer.
In part (c), the command float instructs Maxima to return a
decimal answer.

Converting to decimal numbers


Operation Command Example
Convert to a decimal number float( ) float(sqrt(2));

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

Computer activity 8 Simplifying and approximating numerical


expressions

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 .

Maxima knows the values of standard mathematical constants such as the


irrational numbers e and π. It treats them symbolically unless you
explicitly ask for them in floating point form.
The constants e and π
Constant Syntax Example
e %e %e∧2;
π %pi 2*%pi;

As with the input and output line labels, the ‘%’ symbol indicates the
name of a quantity built into Maxima.

Computer activity 9 Working with built-in constants


π
Use Maxima to calculate the value of the expression π + + e2 , both
3
exactly and as a decimal number.

Notice that in the exact answer, Maxima displays π and e in the form
they were entered: %pi and %e.

Reusing and editing commands


In Computer activity 9, you may have entered the expression twice, once
to evaluate it exactly and once for a decimal answer. This is, however, not
necessary. When you have entered and evaluated an expression, you can
edit it and then evaluate it again, as shown in the following activity.
104
Maxima accessibility guide

Computer activity 10 Editing a command


√ √
(a) Calculate 2 3 + 5 27 by entering the following line into Maxima.
2*sqrt(3)+5*sqrt(27);
√ √
(b) Edit your entry in part (a) to calculate 2 3 − 5 27 as follows.
1. Press the keyboard up arrow key once, so that the previously
entered command appears against the current input line number
(on an Apple Mac you may need to hold down the Alt key while
pressing the keyboard up arrow key once).

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 .

Maxima also permits the result of one calculation to be used in another


calculation. The symbol % represents the result of the last evaluated
command. So, for example, if you enter sqrt(%); Maxima calculates the
square root of the last evaluated output. You can also use the output (or
input) of other cells, by typing the cell line label in a calculation. For
example, if you enter %o5∧3; Maxima calculates the cube of the expression
in output line 5.

Computer activity 11 Using the results of previous calculations

(a) Enter 6*2; into Maxima and evaluate it.


(b) On the following input line type 3+%; and enter it.

Maxima returns 15, the sum of 3 and the previous answer.

(c) Enter %o +5; with replaced by the output line number


corresponding to the result of 6*2 entered earlier.

This command adds 5 to the result of the line referenced.

105
Maxima accessibility guide

Assigning values to variables


Maxima allows you to assign a value to a variable, and then use the
variable in further calculations.
For example, you can assign the value 23 to the variable a, and then
evaluate an expression in a, such as a2 − 3a + 2. You can also assign
expressions, both numerical and (as you will see later) algebraic, and
indeed any other Maxima object, to a variable, and use that variable in
subsequent commands.
To assign a value to a variable you use a colon (:). For example, the
command
a:23;
assigns the value 23 to the variable a. The colon can be read as ‘is
assigned the value’.

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

Variable names are case-sensitive; for example, the variable x is different


from the variable X.
Once a variable has been assigned a value, Maxima will remember this
value for the rest of your session. This may sometimes surprise you. It is
easy to forget that earlier in the day you assigned a value to, say, x; you
may then be confused later on when a calculation involving x gives an
unexpected result. You can, however, tell Maxima to ‘forget’ about a
variable to which you have previously assigned a value. You can also ask it
to list all the variables that you have assigned values to. These commands
are demonstrated in the following activity.

106
Maxima accessibility guide

Computer activity 12 Working with variables



(a) Assign the value of 8 to the variable a by entering a: sqrt(8);

The value of a is displayed as output, in an equivalent form.

(b) Enter a;

This displays the current value of 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.

The variable names are given within square brackets, separated by


commas. This is how Maxima displays lists.

(g) Enter kill(a); to remove the variable a from the system.

You should obtain the output done

(h) Enter a; to display the value of a.

The variable name is output, as a no longer has a value.

(i) Enter b; to display the value of b.

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.

You can practise using variables in the following activity.

Computer activity 13 Using variables

(a) Define the variable a to have the value 42.


(b) Define the variable b to be equal to a3 − 3a + 4.
(c) Define the variable c to be the decimal approximation of the square
root of b.

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

Computer activity 14 Displaying a specified number of significant


figures

Display the decimal approximation of π to 8 significant figures by doing


the following.
(a) Set the system variable fpprintprec to be 8.
(b) Display the decimal approximation of π.

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();

Another useful system variable is leftjust. Setting this to be equal to


true using
leftjust:true;
makes Maxima display the result of a command left-justified against the
output line number. The default value of leftjust is false, which
displays output centred in the line.
Note that the list of variables displayed when typing 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.

109
Maxima accessibility guide

Saving and printing your work


After working with Maxima you will probably want to save your
calculations so that you can reuse or read them at a later date.
When you are using the command-line interface you cannot save the
session directly, as you do when saving other files. Instead there are two
stages in saving your work:
• If you want to keep a record of the contents of the command-line
window, then you need to save a transcript of the session.
• If you want to save the values of all the variables, so that you can
continue working with them in a new Maxima session, then you will
need to save the current state of the system. Note that this does not
give you access to the commands used to define the variables, so you
cannot edit them in the new session.
These two processes are illustrated in Computer activity 16.
When saving your work, you need to tell Maxima exactly where to save
the file containing the session state or your transcript by giving the
complete pathname of the file, which includes not only the name of the file
but also the hierarchy of folders in which the file is located. Unless you do
this, Maxima will try to save the file in the location in which the system is
installed on your computer. Not only is this not recommended, but as a
computer user, you may not have sufficient permission to do this.
The pathname of a file depends on its location, the type of computer you
are using, and your computer username. In the following activity, we
assume that a user with the computer username ‘bill’ wishes to save a
transcript of his Maxima session in a file called transcript.txt within a
folder called maxima which he created in Computer activity 1. The maxima
folder is within Bill’s ‘Documents’ area on a recent Windows computer
(that is, Windows vista, 7 or 8). In this case, the full pathname of his file is
C:/Users/bill/Documents/maxima/transcript.txt
(Notice that Maxima separates parts of the pathname with a forwards
slash (/) rather than the usual Windows backwards slash (\).)
If Bill were using a older Windows computer (such as Windows XP), the
equivalent pathname would be
C:/Documents and Settings/bill/Documents/maxima/transcript.txt
or using an Apple Mac the equivalent is
/Users/bill/Documents/maxima/transcript.txt

110
Maxima accessibility guide

Computer activity 16 Saving your work

(a) Create a transcript of your current session by following these steps.


(i) Enter
writefile("C:/Users/bill/Documents/maxima/transcript.txt");
replacing the pathname with one appropriate to you and your
system.

The path of file is given in double-quote marks.


This tells Maxima to save a copy of all the subsequent input and
outline lines to the file named transcript.txt in your chosen folder.
The output
Starts dribbling to
C:/Users/bill/Documents/maxima/transcript.txt
is given, where the pathname is the one you gave in the command,
followed by the current date and time (in a probably incorrect
timezone!). Some computer implementations may produce a different
output.

(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();

This stops the recording of the session into the file.


The output Finished dribbling to
C:/Users/bill/Documents/maxima/transcript.txt is given.
Again, some computer implementations may produce a different
output.

111
Maxima accessibility guide

(iv) Find the file transcript.txt on your computer and open it


using a text editor, for example, Microsoft Word.

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 save your current session to the file


mysession.txt in your chosen folder.
The path of the file is output.
The file is stored using a form that Maxima can reprocess.

(ii) Close Maxima by entering


quit();

(iii) Restart Maxima in the usual way.


(iv) Load your previously saved session by entering
load("C:/Users/bill/Documents/maxima/mysession.txt");
using the same pathname you used in part (b)(i).

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.

An alternative way of using the writefile and closefile commands is to


enter the first at the very start of your session and the second at the end,
so that everything you do is recorded.
Saving your work
Operation Command
Start writing a transcript writefile(" file path ");
Stop writing a transcript closefile();
Playback all the input and playback();
output in a session
Playback a range of input and playback([ start line number , end line number ]);
output
Save the state of a session save(" file path ", all);
Reload a session load(" file path ");

You can also obtain an image of the Maxima window by taking a


‘screenshot’. To do this on a Microsoft Windows computer, first click on
the Maxima 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 of
the Maxima window, 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
Maxima window and click. This stores the image of the Maxima window,
which you can then paste into a suitable application. You may also like to
use the Grab application from the Utilities folder.

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.

Computer activity 17 Getting help!

(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.

If more than one title is displayed in response to a ?? command, then


Maxima will not continue until you enter one of the following:
• the appropriate number, to display your chosen information
• several numbers, separated by spaces, to see help information
on several topics
• all to display the information on all topics listed, or
• none to see no information.

114
Maxima accessibility guide

Help 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);

Note 1 : the space after the ?, which is needed.


Note 2 : the second pair of commands displays a list of the titles of all
help information pages whose title contains the given text. To obtain
help on a particular topic listed, type the number corresponding to the
required title in the list.

There is further help with Maxima in the Frequently asked questions


section of the OU Maxima website, at learn1.open.ac.uk/site/maxima.
If you are reading this section as an alternative to Section 2, you should
now continue with Section 3. Note, however, the information below
regarding the plotting of graphs, which you will need when studying
Subsection 3.3.

Plotting graphs using the command-line interface


When using the command-line interface, you should use the plot2d
command rather than the wxplot2d command described in Subsection 3.3.
These commands work similarly, and have the same arguments. The main
difference is that plot2d opens a new computer window containing the
graph.
On some computer systems, the plot2d command opens two windows, one
containing the graph and a second containing a command-line interface to
gnuplot, which is the system used by Maxima to plot graphs. To prevent
this second window opening each time, enter the following command.
gnuplot view args: "-persist ∼s";

The Accessibility section of the OU Maxima website contains details of


how to configure Maxima to automatically prevent the display of this
second window.
The graph window can be closed by pressing the usual cross at the top
right-hand corner, or by pressing Alt-F4. You will not be able to enter
any commands into the Maxima command-line interface until the graphing
window is closed.
The graph can be printed using the print button on the graph window, or
saved as an enhanced metafile (.emf) file using the save button. These files
can be opened with many image viewing programs and can be inserted
into word-processed documents.

115
Computer methods for CAS Activities in Books A–D

Computer methods for CAS Activities


in Books A–D
Computer solution to Unit 5, Activity 17
First, load the implicit plot package and set the default plotting options
to use equal scales on the x- and y-axes.
(%i1) load(implicit plot);
(%o1) C:/PROGRA∼1/MAXIMA∼1.0/share/maxima/5.30.0/share/contrib/implicit plot.lisp

(%i2) set plot option([gnuplot preamble, "set size ratio -1"])$

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.

(%i5) wximplicit plot([p, c], [x,0,7], [y,0,7]);

(%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).

(c) The maximum number of intersections of a circle and a parabola is


four. This fact can be justified by the geometric argument that each
‘half’ of the parabola (each part on one side of the vertex) can meet
the circle at most twice.
Alternatively, if the equation of the parabola is used to substitute for
y in the equation of the circle, then an equation for x containing terms
in x4 , x3 , x2 , x and a constant term is obtained, and such an equation
can have at most four solutions (by a result that you will meet in
Unit 12).

Computer solution to Unit 7, Activity 23


(a) The function f is defined as follows.
(%i1) f(x):=(sqrt(1+x


2))/8+(2-x)/16;
1+x2 2-x
(%o1) f(x):= + ;
8 16

(b) The graph of f (x) is plotted below.


(%i2) wxplot2d(f(x),[x,0,2]);

(%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

Maxima returns a rearranged version of the equation, but does not


solve it. The solve command cannot find an exact solution of
equation df(x)=0, so we look for an approximation to the solution
instead.
To do this we need to find an interval containing the solution. We
know from the graph of f (x) that its gradient is negative to the left of
the minimum, and in particular at x = 0, so df(0)< 0. Also, the
gradient of f (x) is positive to the right of the minimum, in particular
at x = 1, so df(1)> 0. So a solution of df(x)=0 must lie in the
interval [0, 1]. An alternative way to find this interval is to plot a
graph of df(x).
(%i5) find root(df(x),x,0,1);
(%o5) 0.57735026918963
The solution of the equation f ! (x) = 0 is x = 0.577 (to 3 s.f.).
(f) The man should join the road 0.58 km (to the nearest 10 metres) along
from the point that is closest to his initial position.
(Because the graph of f indicates that the minimum value of f (x) occurs
at a local minimum rather than at one of the endpoints of the interval
[0, 2], in the solution above we don’t consider the values of f (0) and f (2).)

118
Computer methods for CAS Activities in Books A–D

Computer solution to Unit 8, Activity 48


(a) The domain of f is the interval [−1, ∞).
(b) The graph of f can be plotted as follows.
(%i1) f(x):=(x∧2-10*x+15)/(1+sqrt(x+1));
x2 -10 x+15
(%o1) f(x):= √ ;
1+ x+1
(%i2) wxplot2d(f(x), [x,-1,15]);

(%t2)

(%o2)

(c) The x-intercepts of f can be found by solving f (x) = 0.


First, solve the equation, assigning the result to the variable solns.
(%i3) solns:solve(f(x)=0);
√ √
(%o3) [x=5- 10, x= 10+5]
Next, extract the two solutions from the list and assign them to the
variables sol1 and sol2 respectively.
(%i4) sol1:rhs(solns[1]);

(%o4) 5- 10
(%i5) sol2:rhs(solns[2]);

(%o5) 10+5
Finally, express the solutions as decimal approximations.
(%i6) float(sol1);
(%o6) 1.837722339831621
(%i7) float(sol2);
(%o7) 8.16227766016838
So the two x-intercepts of f are 1.84 and 8.16 (to 3 s.f.).

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

We shall concentrate on evaluating


& 8.162... 2
x − 10x + 15
√ dx,
1.837... 1+ x+1
that is,
& 8.162...
f (x) dx,
1.837...
remembering the required answer is the negative of this integral.
The integrate command cannot evaluate this definite integral, so we
find an approximate value instead.
(%i8) quad qags(f(x),x,sol1,sol2);
(%o8) [-12.37959499949233,1.3744111403970839 10-13 ,21,0]

So
& 8.162...
f (x) dx = −12.4 (to 3 s.f.).
1.837...

Remembering the required area is the negative of this, the required


area is 12.4 (to 3 s.f.).

Computer solution to Unit 8, Activity 49


The area of the cross-section, in square centimetres, is
& 1.5 '
1
3 x3 + 1 dx.
−1

The integrate command cannot evaluate this definite integral, so we find


an approximate value instead. First, assign the integrand to the variable y.
(%i1) y:(1/3)*sqrt(x∧3+1);

x3 +1
(%o1)
3
Then find an approximate value for the definite integral.
(%i2) quad qags(y,x,-1,1.5);
(%o2) [0.93924271889094,7.1021410974481114 10-10 ,231,0]

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

Computer solution to Unit 8, Activity 50


The change in the displacement of the object from time t = 0 to t = 10 is
& 10 8 2 9
t
sin dt.
0 150

The integrate command calculates this definite integral in terms of


values of the Error function, erf. Instead, we shall find an approximation
to its value using the quad qags command.
(%i1) quad qags(sin(t∧2/150),t,0,10);
(%o1) [2.15266541148388,2.3899387041435914 10-14 ,21,0]

So the value of the definite integral is 2.15 (to 2 d.p.).


The displacement of the object at time t = 10 is (6 + 2.15) m = 8.15 m, to
the nearest centimetre.

Computer solution to Unit 9, Activity 28


(a) The matrix form of the equations is
    
2 2 3 x 2
2 3 4  y  = −1 .
4 7 10 z 3

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

The inverse of A can be found as follows.


(%i3) invert(A);
 
1
1 2 - 12
(%o3) -2 4 -1 
1 -3 1

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

The solution is x = 0, y = −11, z = 8.


Note that an alternative way to solve these equations using Maxima is
to use the solve command, as follows.
(%i5) solve([2*x+2*y+3*z=2, 2*x+3*y+4*z=-1, 4*x+7*y+10*z=3], [x,y,z]);
(%o5) [[x=0,y=-11,z=8]]

(b) The matrix form of the equations is


    
3 2 1 x 1
4 3 1 y  = 2 .
7 5 1 z 1

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

The inverse of A can be found as follows.


(%i8) invert(A);
 
2 -3 1
(%o8) -3 4 -1
1 1 -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

This can be calculated using


(%i9) invert(A).b;
 
-3
(%o9)  4 
2

The solution is x = −3, y = 4, z = 2.


Note that an alternative way to solve these equations using Maxima is
to use the solve command, as follows.
(%i10) solve([3*x+2*y+z=1, 4*x+3*y+z=2, 7*x+5*y+z=1], [x,y,z]);
(%o10) [[x=-3,y=4,z=2]]

Computer solution to Unit 9, Activity 29


(a) The matrix form of the equations is
    
1 2 3 x 5
2 3 1 y  = 6 .
4 7 7 z 1
 
1 2 3
The coefficient matrix is 2 3 1. Its determinant can be found
4 7 7
using Maxima as follows.
(%i1) determinant(matrix([1,2,3],[2,3,1],[4,7,7]));
(%o1) 0
The determinant of the coefficient matrix is zero, so the coefficient
matrix is non-invertible and the equations do not have a unique
solution.
(b) The matrix form of the equations is
    
2 2 3 x 5
2 3 1  y = 6 .
 
4 7 7 z 1
 
2 2 3
The coefficient matrix is 2 3 1. Its determinant can be found
4 7 7
using Maxima as follows.
(%i2) determinant(matrix([2,2,3],[2,3,1],[4,7,7]));
(%o2) 14
The determinant of the coefficient matrix is 14. This is non-zero, so

123
Computer methods for CAS Activities in Books A–D

the coefficient matrix is invertible and the equations have a unique


solution.
(c) The matrix form of the equations is
    
1 1 −1 1 x 0
1 −1 1 1   y  2
   =  .
2 0 3 −1 w 1
6 2 4 0 z 0
 
1 1 −1 1
1 −1 1 1
The coefficient matrix is 2
.
0 3 −1
6 2 4 0
Its determinant can be found using Maxima as follows.
(%i3) determinant(matrix([1,1,-1,1],[1,-1,1,1],[2,0,3,-1],[6,2,4,0]));
(%o3) 0
The determinant of the coefficient matrix is zero, so the coefficient
matrix is non-invertible and the equations do not have a unique
solution.

Computer solution to Unit 10, Activity 20


(a) xn = − 31 (1.2)n (n = 1, 2, 3, . . .).
The first 30 points on the graph of the sequence (xn ) can be plotted as
follows.
First, define the sequence.
(%i1) x[n]:=-(1/3)*(1.2)
8 9

n;
1 n
(%o1) xn := − 1.2
3

Then generate the points to be plotted and plot them.


(%i2) xpts:makelist([n,x[n]],n,1,30)$
(%i3) wxplot2d([discrete,xpts], [style,points], [xlabel,"n"], [ylabel,"x[n]"]);

(%t3)

(%o3)

The sequence (xn ) is decreasing and xn → −∞ as n → ∞.

124
Computer methods for CAS Activities in Books A–D

(b) yn = 5(−0.9)n (n = 1, 2, 3, . . .).


The first 30 points on the graph of the sequence (yn ) can be plotted as
follows.
First, define the sequence.
(%i4) y[n]:=5*(-0.9)∧n;
(%o4) yn :=5(-0.9)n

Then generate the points to be plotted and plot them.


(%i5) ypts:makelist([n,y[n]],n,1,30)$
(%i6) wxplot2d([discrete,ypts], [style,points], [xlabel,"n"], [ylabel,"y[n]"]);

(%t6)

(%o6)

The sequence (yn ) alternates in sign and yn → 0 as n → ∞.


1
(c) zn = − 10 (−2.5)n (n = 1, 2, 3, . . .).
The first 15 points on the graph of the sequence (zn ) can be plotted as
follows.
First, define the sequence.
(%i7) z[n]:=-(1/10)*(-2.5)
8 9

n;
1
(%o7) zn := − (-2.5)n
10

125
Computer methods for CAS Activities in Books A–D

Then generate the points to be plotted and plot them.


(%i8) zpts:makelist([n,z[n]],n,1,15)$
(%i9) wxplot2d([discrete,zpts], [style,points], [xlabel,"n"], [ylabel,"z[n]"]);

(%t9)

(%o9)

The sequence (zn ) alternates in sign and is unbounded.

Computer solution to Unit 10, Activity 21


(a) an = 17 − 31 (1.2)n (n = 1, 2, 3, . . .).
The first 30 points on the graph of the sequence (an ) can be plotted as
follows.
First, define the sequence.
(%i1) a[n]:=17-(1/3)*(1.2)∧n;
1
(%o1) an :=17- 1.2n
3
Then generate the points to be plotted and plot them.
(%i2) apts:makelist([n,a[n]],n,1,30)$
(%i3) wxplot2d([discrete,apts], [style,points], [xlabel,"n"], [ylabel,"a[n]"]);

(%t3)

(%o3)

The sequence (an ) is decreasing and an → −∞ as n → ∞.

126
Computer methods for CAS Activities in Books A–D

(b) bn = 5(−0.9)n + 45 (n = 1, 2, 3, . . .).


The first 30 points on the graph of the sequence (bn ) can be plotted as
follows.
First, define the sequence.
(%i4) b[n]:=5*(-0.9)∧n+45;
(%o4) bn :=5(-0.9)n +45

Then generate the points to be plotted and plot them.


(%i5) bpts:makelist([n,b[n]],n,1,30)$
(%i6) wxplot2d([discrete,bpts], [style,points], [xlabel,"n"], [ylabel,"b[n]"]);

(%t6)

(%o6)

The terms of (bn ) alternate either side of 45 and bn → 45 as n → ∞.

127
Solutions to Computer activities

Solutions to Computer activities


Solution to Computer activity 3
(%i1) 2+3*4/5;
22
(%o1)
5
So 2 + 3 × 45 = 22
5 .

Solution to Computer activity 6


(a) (%i1) 27∧(1/3);
(%o1) 3

(b) (%i2) 27∧1/3;


(%o2) 9
Without any brackets, 27∧1/3 is interpreted according to the
BIDMAS rules, as (271 )/3 which is equal to 9.
Do not be surprised if your line numbering differs from ours. Each of
our solutions is prepared as a separate Maxima session with the line
numbering starting at 1 (unless it is a continuation of a previous
activity); your numbering will continue to increase for the duration of
your session.

Solution to Computer activity 7


(a) (%i1) 1309/3451;
11
(%o1)
29
So 1309/3451 = 11
29 .
(b) (%i2) 1309.0/3451;
(%o2) 0.37931034482759
So 1309.0/3451 ≈ 0.37931034482759.
(c) (%i3) float(1309/3451);
(%o3) 0.37931034482759
So 1309/3451 ≈ 0.37931034482759.

128
Solutions to Computer activities

Solution to Computer activity 8


(a) (%i1) sqrt(147);

(%o1) 7 3
(%i2) float(sqrt(147));
(%o2) 12.12435565298214
√ √
So 147 = 7 3 ≈ 12.12435565298214.
(b) (%i3) (8/5)∧(2/3);
4
(%o3) 2/3
5
(%i4) float((8/5)∧(2/3));
(%o4) 1.367980757341358
8 92/3
8 4
So = 2/3 ≈ 1.367980757341358.
5 5
(c) (%i5) 2∧500;
(%o5) 327339060789614187001318969682[91 digits]217256545885393053328527589376

(%i6) float(2∧500);
(%o6) 3.2733906078961419 10150
So 2500 ≈ 3.2733906078961419 × 10150 .

Solution to Computer activity 9


(%i1) %pi + %pi/3 + %e∧2;

(%o1) +%e2
3
(%i2) float(%pi + %pi/3 + %e∧2);
(%o2) 11.57784630371704
π 4π
So π + + e2 = + e2 ≈ 11.57784630371704.
3 3
Solution to Computer activity 10
(a) (%i1) 2*sqrt(3)+5*sqrt(27);

(%o1) 17 3
√ √ √
So 2 3 + 5 27 = 17 3.
(b) (%i2) 2*sqrt(3)-5*sqrt(27);

(%o2) -13 3
√ √ √
So 2 3 − 5 27 = −13 3.

129
Solutions to Computer activities

Solution to Computer activity 11


At the end of this activity, your worksheet should look like the following,
although line numbers may differ.
(%i4) 6*2;
(%o4) 12
(%i5) 3+%;
(%o5) 15
(%i6) %o4+5;
(%o6) 17

Solution to Computer activity 12


(a) (%i1) a: sqrt(8);
(%o1) 23/2

(b) (%i2) a;
(%o2) 23/2

(c) (%i3) b: a*sqrt(2);


(%o3) 4

(d) (%i4) a:
√ sqrt(7);
(%o4) 7

(e) (%i5) b;
(%o5) 4

(f) (%i6) values;


(%o6) [a,b]

(g) (%i7) kill(a);


(%o7) done

(h) (%i8) a;
(%o8) a

(i) (%i9) b;
(%o9) 4

130
Solutions to Computer activities

Solution to Computer activity 13


(%i1) a:42;
(%o1) 42
(%i2) b:a∧3-3*a+4;
(%o2) 73966
(%i3) c:float(sqrt(b));
(%o3) 271.9669097519035

Solution to Computer activity 14


(%i1) fpprintprec:8;
(%o1) 8
(This sets the number of significant figures to be shown in the display of
decimal numbers.)
(%i2) float(%pi);
(%o2) 3.1415927
So the value of π is 3.1415927 (to 8 s.f.).

Solution to Computer activity 15


The circumference of a circle of radius 5 is 31.42 (to 2 d.p.) and the area is
78.54 (to 2 d.p.).

Solution to Computer activity 17


(a) (%i1) ? float;
-- Function: float (<expr>)
Converts integers, rational numbers and bigfloats in <expr> to
floating point numbers. It is also an ‘evflag’, ‘float’ causes
non-integral rational numbers and bigfloat numbers to be converted
to floating point.
There are also some inexact matches for ‘float’.
Try ‘?? float’ to see them.
(%o1) true

(b) (%i2) ?? sqr;


0: isqrt (Functions and Variables for Number Theory)
1: sqrt (Root Exponential and Logarithmic Functions)
2: sqrtdenest (Package sqdnst)
3: sqrtdispflag (Functions and Variables for Display)
Enter space-separated numbers, ‘all’ or ‘none’: 1;
-- Function: sqrt (<x>)
The square root of <x>. It is represented internally by
‘<x>∧(1/2)’. See also ‘rootscontract’.
‘radexpand’ if ‘true’ will cause nth roots of factors of a product
which are powers of n to be pulled outside of the radical, e.g.
‘sqrt(16*x∧2)’ will become ‘4*x’ only if ‘radexpand’ is ‘true’.
(%o2) true
131
Solutions to Computer activities

Solution to Computer activity 18


(a) (%i1) expand( (2+x)*(3*x+4)∧ 3 );
(%o1) 27x4 +162x3 +360x2 +352x+128
So (2 + x)(3x + 4)3 = 27x4 + 162x3 + 360x2 + 352x + 128.
(b) (%i2) factor( 2*x∧3-7*x∧2-10*x+24 );
(%o2) (x-4)(x+2)(2x-3)
So 2x3 − 7x2 − 10x + 24 = (x − 4)(x + 2)(2x − 3).
(c) (%i3) p:(x∧3+1)/(x+1);
x3 +1
(%o3)
x+1

(d) (%i4) fullratsimp(p);


(%o4) x2 -x+1

(e) (%i5) subst(3,x,p);


(%o5) 7

Solution to Computer activity 19


(a) (%i1) r: x∧2+2*x=4;
(%o1) x2 +2x=4

(b) (%i2) lhs(r);


(%o2) x2 +2x

(c) (%i3) rhs(r);


(%o3) 4

Solution to Computer activity 20


(a) (%i1) solve(
√ x 2+2*x=1

√ );
(%o1) [x=- 2-1, x= 2-1]
√ √
The solutions of the equation are x = − 2 − 1 and x = 2 − 1.
(b) (%i2) solve( 4*x∧2-12*x+9=0 );
3
(%o2) [x= ]
2
The solution of the equation is x = 32 .

132
Solutions to Computer activities

(c) (%i3) solve( 2*x∧3+x∧2-5*x+2=0 );


1
(%o3) [x= , x=-2, x=1]
2
The solutions of the equation are x = 12 , x = −2 and x = 1.
(d) (%i4) solve( x∧9+2*x-4=0 );
(%o4) [0=x9 +2x-4]
Maxima was unable to solve this equation.
(e) (%i5) solve( x∧2-4*x+5=0 );
(%o5) [x=2-%i, x=%i+2]
The two complex solutions are x = 2 − i and x = 2 + i. There are no
real solutions.

Solution to Computer activity 21


(a) (%i1) A: [2,3,5,7,11];
(%o1) [2,3,5,7,11]

(b) (%i2) A[4];


(%o2) 7
So the fourth element of A is 4.
(c) (i) (%i3) solns:solve(x
√ √2-x-1=0);

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

Solution to Computer activity 22


(a) (%i1) eq: 3*y+4=3*x∧2+9*x;
(%o1) 3y+4=3x2 +9x;

(b) (%i2) eq-4;


(%o2) 3y=3x2 +9x-4;

(c) (%i3) %/3;


3x2 +9x-4
(%o3) y=
3

133
Solutions to Computer activities

Solution to Computer activity 23


(a) (%i1) eqn:c=(2*a+b+3*c)/(a-b);
2a+b+3c
(%o1) c=
a-b

(b) (%i2) solve(eqn, a);


(b+3)c+b
(%o2) [a= ]
c-2
(b + 3)c + b
So a = .
c−2
Solution to Computer activity 24
(a) (%i1) eq1:3*x∧2+2*y=20;
(%o1) 2y+3x2 =20
(%i2) eq2:4*x-3*y=-4;
(%o2) 4x-3y=-4

(b) (%i3) solve( [eq1,eq2], [x,y] );


(%o3) [[x=2, y=4] , [ x=- 26 68
9 , y=- 27 ]]
The two solutions are x = 2, y = 4 and x = − 26 68
9 , y = − 27 .

Solution to Computer activity 25


(a) (%i1) wxplot2d( 4*x∧2-8*x+2, [x,-1,2]);

(%t1)

(%o1)

134
Solutions to Computer activities

(b) (%i2) wxplot2d( 4*x∧2-8*x+2, [x,-1,2], [y,-5,5]);


plot2d: some values were clipped.

(%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)

Solution to Computer activity 26


(a) (%i1) wxplot2d( [15*t∧3+10*t, 60*t], [t,0,2] );

(%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)

Solution to Computer activity 27


(a) (%i1) f(x):=x∧5-3*x∧2+4;
(%o1) f(x):=x5 -3x2 +4;

(b) (%i2) f(2);


(%o2) 24
So f (2) = 24.
(c) (%i3) g(x):= (x-1)/(x-2);
x-1
(%o3) g(x):= ;
x-2
(%i4) g(3);
(%o4) 2
So g(3) = 2.
(d) (%i5) g(2);
expt: undefined: 0 to a negative exponent.
#0: g(x=2)
-- an error. To debug this try: debugmode(true);

(e) (%i6) h(1);


(%o6) h(1);

(f) (%i7) functions;


(%o7) [f(x), g(x)]

137
Solutions to Computer activities

Solution to Computer activity 28


(a) (%i8) wxplot2d(f(x), [x,-2,2]);

(%t8)

(%o8)

(b) (%i9) wxplot2d(g(x), [x,-5,5]);

(%t9)

(%o9)

138
Solutions to Computer activities

(c) (%i10) wxplot2d(g(x), [x,-5,5],[y,-5,5]);


plot2d: some values were clipped.

(%t10)

(%o10)

Solution to Computer activity 29


(a) (%i1) %e∧5;
(%o1) %e5 ;

(b) (%i2) float(%e∧5);


(%o2) 148.4131591025766
So e5 = 148.41 (to 5 s.f.).
(c) (%i3) exp(5);
(%o3) %e5 ;

(d) (%i4) float( log(8) );


(%o4) 2.079441541679836
So log(8) = 2.079 (to 4 s.f.).
(e) (%i5) solve( 3∧(2*x)=5)

log(- 5) log(5)
(%o5) [ x= , x= ]
log(3) 2log(3)
log(5)
The only real solution is .
2 log(3)

139
Solutions to Computer activities

Solution to Computer activity 30


(a) (%i1) u:( log(x∧3+2*x∧2+x) - log(x) )/log(x+1) );
log(x3 +2x2 +x)-log(x)
(%o1)
log(x+1)

(b) (%i2) radcan(u);


(%o2) 2
Notice,
ln(x3 + 2x2 + x) − ln(x) 1 + $
= ln(x3 + 2x2 + x) − ln(x)
ln(x + 1) ln(x + 1)
8 8 3 99
1 x + 2x2 + x
= ln
ln(x + 1) x
1 + + $$
= ln x2 + 2x + 1
ln(x + 1)
1 ! ;
2
= ln (x + 1)
ln(x + 1)
2 ln(x + 1)
=
ln(x + 1)
= 2.

(c) (%i3) v:log(a)+2*log(b)-log(c);


(%o3) -log(c) + 2log(b) + log(a)

(d) (%i4) logcontract(v);


8 9
a b2
(%o4) log
c

Solution to Computer activity 31


(a) (%i1) cos(%pi/6);

3
(%o1)
2
! π ; √3
So, cos = .
6 2
(b) (%i2) sin(45*%pi/180);
1
(%o2) √
2
1
So, sin 45◦ = √ .
2
(c) (%i3) sec(3.4);
(%o3) -1.034342024711439
So, sec(3.4) ≈ −1.034342024711439.

140
Solutions to Computer activities

(d) (%i4) asin(sqrt(3)/2);


π
(%o4)
3
1√ 4
−1 3 π
So, sin = .
2 3
(e) (%i5) csc(%pi/7);
!π;
(%o5) csc
7

(f) (%i6) tan(-%pi/12);


!π;
(%o6) -tan
12

(g) (%i7) acos(2.0);


(%o7) 1.316957896924817 %i
So, cos−1 2.0 ≈ 1.316957896924817i.
(h) (%i8) acos(2);
(%o8) acos(2);

Solution to Computer activity 32


(a) (%i1) solve(cos(x)-0.6=0);
rat: replaced -0.6 by -3/5 = -0.6
solve: using arc-trig functions to get a solution.
Some solutions will be lost.
8 9
3
(%o1) [x=acos ]
5
8 9
−1 3
So, a solution is x = cos .
5
(b) (%i2) float(%);
(%o2) [x=0.92729521800161]
So a solution is x = 0.927 (to 3 s.f.).
(c) (%i3) solve(sin(3*x+4)=1/2);
solve: using arc-trig functions to get a solution.
Some solutions will be lost.
π-24
(%o3) [x = ]
18
π − 24
So a solution is x = .
18

141
Solutions to Computer activities

(d) (%i4) solve(cos(2*x+4)-sin(x/3)=0);


!x;
(%o4) [sin =cos(2x+4)]
3

Maxima cannot find an exact solution of this equation, so returns the


equation slightly rearranged.

Solution to Computer activity 33


(a) (i) (%i1) f(x):=cos(2*x+4)-sin(x/3);
! x;
(%o1) f(x):=cos(2x+4)-sin
3

(ii) (%i2) wxplot2d(f(x), [x,-2,2]);

(%t2)

(%o2)

Since f(0)< 0 and f(1)> 0, there must be a solution in the


interval (0, 1).
(iii) (%i3) find root(f(x), x, 0, 1);
(%o3) 0.42743338823081
So a solution of cos(2x + 4) − sin(x/3) within (0, 1) is 0.427
(to 3 s.f.).
(b) (%i4) g(x):= (sin(x+2))∧2-3*x;
(%o4) g(x):= sin(x+2)2 -3x
(%i5) wxplot2d(g(x), [x,-2,2]);

(%t5)

(%o5)

142
Solutions to Computer activities

Since g(0)> 0 and g(1)< 0, there must be a solution in the


interval (0, 1).

(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.).

Solution to Computer activity 34


(a) (%i1) trigreduce( sin(x)∧2 );
1-cos(2x)
(%o1)
2

(b) (%i2) trigexpand( % );


sin(x)2 -cos(x)2 +1
(%o2)
2

(c) (%i3) trigsimp( % );


(%o3) sin(x)2

Solution to Computer activity 35


(%i1) trigrat( sin(4*x)/sin(x) );
(%o1) 2cos(3x)+2cos(x)

sin(4x)
So, = 2 cos(3x) + 2 cos(x).
sin(x)

Solution to Computer activity 36


(a) (%i1) f:cos(5*x);
(%o1) cos(5x)
(%i2) g:trigexpand(f);
(%o2) 5cos(x)sin(x)4 -10cos(x)3 sin(x)2 +cos(x)5
So, cos(5x) = 5 cos(x) sin4 (x) − 10 cos3 (x) sin2 (x) + cos5 (x).

143
Solutions to Computer activities

(b) Choosing the range −2π ≤ x ≤ 2π to plot the graphs, we obtain


(%i3) wxplot2d([f,g],[x, -2*%pi, 2*%pi]);

(%t3)

(%o3)

The two graphs appear identical, which suggests the two expressions
are equal.

Solution to Computer activity 37


(a) (%i1) load(implicit plot);
(%o1) C:/PROGRA∼1/MAXIMA∼1.0/share/maxima/5.30.0/share/contrib/implicit plot.lisp

(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

Solution to Computer activity 38


(It is assumed the implicit plot package has already been loaded.)
(%i1) wximplicit plot(x∧2+y∧2=1,[x,-2,2],[y,-2,2],[gnuplot preamble,"set size ratio -1"]);

(%t1)

(%o1)

Solution to Computer activity 39


(It is assumed the implicit plot package has already been loaded.)
(a)
(%i1) set plot option([gnuplot preamble, "set size ratio -1"])$

(b) (%i2) wximplicit plot((x-1)∧2+y∧2=3, [x,-1,3], [y,-2,2]);

(%t2)

(%o2)

145
Solutions to Computer activities

Solution to Computer activity 40


(It is assumed the implicit plot package has already been loaded, and
the plot settings changed to use equal scales for the x- and y-axes.)
(a) (%i1) line:y=3*x-5;
(%o1) y=3x-5
(%i2) circle:(x-2)∧ 2+(y-3)∧2=2;
(%o2) (y-3)2 +(x-2)2 =2

(b) (%i3) wximplicit plot([line, circle], [x,0,5], [y,0,5]);

(%t3)

(%o3)

146
Solutions to Computer activities

Solution to Computer activity 41


(It is assumed the implicit plot package has previously been loaded and
the plotting options set for equal-scale axes.)
(a) (%i1) wximplicit plot(x∧2+4*y∧2=1, [x,-2,2], [y,-2,2]);

(%t1)

(%o1)

(The curve is an ellipse.)


(b) (%i2) wximplicit plot(x∧2-4*y∧2=1, [x,-4,4], [y,-4,4]);

(%t2)

(%o2)

(The curve is a hyperbola.)

147
Solutions to Computer activities

(c) (%i3) wximplicit plot(y∧2=x∧3-2*x+1, [x,-4,4], [y,-4,4]);

(%t3)

(%o3)

(d) (%i4) wximplicit plot(y∧2=x∧3-2*x+5, [x,-4,4], [y,-4,4]);

(%t4)

(%o4)

148
Solutions to Computer activities

(e) (%i5) wximplicit plot(y∧6=x∧2-x∧6, [x,-2,2], [y,-2,2]);

(%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

Solution to Computer activity 42


(a) (%i1) diff(x∧4+5*x∧2+15, x);
(%o1) 4 x3 +10 x
So the derivative of x4 + 5x2 + 15 is 4x3 + 10x.
(b) (%i2) p:t∧2/sin(4*t);
t2
(%o2)
sin(4 t)

(%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

Solution to Computer activity 43


(a) (%i1) diff(2*x∧6+5/x, x);
5
(%o1) 12x5 - 2
x
5 5
The derivative of 2x6 + is 12x5 − 2 .
x x
(b) (%i2) diff(log(exp(x)+x), x);
%ex +1
(%o2)
%ex +x
ex + 1
The derivative of ln(ex + x) is x .
e +x
(c) (%i3) diff((tan(t)-t∧ 2)/exp(t), t);
(%o3) %e-t (sec(t)2 -2t)-%e-t (tan(t)-t2 )
This can be simplified as follows.
(%i4) fullratsimp(%);
(%o4) -%e-t (tan(t)-sec(t)2 -t2 +2t)
(Remember, % in input line 4 refers to the result of the last evaluated
command.)
tan(t) − t2 ! ;
−t 2 2
The derivative of is −e tan (t) − sec (t) − t + 2t .
et
Solution to Computer activity 44
(a) (%i1) f(x):=sin(x)/(exp(x)+1);
sin(x)
(%o1) f(x):=
exp(x)+1

(b) (%i2) df(x):=diff(f(x),x);


(%o2) df(x):=diff(f(x),x)

(c) (%i3) df(3);


diff: second argument must be a variable; found 3
#0: df(x=3)
-- an error. To debug this try: debugmode(true);
(d) (%i4) df(x):=''(diff(f(x),x));
cos(x) %ex sin(x)
(%o4) df(x):= x - 2
%e +1 (%ex +1)
cos(x) ex sin(x)
So f " (x) = x −
e + 1 (ex + 1)2

151
Solutions to Computer activities

(e) (%i5) df(3);


cos(3) %e3 sin(3)
(%o5) - 2
%e3 +1 (%e3 +1)
(%i6) float(%);
(%o6) -0.05332658917586
So the value of f " at x = 3 is −0.053 (to 3 s.f.).
(f) First, define the function.
(%i7) f(x):=sin(x)*exp(cos(x));
(%o7) f(x):=sin(x)exp(cos(x));
Then calculate the derivative, defining df(x) to be the result.
(%i8) df(x):=''(diff(f(x),x));
(%o8) df(x):=%ecos(x) cos(x)-%ecos(x) sin(x)2
Finally evaluate the derivative at x = 1, giving the result as a decimal
approximation.
(%i9) float(df(1));
(%o9) -0.28798342608583
So, the derivative of sin(x)ecos(x) at x = 1 is −0.288 (to 3 s.f.).

Solution to Computer activity 45


(a) (%i1) integrate(2*x∧ 2+exp(3*x), x);
%e3x 2 x3
(%o1) +
& 3 3
e3x 2x3
So 2x2 + e3x dx = + + c.
3 3
(b) (%i2) integrate(1/x, x, 2, 3);
(%o2) log(3)-log(2)
(%i3) float(%);
(%o3) 0.40546510810816
& 3
1
So dx = ln(3) − ln(2) = 0.405 (to 3 s.f.).
2 x
(c) (%i4) p(x):=x/(x∧2+1);
x
(%o4) p(x):= 2
x +1

(%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

Solution to Computer activity 46


(a) (%i1) integrate((x-3)*(x-1), x);
x3 -6 x2 +9 x
(%o1)
& 3
x3 − 6x2 + 9x
So (x − 3)(x − 1) dx = + c.
3
(b) (%i2) integrate(1/sqrt(9-t
!t;

2), t);
(%o2) asin
3
& 8 9
1 −1 t
So √ dt = sin + c.
9−t 2 3
(c) (%i3) integrate(exp(t)*sin(t), t, 0, %pi);
%eπ 1
(%i3) +
2 2
(%i4) float(%);
(%o4) 12.07034631638963
& π
eπ 1
So et sin t dt = + = 12.1 (to 3 s.f.).
0 2 2

Solution to Computer activity 47


(a) (%i1) integrate(exp(sin(x)),
& x);
(%o1) %esin(x) dx
Maxima was unable to calculate this integral.
(b) (%i2) integrate(exp(-x


2), x);
πerf(x)
(%o2)
2
Maxima has calculated this integral, in terms of a function called the
Error function and denoted erf.
(c) (%i3) integrate(exp(x)/x, x);
(%o3) -gamma incomplete(0,-x)
Maxima has calculated this integral, in terms of a function called the
incomplete Gamma function.

153
Solutions to Computer activities

Solution to Computer activity 48


(a) (i) (%i1) kill(n);
(%o1) done

(ii) (%i2) integrate(x∧n, x);


Is n+1 zero or nonzero? n;
xn+1
(%o2)
n+1

(b) (i) (%i3) assume(notequal(n,-1));


(%o3) [notequal(n,-1)]

(ii) (%i4) integrate(x∧n, x);


xn+1
(%o4)
n+1

(iii) (%i5) facts();


(%o5) [notequal(n,-1)]
So Maxima knows n ,= −1.
(iv) (%i6) forget(notequal(n,-1));
(%o6) [notequal(n,-1)]

(v) (%i7) facts();


(%i7) []
No facts are now known.

Solution to Computer activity 49


First, tell Maxima what we know about a.
(%i1) assume(a>0);
(%o1) [a>0]
Then do the integration.
(%i2) integrate(1/(x∧ 2+a),x);
! ;
atan √xa
(%o2) √
a

So
& 8 9
1 1 x
2
dx = √ tan−1 √ + c,
x +a a a
where a > 0.

154
Solutions to Computer activities

Solution to Computer activity 50


(a) (%i1) integrate(log(cos(x∧ 2)), x, 0, 1);
%1
(%o1) 0 log (cos(x2 ))dx
Maxima cannot evaluate this integral exactly. It returns the integral
unevaluated.
(b) (%i2) quad qags(log(cos(x∧ 2)), x, 0, 1);
(%o2) [-0.11151210243615,3.3310015826528369 10-11 ,21,0]
(Remember 3.3310015826528369 10-11 means
3.3310015826528369 × 10−11 .)
& 1
So ln(cos(x2 )) dx = −0.112 (to 3 s.f.).
0
(c) (%i3) quad qags(exp(-t∧2), t, 0, 1);
(%o3) [0.74682413281243,8.2914134759407266 10-15 ,21,0]

& 1
2
So e−t dt = 0.747 (to 3 s.f.).
0

Solution to Computer activity 51


(a) (%i1) A:
2 matrix(
= [1,3,5], [2,4,6] );
1 3 5
(%o1)
2 4 6

(b) (%i2) B: matrix(


[1,2,3,4],
[4,1,2,3],
[2,4,1,3],
); 
1 2 3 4
(%o2) 4 1 2 3
2 4 1 3

Solution to Computer activity 52


(a) (%i3) matrix size(A);
(%o3) [2,3]
So the matrix A has size 2 × 3.
(b) (%i4) B[3,2];
(%o4) 4
The element in the third row and second column of B is 4.
(c) (%i5) B[3];
(%o5) [2,4,1,3]

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

Solution to Computer activity 53


(a) (%i1) 
P:matrix([2,0],[3,-1],[-4,6]);

2 0
(%o1)  3 -1
-4 6

(%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

(b) (%i6) P+Q;


 
2 3
(%o6)  8 -5
-3 9
 
2 3
So P + Q =  8 −5 .
−3 9
(c) (%i7) P-R;
fullmap: arguments must have same formal structure.
-- an error. To debug this try: debugmode(true);
P − R cannot be calculated, since the matrices are of different size.
An error is given.

156
Solutions to Computer activities

(d) (%i8) 2*P;


 
4 0
(%o8)  6 -2
-8 12
 
4 0
So 2P =  6 −2 .
−8 12
(e) (%i9) P.R;
 
2 6
(%o9) 1 5 
8 12
 
2 6
So PR = 1 5 .
8 12
(f) (%i10) P.Q;
MULTIPLYMATRICES: attempt to multiply nonconformable
matrices.
-- an error. To debug this try: debugmode(true);
PQ cannot be calculated, since the matrices are not of the
appropriate sizes. An error is given.
(g) (%i11) P.S;
 
2

(%o11) 1
8
 
2
So PS = 1 .

8
(h) (%i12) P.T;
 
6
(%o12)  5 
12
 
6
Maxima interprets the row vector T as a column vector and obtains  5 .
12
(i) (%i13) 2
R∧∧2; =
7 15
(%o13)
10 22
8 9
2 7 15
So R = .
10 22

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.

Solution to Computer activity 54


(a) (%i1) 
A:matrix([1,2,0],[-4,4,2],[-1,2,1]);

1 2 0
(%o1) -4 4 2
-1 2 1
(%i2) 
B:matrix([1,2,0],[5,6,2],[2,2,1]);

1 2 0
(%o2) 5 6 2
2 2 1

(b) (%i3) determinant(A);


(%o3) 4
So det A = 4.
(c) (%i4) C:invert(A);
 
0 - 12 1
 
(%o4)  12 1
4 - 12 
-1 -1 3
 
0 − 12 1
 1
So A−1 =  12 1
4 − 2 .
−1 −1 3
(d) (%i5) A.C;
 
1 0 0
(%o5) 0 1 0
0 0 1
(%i6) C.A;
 
1 0 0
(%o6) 0 1 0
0 0 1

So AC = CA = I, and C is the inverse of A.


158
Solutions to Computer activities

(e) (%i7) invert(B);


expt: undefined: 0 to a negative exponent. -- an error.
To debug this try: debugmode(true);
B does not have an inverse.

Solution to Computer activity 55


(a) First, enter the matrix into Maxima, and assign it to a variable.
(%i1)  A:matrix([2,-1,1],[2,0,1],[4,2,1]);

2 -1 1
(%o1) 2 0 1
4 2 1

Then, check if the matrix is invertible by finding its determinant.


(%i2) determinant(A);
(%o2) -2

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

Solution to Computer activity 56


(a) (%i1) a[n]:=0.8∧n;
(%o1) an :=0.8n

(b) (%i2) a[100];


(%o2) 2.0370359763345081 10-10
(Remember, this means 2.0370359763345081 × 10−10 .)
So a100 = 2.037 × 10−10 (to 4 s.f.).

Solution to Computer activity 57


(a) (%i1) b[1]:1;
(%o1) 1
(%i2) b[n]:=2*b[n-1]+1;
(%o2) bn :=2 bn-1 +1;

(b) (%i3) b[5];


(%o3) 31
(%i4) b[100];
(%o4) 1267650600228229401496703205375
So, b5 = 31 and b100 = 1267650600228229401496703205375
(c) (%i5) b[1]:10;
(%o5) 10
(%i6) b[5];
(%o6) 31

160
Solutions to Computer activities

(d) (%i7) kill(b);


(%o7) done
(%i8) b[1]:10;
(%o8) 10
(%i9) b[n]:=2*b[n-1]+1;
(%o9) bn :=2 bn-1 +1;
(%i10) b[5];
(%o10) 175
So b5 is now 175.

Solution to Computer activity 58


(a) (%i1) c[n]:=n∧2;
(%o1) cn :=n2

(b) (%i2) pts:[ [1,c[1]], [2,c[2]], [3,c[3]] ];


(%o2) [[1,1],[2,4],[3,9]]

(c)
(%i3) wxplot2d([discrete, pts], [style, points], [xlabel, "n"], [ylabel, "c[n]"]);

(%t3)

(%o3)

Solution to Computer activity 59


(a) (%i1) d[1]:0;
(%o1) 0
(%i2) d[n]:=1/2*(2-d[n-1]);
1
(%o2) dn := (2-dn-1 )
2

(b) (%i3) pts:makelist([n,d[n]], n, 1, 15);


1 3 5 11 21 43 85 171
(%o3) [[1,0],[2,1],[3, ], [4, ], [5, ], [6, ], [7, ], [8, ], [9, ], [10, ],
2 4 8 16 32 64 128 256
341 683 1365 2731 5461
[11, ], [12, ], [13, ], [14, ], [15, ]]
512 1024 2048 4096 8192

161
Solutions to Computer activities

(c)
(%i4) wxplot2d([discrete, pts], [style, points], [xlabel, "n"], [ylabel, "d[n]"]);

(%t4)

(%o4)

Solution to Computer activity 60


(a) First, define the sequence.
(%i1) r[1]:1;
(%o1) 1
(%i2) r[n]:=1.5*r[n-1] - 0.1*(r[n-1])∧ 2;
(%o2) rn :=1.5 rn-1 -0.1 r2n-1
Next, create a list of points to plot, suppressing the output.
(%i3) rpts:makelist([n,r[n]],n,1,50)$
Finally, plot the graph.

(%i4) wxplot2d([discrete, rpts], [style, points], [xlabel, "n"], [ylabel, "r[n]"]);

(%t4)

(%o4)

The terms of the sequence seem to be getting closer and closer to the
value 5.

162
Solutions to Computer activities

(b) First, define the sequence.


(%i5) s[n]:=n∧3-10;
(%o5) sn :=n3 -10
Next, create a list of 50 points to plot, suppressing the output.
(%i6) spts:makelist([n,s[n]],n,1,50)$
Finally, plot the graph.
(%i7) wxplot2d([discrete, spts], [style, points], [xlabel, "n"], [ylabel, "s[n]"]);

(%t7)

(%o7)

The terms of the sequence seem to be continually increasing.


(c) First, define the sequence.
(%i8) t[n]:=1-1.1∧n;
(%o8) tn :=1-1.1n
Next, create a list of 50 points to plot, suppressing the output.
(%i9) tpts:makelist([n,t[n]],n,1,50)$
Finally, plot the graph.
(%i10) wxplot2d([discrete, tpts], [style, points], [xlabel, "n"], [ylabel, "t[n]"]);

(%t10)

(%o10)

The terms of the sequence seem to be continually decreasing.

163
Solutions to Computer activities

Solution to Computer activity 61


(a) (%i1) sum(n∧2, n, 1, 100);
(%o1) 338350
100
:
So n2 = 338350.
n=1
20 8 9n
: 1
(b) The sum can be written and so can be calculated as follows.
n=1
3
(%i2) sum((1/3)∧n, n, 1, 20);
1743392200
(%o2)
3486784401
:20 8 9n
1 1743392200
So = .
n=1
3 3486784401
Notice that the sum is a geometric series with first term, a = 13 ,
common ratio, r = 13 and with 20 terms. So the sum can be calculated
using
! + 1 $20 ;
1
n
a(1 − r ) 3 1 − 3
=
1−r 1 − 13
1 8 9
3 1
= 2 1 − 20
3
3
8 20 9
1 3 −1
=
2 320
20
3 −1
=
2 × 320
3486784400
=
2 × 3486784401
1743392200
=
3486784401
≈ 0.4999999998566.

(c) (%i3) sum(1/(4∧n), n, 1, inf);


:∞
1
(%o3)
n=1
4n

(d) (%i4) simpsum:true;


(%o4) true
(%i5) sum(1/(4∧n), n, 1, inf);
1
(%o5)
3
:∞
1 1
So n
= . You could check this result using the expression for
n=1
4 3
the sum of an infinite geometric series.

164
Solutions to Computer activities

(e) (%i6) sum(1/(n∧2), n, 1, inf);


π2
(%o6)
6
:∞
1 π2
So 2
= .
n=1
n 6

Solution to Computer activity 62


(a) (%i1) taylor(cos(x), x, %pi/6, 3);
√ √ ! π ;2 ! π ;3
3 x- 6 π 3 x- x-
(%o1)/T/ − − 6 + 6 +...
2 2 4 12
So the cubic Taylor polynomial about π/6 for for f (x) = cos(x) is
√ π √ ! π ;2 ! π ;3
3 x − 3 x − x −
− 6 − 6 + 6
2 2 4 12
(b) (%i2) p(x)=''(taylor(tan(x), x, 0, 5));
x3 2 x5
(%o2)/T/ p(x):=x+ + + ...
3 15
So the quintic Taylor polynomial about 0 for f (x) = tan(x) is
x3 2 x5
x+ + .
3 15
(c) (%i3) p(y);
2 y5 +5 y3 +15 y
(%o3)/R/
15

(d) (%i4) float(p(0.1));


rat: replaced 0.10033466666667 by 75251/750000 = 0.10033466666667
(%o4) 0.10033466666667
So, p(0.1)= 0.10033 (to 5 s.f.).
(%i5) float(tan(0.1)-p(0.1));
rat: replaced 0.10033466666667 by 75251/750000 = 0.10033466666667
rat: replaced 0.10033467208545 by 9334601/93034649 = 0.10033467208545
(%o5) 5.418783991614422 10-9
So the difference between the function and its quintic Taylor
polynomial at x = 0.1 is 5.42 × 10−9 (to 3 s.f.).

165
Solutions to Computer activities

Solution to Computer activity 63


First, define the function.
(%i1) f(x):=exp(sin(x∧ 2));
(%o1) f(x):=exp(sin(x2 ))
Next, calculate the required Taylor polynomial. The command is ended
with $ to suppress displaying the result.
(%i2) p(x):=''(taylor(f(x),x,1,5))$
Finally, plot the two curves over the required range.
(%i3) wxplot2d([f(x),p(x)], [x,0,2], [legend, "f(x)", "p(x)"]);

(%t3)

(%o3)

Solution to Computer activity 64


(a) (%i1) a:3+4*%i;
(%o1) 4 %i+3

(b) (%i2) b:2-2*%i;


(%o2) 2-2 %i

(c) (%i3) a+b;


(%o3) 2%i+5
(%i4) a-b;
(%o4) 6 %i+1
So, a+b= 5 + 2i and a-b= 1 + 6i.
(%i5) a*b;
(%o5) (2-2 %i)(4 %i+3)
(%i6) a/b;
4 %i+3
(%o6)
2-2 %i

166
Solutions to Computer activities

(d) (%i7) rectform(a*b);


(%o7) 2%i+14
(%i8) rectform(a/b);
7 %i 1
(%o8) -
4 4
So, a*b= 14 + 2i and a/b= − 14 + 74 i.
(e) (%i9) realpart(a);
(%o9) 3
(%i10) imagpart(a);
(%o10) 4
So the real and imaginary parts of a are 3 and 4 as expected.
(f) (%i11) conjugate(a);
(%o11) 3-4 %i
So the conjugate of a is 3 − 4i as expected.
(g) (%i12) abs(b);
(%o12) 23/2
(%i13) carg(b);
π
(%o13) -
4
+√ $3 π
So, |b| = 23/2 = 2 and the principal argument of b is − .
4
Solution to Computer activity 65
(a) (%i1) c:3*(cos(5*%pi/13)+%i*sin(5*%pi/13));
8 8 9 8 99
5π 5π
(%o1) 3 %i sin + cos
13 13

(%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

(b) The modulus of c*d can be found as follows.


(%i3) abs(c*d);
7 8 92 8 92 7 8 92 8 92
5π 5π 7π 7π
(%o3) 12 sin +cos sin +cos
13 13 13 13
Simplify this using the trigreduce command. Remember, % refers to
the result of the previous calculation.
(%i4) trigreduce(%);
(%o4) 12

167
Solutions to Computer activities

The principal argument of c*d can be found as follows. Again the


initial result requires simplification.
(%i5) carg(c*d);
 8 9  8 9
7π 5π
 sin 13   sin 13 
(%o5) atan
 8 9 +atan 8 9 +π
7π   5π 
cos cos
13 13

(%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

Note that although carg gives a principal argument, that is an


argument in the interval (−π, π], the trigreduce command simplifies
the expression to an equivalent argument which is outside this interval.
24π 2π
The principal argument is − 2π = − .
13 13

So, |c/d| = 34 and Arg(c/d) = − .
13

168
Solutions to Computer activities

Solution to Computer activity 66


(a) (%i1) solns:solve(z∧ 3+z+1=0); √
8√ 91/3 8 √ 9 3 %i 1
31 1 3 %i 1 -
(%o1) [z= - - - - 2 2
2 33/2 2 2 2 8√ 91/3 ,
31 1
3 −
2 33/2 2

8√ 91/3 8 √ 9 3 %i 1
31 1 3 %i 1 - -
z= − - - 2 2
2 33/2 2 2 2 8 √ 91/3 ,
31 1
3 -
2 33/2 2
8√ 91/3
31 1 1
z= − - 8√ 91/3 ]
2 33/2 2 31 1
3 −
2 33/2 2
(b) (%i2) float(rectform(solns));
(%o2) [z=0.34116390191401-1.161541399997252 %i,
z=1.161541399997252 %i+0.34116390191401,
z=-0.68232780382802]
So, to two decimal places, the solutions are
z = 0.34 − 1.16i, z = 0.34 + 1.16i, and z = −0.68.

(c) (%i3) solve(z∧4-20*z∧3+171*z∧2-626*z+962=0);


(%o3) [z=3-2 %i,z=2 %i+3,z=7-5 %i,z=5 %i+7]

So the solutions are 3 − 2i, 3 + 2i, 7 − 5i and 7 + 5i.

Solution to Computer activity 67


(a) (%i1) s:solve(z
√ 4+4*z+5=0);

√ √ √
4-4%i 4-4%i 4%i+4 4%i+4
(%o1) [z=-%i- , z= -%i, z=%i- , z= +%i]
2 2 2 2

(b) (%i2) v:makelist(rhs(s[k]),


√ √ k, 1, length(s));
√ √
4-4%i 4-4%i 4%i+4 4%i+4
(%o2) [-%i- , -%i, %i- , +%i]
2 2 2 2

(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)

Solution to Computer activity 68


(a) (%i1) s:solve(z∧7=1);
2 %i π 4 %i π 6 %i π 6 %i π
-
(%o1) [z=%e 7 , z=%e 7 , z=%e 7 , z=%e 7 ,

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

To plot the solutions in the complex plane, first create a list


containing just the solutions of the equation (without the z=). The
command is ended with $ to suppress the output.
(%i3) v:makelist(rhs(s[k]), k, 1, length(s))$

Then create the list of points to be plotted.


(%i4) pts:makelist([realpart(v[k]), imagpart(v[k])], k, 1, length(s))$

Finally, plot the points.


(%i5) wxplot2d([discrete,pts], [style,points], [xlabel,""], [ylabel, ""]);

(%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

Maxima reference guide


Mathematical operations and functions
Operation or function Syntax Example
Addition + 4+3;
Subtraction - 4-3;
Multiplication * 4*3;
Division / 4/3;
Brackets ( and ) 2*(3+4);
Powers, for example 23 ∧
or ** 2∧3;
√ 2**3;
Square root, for example 5 sqrt( ) sqrt(5);

Exponential, for example e3 %e∧ %e∧3;


or, exp( ) exp(3);
Natural logarithm, ln log( ) log(8);

Magnitude (absolute value) of a real number, abs( ) abs(-3);


for example | − 3|, or modulus of abs(1+2*%i);
a complex number

sin sin( ) sin(1);


cos cos( ) cos(3*%pi/2);
tan tan( ) tan(%pi/4);
cosec csc( ) csc(2);
sec sec( ) sec(%pi/3);
cot cot( ) cot(%pi/4);
sin−1 asin( ) asin(sqrt(3)/2);
cos−1 acos( ) acos(1/sqrt(2));
tan−1 atan( ) atan(1/2);

Equality (within an equation) = 5=2*x+3;

172
Maxima reference guide

Mathematical operations and functions (continued)


Operation or function Syntax Example
Matrix addition + A+B;
Matrix subtraction - A-B;
Scalar multiplication * 2*A;
Matrix multiplication . A.B;
Matrix powers ∧∧
A∧∧3;
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);

Real part of a complex number realpart( ) realpart(1+2*%i);


Imaginary part of a complex number imagpart( ) imagpart(1+2*%i);
Conjugate of a complex number conjugate( ) conjugate(1+2*%i);
Argument of a complex number carg( ) carg(1+2*%i);

Other mathematical symbols


Symbol Syntax Example
e %e %e∧2;
π %pi 2*%pi;
i %i 2+3*%i;
∞ inf sum(1/n∧2,n,1,inf);

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);

Force the evaluation of a ''( ) g(x):=''(diff(x∧4,x));


command

Load a package load( package name ) load(implicit plot);

Assign a value to a variable : a:23;


Display the value of a variable variable a;
Define a function := f(x):=2*x+3;
Evaluate a function at a value function ( ) f(1);
Remove an assigned variable kill( variable ) kill(a);
or function kill( function ) kill(f);
Remove all assigned kill(all) kill(all);
variables and functions
Reset all system variables reset() reset();

Convert to a decimal number float( ) float(sqrt(2));

Expand brackets expand( ) expand( (x+1)∧2 );


Factorise factor( ) factor( 2*x+4*x∧2 );
Simplify fullratsimp( ) fullratsimp( (2*x+4*x∧2)/x );
Simplify something involving radcan( ) radcan( log(x∧2) );
exponentials and logarithms
Combine logarithms logcontract( ) logcontract(log(a)+log(b));
Expand trigonometric functions trigexpand( ) trigexpand(sin(A+B));
of sums, differences and
multiples of angles
Express powers of sines and trigreduce( ) trigreduce(sin(x)∧2);
cosines in terms of sines and
cosines of multiple angles
Simplify trigonometric expressions trigsimp( ) trigsimp(sin(x)∧2+cos(x)∧2);
Simplify algebraic fractions trigrat( ) trigrat((sin(2x))/cos(x));
containing trigonometric
functions
Substitute subst( value , variable , subst(4, x, x∧2+1);
expression ) which substitutes 4 for x in x∧2+1

174
Maxima reference guide

Maxima commands (continued)


Operation Command Example
Left-hand side of an equation lhs( equation ) lhs(4*x+1=2*x-2);
Right-hand side of an equation rhs( equation ) rhs(4*x+1=2*x-2);
Solve an equation, exactly solve( equation ) solve(2*x∧2-1=0);
Solve an equation for a variable solve( equation , variable ) solve(2*a*b-3*b=0, a);
Solve simultaneous equations solve( list of equations , solve([2*x+y=4, 3*x-2*y=-1],
list of unknowns ) [x,y]);
Solve an equation numerically find root( expression , find root(2*x∧2-1,x,0,1);
variable ,
interval start value ,
interval end value )

Make an assumption about a assume( ) assume(a>0);


variable
State two things are equal equal( , ) assume(equal(n,3));
State two things are not equal notequal( , ) assume(notequal(n,-1));
Forget a property forget( property ) forget(a>0);
List all known facts facts() facts();
List all known facts about facts( variable ) facts(a);
a particular variable

Form a list [ , , ... ] A: [a,b,c];


Create a list makelist( general term , makelist(2*n,n,1,100);
dummy variable ,
start value , end value )
Extract an element of a list list [ index ] A[2];
Find the length of a list length( list ) length(A);

Specify a matrix matrix( row , row ,...) A:matrix([1,2],[3,4]);


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];

175
Maxima reference guide

Maxima commands (continued)


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.
(use plot2d similarly if not
using wxMaxima) wxplot2d(x∧2,[x,0,1],[y,0,2]);
which plots the graph of x2
for x between 0 and 1
and vertical axis values between 0 and 2.
Plot several graphs wxplot2d( list of expressions , wxplot2d([x∧2, 2*x], [x,0,1]);
horizontal range ,...) which plots graphs of x2 and 2x
for x between 0 and 1.
Plot a sequence wxplot2d([discrete, wxplot2d([discrete,
list of coordinate pairs ], [[1,5], [2,10]]],
[style, points],...) [style, points]);
Plot a curve represented wximplicit plot( equation , wximplicit plot(x∧2+y∧2=1,
by an equation in implicit horizontal range , [x,-1,1], [y,-1,1]);
form vertical range ,...)

Plot several curves wximplicit plot( wximplicit plot(


represented by equations list of equations , [x∧2+2*y∧2=4, y=x∧3],
in implicit form horizontal range , [x,-1,1], [y,-1,1]);
vertical range ,...)

(use implicit plot similarly


if not using wxMaxima)

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

Maxima commands (continued)


Operation Command Example
Define a sequence sequence [n]:= expression in n a[n]:=n∧2;
using a closed form
Define a sequence sequence [ first term number ]: initial value b[1]:1;
using a recurrence sequence [n]:= expression in sequence [n-1] b[n]:=2*b[n-1];
system
Calculate a term in a sequence [ term number ] b[50];
sequence
Sum a series sum( general term , index variable , sum(n∧2,n,1,10);
lower limit , upper limit )

Find a Taylor polynomial taylor( function , variable , centre , degree ) taylor(sin(x),x,0,3);

Express a complex number rectform( ) rectform(2/%i);


in Cartesian form

Maxima system variables


Variable Description Example
fpprintprec The number of significant figures of fpprintprec:3;
a decimal number to display
functions The list of all user defined functions functions;
values The list of all user assigned variables values;
simpsum Whether to simplify summations simpsum:true;

177
Maxima reference guide

Maxima graph plotting options


The following options can be added as additional arguments to plotting
commands.
Option Argument Example
Vertical range [y, , ] [y, 0, 5]
Curve colour [color, ,...] [color, red]
Legend text [legend," ",...] [legend, "Car A"]
(a label should be listed
for each curve plotted)
Turn legend off [legend, false] [legend, false]
Horizontal axis label [xlabel, " "] [xlabel, "time, t (h)"]
Vertical axis label [ylabel, " "] [ylabel, "displacement, s (km)"]
Plot points [style, points] [style, points]
Change the relative lengths/scales [gnuplot preamble, [gnuplot preamble,
of graph axes. "set size ratio number "] "set size ratio -1"]
(A positive number specifies the (which sets the axes to have
ratio of axis lengths, a negative equal scales)
number specifies the ratio of axis
scales.)

Maxima packages
Maxima package Functions added
implicit plot Plotting curves given by equations in implicit form

wxMaxima keyboard sequences (Microsoft Windows)


Key sequence Function
Zoom in Alt-I
Zoom out Alt-O
Copy Ctrl-C
Interrupt a calculation Ctrl-G
Re-evaluate the worksheet Ctrl-R
Close wxMaxima Ctrl-Q
Paste Ctrl-V

178
Acknowledgements

wxMaxima menu commands (Microsoft Windows)


Operation Menu name Menu option
Close wxMaxima File Exit
Save your work File Save or Save As
Print the worksheet File Print
Open a worksheet File Open
Configure wxMaxima Edit Configure
Copy Edit Copy
Paste Edit Paste
Interrupt a calculation Maxima Interrupt
Restart Maxima Maxima Restart Maxima
Maxima help window Help Maxima Help
Re-evaluate worksheet Cell Evaluate All Visible Cells
Insert text cell Cell Insert Text cell
Insert title cell Cell Insert Title cell
Insert section cell Cell Insert Section cell
Insert subsection cell Cell Insert Subsection cell
Enter a matrix Algebra Enter Matrix...

Maxima command-line interface commands


Operation Command
Close Maxima quit();
Interrupt a calculation Ctrl-C
Turn off 2D formatting of maths display2d:false;
Display output left justified leftjust:true;
Start writing a transcript writefile(" file path ");
Stop writing a transcript closefile();
Playback all the input and playback();
output in a session
Playback a range of input and playback( [ start line number , end line number ] );
output
Save the state of a session save(" file path ", all);
Reload a session load(" file path ");

179
Acknowledgements

Acknowledgements
Grateful acknowledgement is made to the following sources:

Page 5: Taken from: http://www.ma.utexas.edu/people/in memoriam/


Page 6: www.cartoonstock.com

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

sequences 78 term of a sequence 80


closed form 78 toolbar 10
infinite 83 trigexpand 53
plotting 80 trigonometric equations 49
recurrence relation 79 trigonometric expression
revising 80 manipulating 53
term of 80 simplifying 53
series trigonometric functions 47
summing 84 inverse 47
Taylor 85 trigrat 54
set plot option 57 trigreduce 53
significant figures 24 trigsimp 53
using command-line interface 109
simplifying values 23
expressions 32 using command-line interface 108
trigonometric expressions 53 variable 21
simultaneous equations 37 assign 21
sin 47 assign, using command-line interface 106
size of a matrix 73 assumption 68
solve 33, 90 define 21
solving equations 33 define, using command-line interface 106
trigonometric 49 delete 23
numerically 50 delete, using command-line interface 108
with non-real solutions 90 system 24
sqrt 15 system, using command-line interface 108
using the command-line interface 101 using command-line interface 106
square root 15
using the command-line interface 101
worksheet 9
subject of equation, changing 37
re-evaluating 21
subst 32
substitute 32 wximplicit plot 55
wxMaxima
subtraction 15
adding comments 25
of matrices 74
cell 12
using the command line interface 101
closing 15
sum 84
configure 13, 16
summing series 84
file types 27
syntax 15
input prompt 11
using the command-line interface 101
system variables 24 interface 7, 9
menus 10
resetting 24
printing 28
resetting, using command-line interface 109
saving work 27
using command-line interface 108
toolbar 10
tan 47 worksheet 9
taylor 87 wxplot2d 38
Taylor polynomials 85 discrete points 81

184

You might also like