STACK DocumentationDocumentation home | Category index | Parent | Site map
Introduction to Maxima for STACK users
Maxima is a system for the manipulation of symbolic and numerical expressions, including differentiation, integration, Taylor series, Laplace transforms, ordinary differential equations, systems of linear equations, polynomials, and sets, lists, vectors, matrices, and tensors.
To write more than very simple questions you will need to use some Maxima commands. This documentation does not provide a detailed tutorial on Maxima. A very good introduction is given in Minimal Maxima, which this document assumes you have read.
STACK then modifies Maxima in a number of ways.
Types of object
Maxima is a very weakly typed language. However, in STACK we need the following "types" of expression:
- equations, i.e. an expression in which the top operation is an equality sign;
- inequalities, for example ;
- sets, for example, ;
- lists, for example, . In Maxima ordered lists are entered using square brackets, for example as
p:[1,1,2,x^2]. An element is accessed using the syntax
- matrices. The basic syntax for a matrix is
p:matrix([1,2],[3,4]). Each row is a list. Elements are accessed as
- logical expression. This is a tree of other expressions connected by the logical
or. This is useful for expressing solutions to equations, such as
x=1 or x=2. Note, the support for these expressions is unique to STACK.
Expressions come last, since they are just counted as being not the others! STACK defines predicate functions to test for each of these types.
Numbers are important in assessment, and there is more specific and detailed documentation on how numbers are treated: Numbers in STACK.
STACK defines the following function alias names
simplify := fullratsimp int := integrate
The absolute value function in Maxima is entered as
abs(). STACK also permits you to enter using
| symbols, i.e.
|x|. This is an alias for
abs. Note that
abs(x) will be displayed by STACK as .
STACK also redefined a small number of functions
- The plot command
plot2dis not used in STACK questions. Use
plotinstead, which is documented here. This ensures your image files are available on the server.
- The random number command
randomis not used in STACK questions. Use the command
randinstead, which is documented here. This ensures pseudorandom numbers are generated and a student gets the same version each time they login.
Parts of Maxima expressions
op(x) - the top operator
It is often very useful to take apart a Maxima expression. To
help with this Maxima has a number of commands, including
part(ex,n). Maxima has specific
documentation on this.
op(ex) returns the main operator of the expression
ex. This command has some problems for STACK.
- calling op(ex) on an atom (see Maxima's documentation on the predicate
atom(ex)) such as numbers or variable names, cause
op(ex)to throw an error.
op(ex)sometimes returns a string, sometimes not.
- the unary minus causes problems. E.g. in
-1/(1+x)the operation is not "/", as you might expect, but it is "-" instead!
To overcome these problems STACK has a command
This always returns a string. For an atom this is empty, i.e.
"". It also sorts out some unary minus problems.
get_ops(ex) - all operators
This function returns a set of all operators in an expression. Useful if you want to find if multiplication is used anywhere in an expression.
Maxima commands defined by STACK
It is very useful when authoring questions to be able to test out Maxima code in the same environment which STACK uses Maxima. That is to say, with the settings and STACK specific functions loaded. To do this see STACK-Maxima sandbox.
STACK creates a range of additional functions and restricts those available, many of which are described within this documentaion. See also Predicate functions.
||Returns a list of factors of ex without multiplicities|
||This function applies the binary function to two lists and returning a list. An example is given in adding matrices to show working.|
||This function takes an expression ex and returns a list of coefficients of v|
||This function takes an expression ex and returns a list of nonzero coefficients of v|
||Takes an algebraic fraction, e.g. and divides through by the denominator, to leave a polynomial and a proper fraction. Useful in feedback, or steps of a calculation.|
||Removes any variable beginning with the
||Takes the expression
||Resets constants, e.g. , as abstract symbols, see Numbers.|
||Returns the operation of the expression as a string. Atoms return an empty string (rather than throwing an error as does
||Returns a quadratic
||Returns the degree of the expanded form of
||Tidies up the way unary minus is represented within expressions when
||Displays all non-numeric atoms in bold. Useful for vector questions.|
||This function makes a substitution of all variables for their lower case equivalents.|
In Maxima the assignment of a value to a variable is very unusual.
||Assignment of the value to .|
||An equation, yet to be solved.|
||Definition of a function.|
In STACK simple assignments are of the more conventional form
key : value, for example,
n : rand(3)+2; p : (x-1)^n;
Of course, these assignments can make use of Maxima's functions to manipulate expressions.
p : expand( (x-3)*(x-4) );
Another common task is that of substitution. This can be
performed with Maxima's
subst command. This is quite useful,
for example if we define as follows, in the then we can
use this in response processing to determine if the student's
answer is odd.
p : ans1 + subst(-x,x,ans1);
All sorts of properties can be checked for in this way. For example, interpolates. Another example is a stationary point of at , which can be checked for using
p : subst(a,x,diff(ans1,x));
Here we have assumed a is some point given to the student,
ans1 is the answer and that will be used in the response processing tree.
You can use Maxima's looping structures within Question
variables, although the syntax requires this to be of the form
key = value. In this case, the key will be assigned the value
DONE at the end of the process, unless another value is
returned. For example
n : 1; dum1 : for a:-3 thru 26 step 7 do n:n+a;
Note, you must use Maxima's syntax
a:-3 here for assignment of to the variable
a. The assignment to the dummy variable
dum1 is to ensure every command is of the form
key : value. Please look at Maxima's documentation for the command
It is also possible to define functions within the Question Variables for use within a question. This is not recommended, and has not been widely tested. For example
dum1 : f(x) := x^2; n : f(4);
STACK loads the contributed Maxima package
log10. This defines logarithms to base automatically.
STACK also creates two aliases
lnis an alias for , which are natural logarithms
lgis an alias for , which are logarithms to base . It is not possible to redefine the command
logto be to the base .
It is sometimes useful for the teacher to define functions as part of a STACK question. This can be done in the normal way in Maxima using the notation.
define() command is forbidden. An alternative is to define
f as an "unnamed function" using the lambda command.
Here we are giving a name to an "unnamed function" which seems perverse. Unnamed functions are extremely useful in many situations.
For example, a piecewise function can be defined by either of these two commands
f(x):=if (x<0) then 6*x-2 else -2*exp(-3*x); f:lambda([x],if (x<0) then 6*x-2 else -2*exp(-3*x));
You can then plot this using
- See the section above on assignment.
- Maxima does not have a
degreecommand for polynomials. We define one via the
- Matrix multiplication is the dot, e.g.
A.B. The star
A*Bgives element-wise multiplication.
Further information and links
Documentation home | Category index | Parent | Site map