Tutorial on Maxima (under construction!)

Document Sample
Tutorial on Maxima (under construction!)
Tutorial on Maxima (under construction!)

An open-source symbolic math tool



Contents

2 Obtaining and installing

2 Running Maxima

4 Arithmetic

7 Derivatives

8 Integrals

9 Taylor series

9 Partial fractions and Laplace transforms

11 Simplifying expressions

13 Linear algebra

15 Vector calculus









2006-03-27 Maxima Tutorial 1/17

Introduction

Maxima is a free, open-source, powerful computer algebra system available for both Linux and

Windows. Plain Maxima is an ASCII text-based program and can produce output that is difficult

to read. The free, open-source TeXmacs package provides a graphical interface that produces

nicely formatted output. I will refer to this combination as TeXmacs/Maxima.



Installing TeXmacs/Maxima

TeXmacs/Maxima should already be installed on the WSU-TC, EE machines. You may wish to

install these packages on your personal computer. Maxima packages can be downloaded from

maxima.sourceforge.net/ while TeXmacs packages can be downloaded from www.texmacs.org/.



Windows: Download and run maxima-5.9.1.exe. Then download and run

wintexmacs-1.0.5.exe. I have successfully done this under Windows XP Home Edition. For

convenience these packages are available at



http://www.tricity.wsu.edu/~hudson/Teaching/



Linux: Under Fedora Core 3 the following procedure works. Download the four rpm files and

install as shown. The maxima files are available from maxima.sourceforge.net/ while the

TeXmacs packages can be downloaded from www.texmacs.org/.



rpm -ivF maxima-5.9.1-1.i386.rpm

rpm -ivF maxima-exec-cmucl-5.9.1-1.i386.rpm

rpm -ivF TeXmacs-1.0.6-1.i386.rpm

rpm -ivF TeXmacs-extra-fonts-1.0-1.noarch.rpm



Running TeXmacs/Maxima

If a TeXmacs icon appears on your screen, click (or double click) that to get started. Otherwise,

on Windows choose WinTeXmacs from the start menu. On Linux you can enter texmacs at a

terminal prompt. On the WSU-TC EE Linux machines click Applications => Other to get a

launcher for TeXmacs.



A window looking something like that below should open. The last icon in the top line of icons

is a computer monitor. Click on that. This brings up a list of the programs TeXmacs can run.

Click on Maxima to get started.









2006-03-27 Maxima Tutorial 2/17

If you don't see the computer monitor icon, look at the very bottom of the window. There might

be a message such as “Reload file from last session?” Enter “no” and hit return.



In TeXmacs/Maxima, input prompts appear in red and have a form such as %i3. Your input will

appear as blue ASCII text. Lines of output are labeled in red with a form such as %o4. The actual

output will be black formatted mathematical notation. Every line of input needs to be terminated

by a semi-colon “;”. The Linux version is quite forgiving on this. If you hit return before entering

the “;” you can enter it on the next line. The Windows version seems to lock up, requiring you to

start a new session.



Entering Commands









2006-03-27 Maxima Tutorial 3/17

Arithmetic

Arithmetic input consisting of integers will produce exact

results reduced as much as possible. For example %o1 and

%o2 in the figure at right. To get the floating point form of a

result one can use the float function, as in %i2. Alternately, if

any of the input numbers are floating point (e.g., 17.0 in %i4),

the output will be in floating point format. Note how in lines

%i2 and %i3 we use %o1 and %o2 as a "handles" to refer to

particular output expressions we wish to operate on. The

handle % refers to the previous output expression.



Naming expressions and functions

When performing multiple operations

on large expression it is convenient to

give that expression a short name and

then use that name as a “handle” to

refer to the expression. As seen in the previous example, Maxima does

this automatically when it labels output with handles such as %o1. We

may, however, prefer use our own handles. We do this as follows



handle : expression;



The example illustrates this. As shown in (%i3) entering just a handle

will cause Maxima to echo its value.



Greek letters are used

extensively in math, science and engineering.

Maxima recognizes names such as “beta” and

“rho,” as shown in the following example. Also,

note the use of brackets to denote subscripts, as

in beta[rho].









2006-03-27 Maxima Tutorial 4/17

In Maxima functions can be defined as follows



f(x) := expression;



This is illustrated at left. Note that you can include undefined

variables in your definition. If you later define values for those

variables your function will reflect that.









Plotting

The plot2d function allows a function of one variable to be plotted

over a specified domain. For example, the commands at right produce

the plot below









2006-03-27 Maxima Tutorial 5/17

Solving equations

The solve command

will attempt to solve an

equation, or a set of

equations for one or

more variables. In the

example we solve

2

x ­3x2

e =1/2 for x. In

%o2 Maxima gives us

the exact solutions. A

call to float gives

numerical values and

makes it clear that these

are complex numbers. In Maxima the log function is the natural log function that elsewhere is

often denoted by ln  x or log e  x . Note that although I gave my expression the handle “eq” I

can still refer to its echoed version as %o1. Alternately, we could have used the command

solve(eq,x); instead.



Here's an example of solving two linear equations in

two unknowns. We give the equations the names eq1

and eq2. Then we use solve to find expressions for x

and y. The first argument to solve is a list of

equations. The second argument is a list of variables

to solve for. Lists are contained between brackets [...]

and items are separated by commas. Instead of using

the names eq1, eq2 we could have referred to the

equations as %o1, %o2. Notice that we can also

solve for other parameters in the equations, such as

in %i4.









2006-03-27 Maxima Tutorial 6/17

Derivatives

The diff operator calculates symbolic

derivatives of its first argument with respect

to the second (as in %i1). An optional third

argument specifies multiple derivatives (see

%i3). As always, we can name an

expression and then operate on the handle

(%i4, %i5).









You can use diff to verify that a function satisfies a

differential equation. In this example we confirm that

2



e­ x satisfies the differential equation

y ' '2xy '2y=0 .







Nested calls to diff can calculate

mixed partial derivatives. At left

we calculate



2

sin  x x cos  y y e­ j  z

z



∂ y∂ x









2006-03-27 Maxima Tutorial 7/17

Integrals

Indefinite integrals (anti-derivatives) can be obtained using the

integrate command. The first argument is an expression (or a

handle), and the second argument is the variable of integration.

%i1 illustrates integrating an expression. %i2, %i3 illustrate

using a handle. If integrate cannot find an answer it returns an

expression with an integral sign (%o4) or, sometimes, an error

message.









You can also compute definite integrals by providing

limits of integration as the third and fourth arguments

of integrate.



Putting an apostrophe (') before the integrate command

tells Maxima to not attempt to do the integration. The

integral expression will simply be echoed. Sometimes

this is useful, as in the following example. The

changevar command implements a change of variable

(%i3). The first argument is the expression (or handle),

the second argument defines the change of variables, the

third argument is the new variable and the fourth

argument is the old variable. The second argument

should be an expression which when zero gives the change of variable. For example, if we want

to change x to the variable y where y=x 2 , our second argument would be y­x 2 or x 2­ y .



Multiple integrals can be done by nesting

integrate commands. Suppose we wanted

1 y

to calculate ∫∫ e­x dx dy . We can do this

0 0

as shown below. Note that Maxima asks if

y is positive, negative, or zero. We answer

positive; (don't forget the semi-colon).









2006-03-27 Maxima Tutorial 8/17

If we wish, we can define the inner integral as a function of y and then integrate that function.









Numerical integration can be performed with the

romberg command. We can operate on an expression

directly, or first define a function and then operate on

that.









Taylor Series

Taylor series are obtained using the

taylor command. The first argument

is the function, the second is the

independent variable, the third is the

point about which the series is

developed and the fourth is the

highest power you want in the

series.





Partial fractions and Laplace transforms

At left is an example of using the partfrac

command to obtain a partial fraction expansion.









At right we define a function and take its Laplace transform using the laplace command.









2006-03-27 Maxima Tutorial 9/17

2006-03-27 Maxima Tutorial 10/17

The inverse Laplace transform is performed using the ilt

command.









Simplifying expressions

Trial and error with the following simplification functions will often lead to a more compact and

readable result.



ratsimp(exp), fullratsimp(exp) test



factor



expand(exp) expandwrt(exp,var) test









trigexpand(exp) expands trigonometric and

hyperbolic functions of sums of angles and

of multiple angles.









trigreduce(exp) combines products and powers of trigonometric

and hyperbolic sin's and cos's.









trigsimp(exp) employs the identities sin(x)^2 + cos(x)^2 = 1 and cosh(x)^2 - sinh(x)^2 = 1 to

simplify expressions containing tan, sec, etc., to sin, cos, sinh, cosh. trigreduce, ratsimp, and



2006-03-27 Maxima Tutorial 11/17

radcan may be able to further

simplify the result.







radcan



logcontract



ratexpand





Partitioning expressions

realpart(exp), imagpart(exp) allow you to extract the real and

imaginary parts of a complex expression.









partition(exp,var);



part(exp,n);



pickapart(exp,depth)









2006-03-27 Maxima Tutorial 12/17

Linear algebra: vectors and matrices

Generally, for numerical vector/matrix operations a tool such as Scilab is preferable. Maxima can

be used to perform symbolic vector/matrix operations and exact numerical operations.





The matrix command allows you to define a matrix of arbitrary

dimensions. Matrices can be stacked using the addcol and

addrow commands.









The row and col commands allow matrix rows and

columns to be extracted.









2006-03-27 Maxima Tutorial 13/17

Determinants and inverses can be calculated with the

determinant command. The adjoint command gives

the determinant times the inverse and is sometimes

useful.









The characteristic polynomial of a matrix can be

calculated as the determinant of the matrix minus s times

the identity matrix, or directly using the charpoly

command.









Symbolic eigenvalues

and eigenvectors can be

calculated. The

eigenvalues command

returns two lists. The

first lists the eigenvalues

while the second lists

their multiplicities. The

eigenvectors command

gives the eigenvalue info

followed by

eigenvectors. Note that

the eigenvectors are

generally not normalized. This usually leads to cleaner expressions. If you want normalized

vectors, use uniteigenvectors instead.





2006-03-27 Maxima Tutorial 14/17

Vector calculus

Maxima has a special “vect”

package for doing vector

calculus (gradient, curl, etc.)

in arbitrary orthogonal coordinate systems. To use it start with the command load(vect). The

coordinate system is defined using the scalefactors command. To define an orthogonal coordinate

system u,v,w we do the following



scalefactors([[x(u,v,w),y(u,v,w),z(u,v,w)],u,v,w]);



Here x(u,v,w) expresses the x rectangular coordinate as a function of u,v,w and likewise for

y(u,v,w) z(u,v,w). Finally we list the three coordinates in order u,v,w. Note carefully the required

brackets and commas. In %i2 we defined the cylindrical coordinate system rho,phi,z.



We can obtain symbolic expressions

for the gradient and Laplacian of a

scalar as in %i4 and %i5. Note the

need for the express command. If

you just enter grad(f); you will get

grad(f) echoed back without it being

expressed in terms of derivatives.



In %i6 we define a vector with

components A , A , Az . We can

then get symbolic expressions for the

divergence and curl, as shown.









2006-03-27 Maxima Tutorial 15/17

load(vect)$ Here's an example from

scalefactors([[x,y,z],x,y,z])$ electromagnetics. The Maxima

A:[0,0,a*exp(-%i*beta*x)]$ code is at left and the output is

display(A)$

H:(1/mu)*curl(A)$ at right. We define a vector

H:ev(express(H),diff)$ potential A. The magnetic

display(H)$ field H and the electric field E

E:(-%i/(omega*epsilon))*curl(H)$

E:ev(express(E),diff)$

are obtained via curl

display(E)$ operations. We take the

Hc:subst(-%i,%i,H)$ conjugate of H using the subst

P:express((1/2)*(E~Hc))$ command and finally form the

display(P)$

Poyting vector using a cross

product between E and the conjugate of H. The cross

product operation is denoted by the symbol ~.









2006-03-27 Maxima Tutorial 16/17

Screen shots should use 144 dpi resolution.









2006-03-27 Maxima Tutorial 17/17


Share This Document


Other docs by techmaster
A Quick Pay Tutorial
Views: 42  |  Downloads: 0
User guide for the Document Manager plug-in
Views: 13  |  Downloads: 1
Product Specifications SolarSave�
Views: 3  |  Downloads: 0
QUICK REFERENCE FLOW CHART FOR CAT AND SAP
Views: 65  |  Downloads: 6
JAGUAR X-TYPE SALOON TECHNICAL SPECIFICATIONS
Views: 39  |  Downloads: 0
2008 Devon Dust Up Technical Guide
Views: 4  |  Downloads: 0
User Guide
Views: 104  |  Downloads: 1
USER MANUAL
Views: 78  |  Downloads: 2
by registering with docstoc.com you agree to our
privacy policy

You are almost ready to download!

You are almost ready to download!