/usr/share/doc/maxima-doc/html/intromax.html introduction /usr/share/doc/maxima-doc/html/maxima_toc.html full helptop
Text mode:
unix> maxima
interrupt a maxima calculation with
<CTRL>-G
terminate maxima with
quit();
GUI:
unix> xmaxima
unix> wxmaxima
Help:
GUI ->Help
descripe(string);
? string; /* note the space after "?" */
A perfect way to restart maxima does not exist (see
mailing list), use
reset();
kill(all);
top
Terminate commands with ";" or "$" (quiet mode). command prompts: (%i1) (%i2) .. output labels: (%o1) (%o2) .. Previous result: % Former output, e.g. (%o5): %o5 Redo command, e.g. (%i5) : ''%i5; Operators: + - * / ^ ** ( ) ! !! Comparison: = # > < >= <= /* "#" is "not equal" */ Logical: and or not Text strings are written as "text".top
declare("$", alphabetic);
Pre-defined constants:
%i %pi %e true false
%gamma Euler's constant
%phi (1 + sqrt(5))/2
inf real infinity
minf real (-infinity)
infinity complex infinity
Pre-defined functions:
sqrt log exp
sin .. asin ..
sinh .. asinh ..
gamma beta
zeta
binomial factorial
mod floor
kron_delta
..
Reserved names:
integrate next from diff
in at limit sum
for and elseif then
else do or if
unless product while thru
step
Manage user-defined variables:
values list of all user defined variables
remvalue(var); delete the value of var
remvalue(all); delete the values of all variables
top
Assignment: : (without "="!)
:: ??
:= defines a function
::= defines a macro
Unassign names:
kill(name1, name2, ..);
kill(all);
xmaxima: ->File ->Restart
wxMaxima: ->Maxima ->Restart maxima
top
lst: [el1, el2, ...]; contruct list explicitly
lst[2]; reference to element by index
(starting from 1)
makelist(expr, i, i1, i2); create list with control variable i
makelist(expr, x, xlist); create list with x from another list
length(alist); returns #elements
sort(alist);
reverse(alist);
cons(expr, alist); prepend expr to alist
endcons(expr, alist); append expr to alist
append(list1, list2, ..); merge lists
first(alist); first element (also: second ... tenth)
last(alist); last element
rest(alist); list with first element removed
rest(alist, num); ... num elements ...
firstn(alist, num); list of first num elements
lastn(alist, num); ... last ...
pop(alist); removes the first element and returns it
push(expr, alist); prepends expr and returns the new list
listp(expr); true if expr is a list, else false
map(fct, list); evaluate a function of one argument
map(fct, list1, list2); evaluate a function of two arguments
top
'expr don't evalute
''expr do evaluate
e.g.
a: b+c;
c + b
b:5$
a;
c + b
''a;
c + 5
'b + c;
c + b
Evalutate variables, based on equations:
at(expr, var=ex);
at(expr, [var1=ex1, var2=ex2, ..]);
e.g. at(diff(sin(x), x), x=%pi);
-1
Evaluate with additional settings/flags:
ev(expr, arg1, arg2...);
expr, arg1, arg2, ...; same in short
args: numer
float
bfloat
simpsum
eval
...
Many of the evalutation switches (e.g. numer, simpsum) are actually flags,
which are false by default, but can be enabled for subsequent use.
float(expr); evaluate to floating point number
expr, numer; return numerical result
numer: true; numerical evaluation on (default: false)
fpprec: digits; precision of big floats (default: 16)
fpprintprec: digits; no. of printed digits
bfloat(expr); evaluate to big float
example:
fpprec: 30;
sin(%pi); => 0
sin(float(%pi)); => 1.2246063538223773E-16
sin(bfloat(%pi)); => 1.69568553207377992879174029388B-31
Note: WxMaxima, with output format set to xml, diplays long numbers
with a shortcut - compare the output of
bfloat(%pi), fpprec:1000;
top
subst(..) syntactic, symbols and complete sub-expressions only
ratsubst(..) similar, but employs some algebra
at(..) evaluation, based on equations
ev(..) evaluation, with equations, flags etc.
subst(..) and ratsubst(..) in more detail:
subst(ex, var, expr); substitute ex for var in expr
subst(var=ex, expr); same
subst([var1=ex1, var2=ex2,..], expr); multiple substitutions
ratsubst(ex, var, expr); substitute ex for var in expr
subst(s, a+b, a+b+c);
c + b + a
ratsubst(s, a+b, a+b+c);
s + c
subst(1-cos(x)^2, sin(x)^2, sin(x)^4 - 5*sin(x)^2);
4 2
sin (x) - 5 (1 - cos (x))
ratsubst(1-cos(x)^2, sin(x)^2, sin(x)^4 - 5*sin(x)^2);
4 2
cos (x) + 3 cos (x) - 4
top
func(x) := sin(x)/x;
radius(x,y) := sqrt(x^2 + y^2);
Alternative form:
define(f(x), expr); /* expr is always evaluated */
define(f(x,y), expr); /* etc */
More complicated function definitions can be formulated with the
block(..) construct.
factor(expr); factorise polynomials (over integers only)
expand(expr); expand polynomials
ratexpand(expr); same (more efficient algorithm)
expandwrt(expr, x, ..); expand w.r.t. specified variables
coeff(expr, x, n); coefficient of x^n in expr
ratcoef(expr, x, n); same, but simplifies expr first
divide(pol1, pol2); polynomial devision (with remainder)
quotient(pol1, pol2); quotient of polynomial devision
remainder(pol1, pol2); remainder of polynomial division
realroots(pol, tol); numerical approx. to all real roots
realroots(pol); tol = rootsepsilon (default: 1e-7)
allroots(pol); numerical approx. to all complex roots
top
ratsimp(expr); put on common denominator,
cancel factors,
expand numerator and denominator
fullratsimp(expr); repeated application of `ratsimp'
factor(expr); same as `ratsimp', but returns numerator and
denominator in factored form
expand(expr); expand numerator and denominator, split numerator
(no common denominator)
ratexpand(expr); put on common denominator,
cancel factors,
expand numerator and denominator,
split numerator
ratdenomdivide: false; don't split numerator (same as ratsimp?)
num(expr); numerator of rational expression
denom(expr); denominator
facsum(expr, var, ..) expand w.r.t. specified variables
facsum_combine: false; split numerator
partfrac(expr, var); partial fraction decomposition
examples:
ratsimp(a/b + c/d);
a d + b c
---------
b d
(x-1)/(x+1)^2 - 1/(x-1);
x - 1 1
-------- - -----
2 x - 1
(x + 1)
ratexpand(%);
4 x
- ---------------
3 2
x + x - x - 1
factor(%);
4 x
- ----------------
2
(x - 1) (x + 1)
r: (u+v)^2*u/((u^2-v^2)*v);
2
u (v + u)
-----------
2 2
v (u - v )
ratsimp(r);
u v + u
- --------
2
v - u v
factor(r);
u (v + u)
- ---------
v (v - u)
ratexpand(r);
2
u u
- -------- - -----
2 v - u
v - u v
s: a*b/(c*d+c*e) + f*b/(c*d+c*e);
b f a b
--------- + ---------
c e + c d c e + c d
factor(s);
b (f + a)
---------
c (e + d)
ratsimp(s);
b f + a b
---------
c e + c d
Notes:
ratsimp(expr); and ratexpand(expr), ratdenomdivide: false;
ratsimp(expr), factor; and factor(expr);
but factor(expr) does not understand algebraic!
Summary: simplify rational functions with ratsimp(expr), possibly combined with factor and/or algebraic. Use ratexpand(expr), possibly with algebraic, if you prefer to split the numerator.
In the complex case, try e.g.
gfactor(expr); factorise over integers and %i
partfrac(gfactor(expr)), var); partial fractions with complex roots
top
rootscontract(expr); products of roots -> roots of products
ratsimp(expr), algebraic; rationalise denominators
radcan(expr); canonical form, involving roots, logs,
radcan(expr), algebraic; and exponentials
examples:
ex: 1/(sqrt(a)+sqrt(b));
1
-----------------
sqrt(b) + sqrt(a)
ratsimp(ex), algebraic;
sqrt(b) - sqrt(a)
-----------------
b - a
sqrt(x^2);
abs(x)
sqrt(x^2), radexpand:all;
x
In some cases, sqrtdenest can disentangle nested square roots:
load(sqdnst);
sqrtdenest(expr);
e.g.
sqrt(sqrt(7)+ 4);
sqrt(sqrt(7) + 4)
sqrtdenest(%);
sqrt(7) 1
------- + -------
sqrt(2) sqrt(2)
factor(%);
sqrt(7) + 1
-----------
sqrt(2)
top
logexpand:all; enables automatic expansion of products
logcontract(expr); contracts sums of logs to logs of products
and _integer_ multiples of logs to
logs of powers
radcan(expr); canonical form, involving roots, logs,
radcan(expr), algebraic; and exponentials
examples:
log(a^b);
log(a) b
log(a*b), logexpand:all;
log(b) + log(a)
logcontract(2*log(a) + 3*log(b));
2 3
log(a b )
top
trigsimp(expr); use sin(x)^2 + cos(x)^2 = 1 etc
trigexpand(expr); use addition theorems etc
trigreduce(expr); powers -> multiple arguments
products -> sums
trigrat(expr); simplify rational expressions of trigonometric
functions as well as linear arguments
involving %pi/n
halfangles:true; replace half angles by roots
exponentialize(expr); trig/hyperb -> exponentials
demoivre(expr); complex exponentials -> trig (not hyperb)
logarc(expr); arc trig/hyperb -> logarithms
trigexpand is a flag as well (and an evflag), but the other
trigX aren't!
trigsimp(..) in combination with roots is tricky:
trigsimp(sqrt(sinh(x)^2 + 1));
cosh(x)
trigsimp(sqrt(cosh(x)^2 - 1));
sqrt(cosh(x) - 1) sqrt(cosh(x) + 1)
instead of the expected abs(sinh(x)). It does not work for
sin() and cos(x) either. Is this caused by abs(..)?
There is no command to convert real exponentials to hyperbolic functions - use ratsubst(..) instead.
Examples:
sin(x/2), halfangles;
sqrt(1 - cos(x))
----------------
sqrt(2)
?HOW TO:
sin(x) + cos(x) = sqrt(2) * sin(x + %pi/4)
try exponentialize(...)
?HOW TO
ex1: cos(x) + cos(y);
ex2: 2 * cos((x+y)/2) * cos((x-y)/2);
ex2 -> ex1:
trigreduce(ex2), ratsimp;
or trigrat(ex2);
ex1 -> ex2 ??
logarc examples:
asinh(x), logarc;
2
log(sqrt(x + 1) + x)
acosh(x), logarc;
sqrt(x + 1) sqrt(x - 1)
2 log(----------- + -----------)
sqrt(2) sqrt(2)
%, logcontract, expand, rootscontract;
2
log(sqrt(x - 1) + x)
top
minfactorial(expr) combines factorials with integer offset
factcomb(expr) combines factorials with factors
gamma_expand: true expand gamma(z+n) and gamma(z-n)
beta_expand: true expand beta for arguments z+n and z-n
makegamma(expr) transforms binomial, factorial,
and beta functions into gamma functions
For products involving these functions with integer offsets, try
makegamma(..) in combination with gamma_expand: true
rectform(z) a + %i*b
conjugate(z)
realpart(z)
imagpart(z)
polarform(z) |z|*e^(%i*phi)
cabs(z) |z|
carg(z) polar angle phi in (-%pi, %pi]
top
factor(n) basic method
ifactors(n) more efficient algorithm
ifactor_verbose: true show details
top
limit(f(x), x, a);
limit(f(x), x, a, dir); direction dir = plus, minus
top
diff(expr, x);
diff(expr, x, n); /* n-th derivative */
diff(expr, x, 1, y, 1); /* mixed partial derivative */
Convert the derivative to a function with define(..):
f(x) := sin(x); /* works */
diff(f(x), x);
cos(x) /* ok */
g(x) := diff(f(x), x); /* doesn't work */
define(g(x), diff(f(x), x));
g(x) := cos(x) /* works */
Compute the derivative at a specific value with at(..):
at(diff((x-a)^2, x, 2), x=a);
2
top
integrate(f(x), x); indefinite integral
integrate(f(x), x, a, b); definite integral
defint(f(x), x, a, b); same
ldefint(f(x), x, a, b); same, but taking limits at the boundaries
Examples:
assume(a>0)$
declare(a, noninteger)$
facts(a);
[a > 0, kind(a, noninteger)]
integrate(x^a * exp(-x), x, 0, inf);
gamma(a + 1)
kill(all)$
facts();
[]
integrate(1/(a - cos(x)), x, 0, %pi);
Is (a - 1) (a + 1) positive, negative, or zero? pos;
2
Is sqrt(a - 1) - a positive or negative? neg;
2
Is sqrt(a - 1) - a + 1 positive, negative, or zero? pos;
! 2 !
Is !sqrt(a - 1) + a! - 1 positive, negative, or zero? pos;
2
2 %pi sqrt(a - 1) - 2 %pi a
- ----------------------------
2 2
2 (a sqrt(a - 1) - a + 1)
ratsimp(%), algebraic;
%pi
------------
2
sqrt(a - 1)
top
sum(expr, n, n1, n2);
ev(sum(...), simpsum); sum and simplify
sum(...), simpsum; same in short
simpsum: true; enable summations
Example:
sum(k^2, k, 1, n);
n
====
\ 2
> k
/
====
k = 1
%, simpsum;
3 2
2 n + 3 n + n
---------------
6
The same is achieved with
sum(k^2, k, 1, n), simpsum;
or
simpsum: true;
sum(k^2, k, 1, n);
Within a function definition, the ev(..) command is used to
force the summation. The following example computes the partial
sum of the harmonic series and returns the result as a floating
point number:
Harm(n) := ev(sum(1/k, k, 1, n), simpsum, numer);
In the same way, products are defined with
product(..) and evaluated (symbolically) with
simpproduct:
product(expr, n, n1, n2);
ev(product(expr, n, n1, n2), simpproduct);
top
powerseries(expr, var, point); symbolic, possibly infinite
taylor(expr, var, point, order); truncated at given order
niceindices(expr); rewrite symbolic sums
Expansion in several variables:
taylor(expr, [x_1, x_2], a, n); around x_i = a
taylor(expr, [x_1, x_2], [a_1, a_2], n); around x_i = a_i
Extract coefficients with coeff(..), e.g.
ser: taylor(exp(x), x, 0, 10);
coeff(ser, x, 3);
1
-
6
makelist(coeff(ser, x, i), i, 0, 5);
1 1 1 1
[1, 1, -, -, --, ---]
2 6 24 120
top
solve(eqn, var);
solve([eqn1, eqn2, ..], [var1, var2, ..]);
It returns a list of solutions resp. solution vectors.
sol: solve(x^2 + p*x + q, x);
sqrt(p - 4 q) + p sqrt(p - 4 q) - p
[x = - ------------------, x = ------------------]
2 2
x1: x, sol[1];
sqrt(p - 4 q) + p
- ------------------
2
x2: x, sol[2];
sqrt(p - 4 q) - p
- ------------------
2
eqn1: x + y = 4;
y + x = 4
eqn2: x - y = 2;
x - y = 2
sol: solve([eqn1, eqn2], [x,y]);
[[x = 3, y = 1]]
x, sol;
3
y, sol;
1
Check:
map(is, ev([eqn1, eqn2], sol));
[true, true]
Maybe ev(..) needs more flags (e.g. ratexpand).
Check multiple solutions (equation is formulated as f(x) = 0):
f(x):= x^2 + 2*b*x + c;
2
f(x) := x + 2 b x + c
sol: solve(f(x), x);
2 2
[x = - sqrt(b - c) - b, x = sqrt(b - c) - b]
map(f, map(rhs, sol)), expand;
[0, 0]
?HOW TO:
solve(sin(x) + cos(x) = 1/2, x);
eqn: sin(x) + cos(x) = 1/2;
solve(eqn, x); no success
eqnx: exponentialize(eqn);
sol: solve(eqnx, x); solution in terms of complex logs
ratsimp(sol);
%, numer;
rectform(sol); imaginary parts are obsolete
ratsimp(%); nicer formula
%, numer;
?HOW TO:
solve(s + sqrt(1-s^2) = 1/2, s);
solveradcan: true; doesn't help here
(solve calls radcan)
eq1: s + r = 1/2; aux variable r = sqrt(1 - s^2) > 0
eq2: r^2 = 1 - s^2;
solve([eq1, eq2], [s, r]);
sqrt(7) - 1 sqrt(7) + 1
[[s = - -----------, r = -----------],
4 4
sqrt(7) + 1 sqrt(7) - 1
[s = -----------, r = - -----------]]
4 4
Solution is s = (1 - sqrt(7))/4 .
?HOW TO:
solve([sqrt(x) + y = 0, sqrt(x) = 1], [x, y]);
[]
eliminate([sqrt(x) + y = 0, sqrt(x) = 1], [x]);
[1] ??? BUG ???
eliminate([sqrt(x) + y = 0, sqrt(x) = 1], [y]);
[ sqrt(x) - 1 ] ok
Note that eliminate() uses resultant(), which is
supposed to work with polynomials.
eliminate([eqn1, eqn2, ..], [var1, var2, ..]);
eqn: sin(x) + cos(x) = 1/2;
to_poly_solve(eqn, x); /* auto-loads the package */
%union{...}
or
load(to_poly_solve); /* manual load */
sol: %solve(eqn, x); /* alias for to_poly_solve */
%union{...}
first(sol); /* extract solutions */
second(sol);
The set of solutions is returned as a %union.
Extract single solutions (explicit equations) with commands like
first, second, .., tenth, last, rest.
find_root(expr, x, a, b)
For polynomials: see realroots(pol), allroots(pol).
ode2(eqn, y, x);
E.g. eqn of 2nd order:
eqn: 'diff(x,t,2) + r*'diff(x,t)^2 = 0;
general solution, with constants of integration %k1, %k2:
sol: ode2(eqn, x, t);
log(r t + %k1 r)
x = ---------------- + %k2
r
impose initial conditions:
ic2(sol, t=0, x=x0, 'diff(x,t)=v0), logcontract, ratexpand;
log(r t v0 + 1)
x = x0 + ---------------
r
convert solution equation to a function:
define(x(t), rhs(%));
[TO DO: for the same deqn with exponent 2 -> 3, ic2() fails to solve
for the initial conditions. This looks like a problem with solve...]
eqn: 'diff(f(x), x) = 2*f(x); /* linear ODE of 1st order */
sol: desolve(eqn, f(x));
2 x
f(x) = f(0) %e
[Note the different format of derivatives in the equation.]
eqn: 'diff(f(x), x) = 2*f(x);
atvalue(f(x), x=0, k); /* initial value at x=0 */
sol: desolve(eqn, f(x)); /* solution as an equation */
2 x
f(x) = k %e
define(f(x), rhs(%)); /* solution function */
2 x
f(x) := k %e
An example of second order:
eqn: 'diff(f(t), t, 2) + r*'diff(f(t), t) + f(t) = sin(omega*t);
atvalue(f(t), t=0, 1);
atvalue('diff(f(t), t), t=0, 0);
desolve(eqn, f(t)); /* omega nonzero, -2 < r < 2 */
define(f(t), rhs(%));
plot2d(ev(f(t), omega=1.1, r=0.1), [t, 0, 100]);
A linear system is solved with desolve as follows:
eqn1: 'diff(f(x), x) = c*f(x) - g(x);
eqn2: 'diff(g(x), x) = c*g(x) + f(x);
atvalue(f(x), x=0, 1);
atvalue(g(x), x=0, 0);
sol: desolve([eqn1, eqn2], [f(x), g(x)]);
define(f(x), rhs(sol[1]));
define(g(x), rhs(sol[2]));
c: 0.1;
plot2d([parametric, f(x), g(x), [x, 0, 10]]);
desolve requires that the inverse Laplace transform (ilt) is applied to a rational function with a denominator of first or second order.
gamma(z) # Euler's gamma function
log_gamma(z)
psi(z) # log. derivative
%gamma # Euler's constant (0.5772..)
gamma_expand: true # simplify gamma(z+n) and gamma(z-n)
beta(x,y) # Euler's beta function
beta_expand: true # simplify beta(x+n,y) etc
zeta(n) # Riemann's zeta function
It is implemented numerically.
erf(z)
erfc(z)
top
x: [x1, x2, x3];
y: [y1, y2, y3];
s * x + t * y;
x . y; /* scalar product */
load("vect");
express(x ~ y); /* 3d cross product */
Matrix construction:
A: matrix([a, b, c], [d, e, f], [g, h, i]); /* (3x3) matrix */
u: matrix([x, y, z]); /* row matrix */
v: transpose([r, s, t]); /* column matrix */
ident(n); /* (nxn) unit matrix */
diagmatrix(n,x); /* (nxn) diagonal matrix diag(x,..,x) */
zeromatrix(m,n); /* (mxn) zero matrix */
ematrix(m,n,x,i,j); /* (mxn) matrix with M[i,j]=x, 0 elsewhere */
genmatrix(a,m,n); /* generate (mxn) matrix from a, with */
/* symbolic items for undefined elements */
addrow(M, row, ..); /* add row(s) (lists or vectors) */
addcol(M, col, ..); /* add column(s) (lists or vectors) */
B: A; /* matrix assignment (new name/pointer) */
B: copymatrix(A); /* copy matrix (new storage) */
Reference to matrix elements etc:
u[1,2]; /* second element of u */
v[2,1]; /* second element of v */
A[2,3]; or A[2][3]; /* (2,3) element */
A[2]; /* second row of A */
row(A,i); /* i'th row of A */
col(A,i); /* i'th column of A */
Element by element operations:
A + B; A - B;
A * B; A / B;
A ^ s; s ^ A;
Matrix operations:
A . B; /* matrix multiplication */
A ^^ s; /* matrix exponentiation (including inverse) */
transpose(A);
determinant(A);
invert(A);
mat_trace(A); /* trace of square matrix */
eigenvalues(A); or eivals(A);
eigenvectors(A); or eivects(A);
top
assume(pred); predicate `pred' e.g. a > 0, equal(b,3), notequal(c,0)
is(expr); check whether expr is true, based on assumptions
forget(pred); remove `pred' from assume database
features list of mathematical properties
declare(var, prop);
remove(var, prop);
facts(item); list properties associated with item
facts(); list all properties
domain:real default
domain:complex
Examples:
facts(a); list of properties involving a
forget(facts()); remove all properties (but not the features?)
forget(facts(a)); remove all properties (not features?) involving a
kill(all) clears the facts database (among other things).
plot2d(expr, range); /* one curve */
plot2d([expr1, expr2], range); /* two curves */
plot2d([parametric, expr1, expr2, range]); /* parametric */
plot2d([contour, expr], range1, range2, options) /* contour */
plot2d([discrete, xlist, ylist]); /* polygon */
plot2d([discrete, xlist, ylist], [style, points]); /* points */
examples:
plot2d(sin(x), [x, 0, 10]);
plot2d(tan(x), [x, 0, 10], [y, -2, 2]); /* truncate vertically */
plot2d([8*sin(x), exp(x)], [x, -2, 2]);
plot2d([parametric, t*cos(t), t*sin(t), [t, 0, 10]]);
plot2d([contour, x*y], [x, -2, 2], [y, -2, 2]); /* default levels */
plot2d([contour, x*y], [x, -2, 2], [y, -2, 2], [levels, 20]);
plot2d([contour, x*y], [x, -2, 2], [y, -2, 2], [levels, -1, -.1, .1, 1]);
plot2d(sin(x), [x, 0, 10], [gnuplot_term, ps],
[gnuplot_out_file, "filename"]); /* write PS file */
plot3d(expr, range1, range2); /* 3D mesh plot */
example:
plot3d(sin(x)^2 * sin(y)^2, [x, -2, 2], [y, -2, 2]);
More details in an appendix and in section 12 of the Maxima manual.
print("text");
print(expr1, expr2, ..);
disp(expr1, expr2, ..);
display(expr1, expr2, ..);
z: read("what is z?"); /* terminate reply with ; */
Read/write data (in matrix or list form) from/to a file (space-separated numbers):
load("numericalio");
read_matrix("filename");
write_data(matrix, "filename");
read_nested_list("filename");
write_data(list, "filename");
File search and display:
file_search("filename"); check for the existence of a file, using
file_search_maxima etc as search paths
file_search("filename",["path/"]); use specified path
(relative or absolute path)
file_search_maxima search path list, for load etc
file_search_usage search path list, e.g. for printfile
printfile("filename"); display contents of file
e.g. prepend a directory as follows:
file_search_maxima: cons("/home/me/work/", file_search_maxima);
Notes:
for var: first step incr thru limit do body
for var: first step incr while cond do body
for var: first step incr unless cond do body
if cond then body
if cond then body1 else body2
return(expr); /* abnormal termination of the "for" loop */
step 1 can be omitted.
x: 1.;
for n: 1 thru 10 do
(x0: x, x: .5*(x + 10./x), if x = x0 then return(x));
In this example, the control variable is obsolete and can be omitted:
x: 1.;
do (x0: x, x: .5*(x + 10./x), if x = x0 then return(x));
top
/* .. */ comments in script
Run script in maxima:
batch("filename"); run maxima commands from file
batchload("filename"); same, in quiet mode
load("filename"); run maxima and lisp code from file
Run script from the command line:
unix> maxima -b filename
top
There is a config option to display greek letters by name (without %):
->Edit ->Configure
->Worksheet
[x] Change names of greek letters to greek letters
Beware: beta gamma zeta are pre-defined functions!
set_display('xml); nice format (default)
set_display('ascii); multi-line mode, like maxima with display2d:true
set_display('none); one-line mode, like maxima with display2d:false
May be set via ->Maxima ->Change 2d display.
wxsubscripts: false
true /* default */
all /* for multi-letter subscripts */
which can also be changed in Configure ->Worksheet.
(Mis)use of array indices as subscripts (e.g. alpha[new]) is discouraged.
[x] Enter evaluates cells
In wxMaxima-0.8.5, %alpha etc are represented as greek letters by default (no need to configure).
It appears that wxMaxima has an additional mechanism to auto-load packages, in addition to setup_autoload(..) in maxima.
maxima_userdir directory for user startup files
(Unix default: $HOME/.maxima)
Startup files, see maxima(1):
maximarc
maxima-init.lisp
maxima-init.mac
The latter can be used to configure auto-loading of modules, e.g.
setup_autoload("to_poly_solve.mac", to_poly_solve, %solve);
top
display2d:false
Convert expression to TeX format:
tex(expr);
Save command output and input to file:
with_stdout("filename", commands); writes output of commands to file
file_output_append: true; switch to append mode
stringout("filename", expr1, ..); write expressions in a form
suitable for maxima input
Session transcript:
writefile("filename"); session transcript in console output format
appendfile("filename"); same, but append to file
closefile(); terminate session transcript
top
build_info();
run_testsuite();
run_testsuite(true); show bugs only
top
provided e.g. with Maxima-5.15.0 + 5.17.1:
files:
topoly.lisp (engine)
topoly_solver.mac (wrapper).
They also work with Maxima-5.10.
load(topoly_solver);
/home/b/maxima/5.15.0/topoly_solver.mac
to_poly_solve(s + sqrt(1-s^2) = 1/2, s);
sqrt(7) - 1
[[s = - -----------]]
4
to_poly_solve([sqrt(x) + y = 0, sqrt(x) = 1], [x, y]);
[[x = 1, y = - 1]]
to_poly_solve(sin(x) + cos(x) = 1/2, x);
Nonalgebraic argument given to 'topoly'
In Maxima-5.18.1, there is a new version (which does not work with
Maxima-5.10?) - it solves the last example as well:
load(to_poly_solver);
to_poly_solve(sin(x) + cos(x) = 1/2, x);
%union{...}
In Maxima-5.21.1, the to_poly_solver package is auto-loaded as needed.
plot2d(plot, options, ...) one plot item
plot2d([plot_1, plot_2, ...], options, ...) several plot items
Each plot item can be one of
expr functional expression
[parametric, expr1, expr2, range] parametric function
[discrete, xlist, ylist] discrete points
[discrete, xylist] xylist = [[x1, y1], [x2, y2], ...]
If expressions are present, the (common) name and range of the
independent variable has to be given as the first option.
Discrete points are drawn as polygons by default. For point symbols, a style option is required, specifying which items in the plot list should be points instead of lines, e.g.
[style, lines, points, lines, ..]
[same_xy, true] equal scales for x and y
[logx, true] logrithmic scale(s)
[logy, true]
[yx_ratio, value] set aspect ratio
[x, min, max] horizontal range
[y, min, max] vertical range
[label, ["text",x,y], ..] write text at specified location(s)
[title, "text"]
[xlabel, "text"]
[ylabel, "text"]
[legend, "text1",..,"textn"] legends for n curves
[legend, false] suppress legends
[grid2d, true] display grid
[point_type, value]
value = bullet, circle, plus, times, asterisk, box, square,
triangle, delta, wedge, nabla, diamond, lozenge
[color, value]
value = red, green, blue, magenta, cyan, yellow, orange, violet,
brown, gray, black, white, #RRGGBB
[pdf_file, "filename"] better use absolute pathname
[png_file, "filename"]
[ps_file, "filename"]
[svg_file, "filename"]
[gnuplot_default_term_command, "set term wxt 1"]
plot to alternative window 1 etc (default: 0)
see Maxima manual, section 12.5 "Gnuplot Options"
Note: The option name alone is a shorthand for true (if applicable).
The Greek letters can be displayed by {/Symbol a}. This gives "alpha" which corresponds to "a". The relation of the Symbol and alphabet is as follows:
| ALPHABET | SYMBOL | ALPHABET | SYMBOL | alphabet | symbol | alphabet | symbol |
|---|---|---|---|---|---|---|---|
| A | Alpha | N | Nu | a | alpha | n | nu |
| B | Beta | O | Omicron | b | beta | o | omicron |
| C | Chi | P | Pi | c | chi | p | pi |
| D | Delta | Q | Theta | d | delta | q | theta |
| E | Epsilon | R | Rho | e | epsilon | r | rho |
| F | Phi | S | Sigma | f | phi | s | sigma |
| G | Gamma | T | Tau | g | gamma | t | tau |
| H | Eta | U | Upsilon | h | eta | u | upsilon |
| I | iota | W | Omega | i | iota | w | omega |
| K | Kappa | X | Xi | k | kappa | x | xi |
| L | Lambda | Y | Psi | l | lambda | y | psi |
| M | Mu | Z | Zeta | m | mu | z | zeta |
MAXIMA>>(help) show GCL help
MAXIMA>>(run) restart Maxima session
MAXIMA>>(bye) exit
MAXIMA>>(by) exit
top