Valid
	XHTML 1.1! Valid CSS!
Created 1/1/02 Modified 12/9/05
Chelton Evans

Maxima and Mathematica Notes home

Maxima
Mathematica
Lisp
HP 49G

Maxima

An open source alternative to Mathematica - to a large extent. Both are written in Lisp. Actually there are a few things it does better.

Not case sensitive.
$ suppresses printing.
Each entry generates a variable that can be refered to. eg (C4) entry as EV(c4,x=2.6);
kill(name); to remove definition.

factor(289);
expand((x+3)^3);
Assignment:    u:(x^3+1)^2; diff(u,x);
%e^(%i*%pi);
3>5;%,pred; - evaluates boolean expression.
f1(x):=x^2+sin(x); f1(.2); -defining a function.
# is not equal to operator.
evenp(35); FALSE    - even number?
oddp
mod(34,3); 1
random(n);    [0,n-1]
subst(a,b,c);    a for b into c.
integrate(1/x^2,x,1,inf);
ev(d11,numer);    - numerical evaluation.
(x:1,y:0,for i from 1 thru 10 do (y:y+i),y);
product(t+i,i,1,5);
?round(2.3);
?truncate(ev(5/2,numer));
ev(   ?truncate(   log(15)/log(2)   ),   numer   );
append(   [2,3],   [3,5]   );

e1: x^2+3*x*y+y^2;
e2: 3*x+y=1;
solve([e1,e2]);

for i:1 while i<=10 do s:s+i;

fac[1](x) := 1;
fac[n](x) := n*fac[n-1](x);

f1(n) := if (evenp(n)) n/2 else 3*n+1;

Mathematica

"Mathematica A Practical Approach" by Nancy Blachman and Colin Williams is good.

Mathematica and its memory sux. I use an older version, but often after updating a variable there is no change.
f4[x_] := ... <shift and return to update>
still no change, then for my sanity I rename the variable to a new one say f5. This is an intermediate problem for Mathematica, often it has no trouble updating the f4 variable, so it is a really anoying bug because often it works and then starts failing.

Mathematica diary

Clear[ variablename ]

GCD[a,b]   a>b
Mod[m,n]  
Prime[n] gives nth prime
PrimeQ[n] True or false if n is prime
IntegerQ[n] True of false if integer
FactorInteger[4] -> {{2,2}}
Divisors[4] -> {2,4}
EulerPhi[n]   Φ(n)
Random[ Integer,{10,10001}] 10≤integer≤10001
Floor[n]
Ceiling[n]
Round[n]
Chop[n]

{{1,2},{3,4}}.{{5},{6}} Matrix multiplication

MatrixForm[ {{1,2},{3,4}} } ]   1   2
  3   4
R1 := %31   assignment of output from In[31] to variable

Integrate[1/(1+x),x]
Solve[x*x/4+y*y/9 == 1 /. x->1.5, y]
Warning: variables returned by Solve are in no particular order, use the /. operator. eg let ei have varibles a[0], a[1], a[2], a[3], sol = Solve[ {e1,e2,e3,e4},{a[0],a[1],a[2],a[3]} ]
To put the variables into an equation say f=a[1]+a[3]*t-a[0]*t^2... f /. sol

N[ Sum[ 1/(2*i+1),{i,1,Infinity}] ] -> Infinity
Product[ 2*k+1,{k,0,3}]
While[ test, body]
If[ condition, t, f]

ListPlot[ {}, PlotJoined->True, AspectRatio->1]
Show[%167,%168], Show[p1,p2,AxesLabel->{"x","error"}]
Plot[ {x^2,x^3},{x,0.0,1.0}]
Plot[ , PlotStyle->{ RGBColor[1.0,0.0,0.0], Dashing[.03], Thickness[.002], PlotLabel->"Title" }]
Plot[ tan[x], {x,-Pi/2,Pi}, PlotRange->{-2,2}]
ParametricPlot[{2*Cos[t],3*Sin[t]},{t,0,2*Pi}]
Plot3D[ x*y, {x,-1.0,1.0},{y,-1.0,1.0} ]

SumOfList[{1,2,3}] ->6
tmp={{1},{2},{3}] to extract elements from list
tmp[[1]] -> {1}
tmp[[1]][[1]] -> 1 left to right operator [[]] precidence

For[ start, test, inc, body ]
ToString[ ]
StringJoin[{"s1","s2"}]
Unprotect[Cos]; Unprotect["^"]; Cos[j*Pi]:=(-1)^j; (-1)^(2*j):=1; Protect["^",Cos]; Flatten[ {1,2,3,{333,2}} ] -> {1,2,3,333,2}
AppendTo[s,elem]
Append[{a,b},c} -> {a,b,c}
Prepend[{a,b},x] -> {x,a,b}
PrependTo[ ]
Insert[{a,b,c},x,2] -> {a,x,b,c}
Insert[{a,b,c},x,{{-1},{1}} -> {x,a,b,c,x}
Take[{a,b,c,d,e},-2 -> {d,e}
Position[{1+x^2,5,x^4},x^_] -> {{1,2},{3}}
Drop[{a,b,c,d,e},2] -> {c,d,e}
Reverse[{a,b,c}] -> {c,b,a}

Rest[{a,b,c}->{b,c} //removes first element
Part as operator {a,b,c}[[2]] -> b
Part[{a,b,c},1] -> a
Part[ {a,b,c}, {1,3}] -> {a,c}
ReplacePart[exp,new,n] ReplacePart[{a,b,c,d},x,3] -> {a,b,x,d}
Last[ {a,b,c} ] -> c

Delete[ {a,b,c}, 2] -> {a,c}
doesn't change initial argument, returns value
Map[ f,{a,b,c} ] -> {f[a],f[b],f[c]}
MapAt[ f, {a,b,c,d}, {{1},{4}} ] -> {f[a], b, c, f[d]}
MapAt[ f, {a,b,c,d}, 2 ] -> {a, f[b], c, d}
Length[ {a,b,c} ] -> 3

Array[f,3] -> {f[1],f[2],f[3]}
Table[ f[i], {i,3} ] -> {f[1],f[2],f[3]}
Nest[ f,x,3 ] -> f[f[f[x]]]

Return[ expr ] - used to make a modual a function Evaluate[ expr ]
f[a_] := Module[ { }, expr ]
f[arguments] := Module[ {local variables}, .. Return[ ] ];

Fit[{{-2,1},{0,0},{2,1},{3,7}},{1,x,x^2},x] least squares poly approx

Directory[] display the current directory
SetDirectory[""] FileNames[]
L1 = ReadList["data04.txt", Table[Number,{3}]] Creat a table by reading in 3 numbers at a time into a list structure.

Limit[Tan[x],x->Pi/2] -> Infinity
Collect[ 3*x+5*x^2+z*z*x+y+2*x,x] Collect terms in powers of x
Series[Log[1+x],{x,0,5}]
s1[s_,n_] := Table[SeriesCoefficient[s,i],{i,0,n}]

Apart[1/(1-x)/(2+x)] ->   -1           1
                       ---------- + ---------
                       3 (-1 + x)   3 (2 + x)

Needs["Graphics`Shapes`"] refers to C:\WNMATH22\PACKAGES\GRAPHICS\SHAPESS.M

Binding values to function arguments

f1[a_,b_,x_] := a*x+b/x;
f1[a_,b_][x_] := f1[a,b,x];

f2[a_,b_,n_] := Nest[f1[a,b],1.0,n]

f2[0.5,4.5,5]

Utility

(* Plot symbolic expression in t on [c+m*[0..1]] at n+1 points *)
symPlot[c_,m_,n_,f_] := Module[ {tbl},
   tbl := Table[ {N[i/n*m+c], f /. t-> N[i/n*m+c]} ,{i,0,n} ];
   ListPlot[ tbl, PlotJoined->True, AspectRatio->1] 
]
   (* Plotting a complex function *)
   ParametricPlot[ {Re[f1[t]],Im[f1[t]]},{t,0,Pi}]

Lisp

( + 1 3 5 )
9

expt root mod + - * /
numberp zerop plusp minusp evenp oddp > <
quit
( defun g2 (a b c )
   ( + a b c ) );