pianofisica

Mathematics & Physics, Maxima, a bit Python & Wolfram, and Arts

Learn How to use Maxima through Examples (Basics)

Though it would be enjoyable to manipulate equations,
more or less it sometimes falls into an unskilled work.

To make your learning more efficient,
it would be beneficial to let such tedious work be done by your computer.

A well-known software manipulating equations would be "Mathematica",
whenever facing any difficulties, you might be able to ask some help
by referring to its substantial on-line help,
or even you can find some information on web because there are many users.

However, there is a charge (and it is expensive).

Here I'd like to introduce you "Maxima",
which can be said to be a free version of "Mathematica" .

Once you get to know how to use it,
it must serve you well as a kind of developed scientific calculator!

For downloading and installing "Maxima", see for example the following site

maxima.sourceforge.net

How to use Maxima


An input of Maxima ends with " ; " or " $ "

The latter " $ " is an option for not displaying the output on your monitor.

Once you input what you want to evaluate,
press "Shift" + "Enter", then it will be done.

Anyway, let's get do it!

The following shows many examples of input for Maxima.

Copy, paste, and do it, and modify the input!

Addition, Subtraction, Multiplication, Division

3+2;   /* comment (string which is ignore for evaluation) is made by closing with "/*  */". */
3-2;
3*2;
3/2;

Power, Factorial, Double factorial, Square root

3^2;
50!;
50!!;
sqrt(50);

Floating point

Big number
float(10^8);
bfloat(10^8);
Napier's constant
%e;
float(%e);
bfloat(%e);
Pi
%pi;
float(%pi);
bfloat(%pi);
Square root of 2
float(sqrt(2));
bfloat(sqrt(2));

Imaginary number

Imaginary unit
%i;   /* imaginary unit is represented by " %i " */
%i^2;
Complex conjugate
conjugate(2+sqrt(3)*%i);
conjugate(a+b*%i);   /* letters are treated as a real number as long as no flag */
Real part, Imaginary part
realpart(2+%i*sqrt(3));
imagpart(2+%i*sqrt(3));
Absolute value
abs(2+%i*sqrt(3));
Polar form
polarform(2+%i*sqrt(3));
Rationalization of denominator
rectform(1/(2+%i*sqrt(3)));
rectform(1/(a+%i*b));

Algebraic manipulations

Prime factorization
factor(10!);
Factorization of expression
factor(x^2-4*x+3);
factor(x^6-1);
Factorization into Gaussian integer polynomial
gfactor(x^2+1);

where Gaussian integer is a complex number of its real part and imaginary part are both integer.

Partial fraction decomposition
partfrac(1/(x^2-4*x+3), x);
partfrac(1/(x^6-1), x);
Reduce to a common denominator
xthru(1/(x-1)^2+1/((x-1)*(x-2)));
Expand expression
expand((x+1)^6);
Order in ascend
powerdisp:true$   /* to make it descend, replace "true" with "false" */
expand((x+1)^6);
Simplify expression
ratsimp((2*x-2)/((x-1)^2*(x-2)));
Judge True or False
is(0=sqrt(2)-2^(1/2));
is(0=sqrt(2)-2^(1/3));

but sometimes requires proper process:

is(x^2-2*x+1=(x-1)^2);
is(x^2-2*x+1=expand((x-1)^2));
Extract coefficient of a specific term from expression
ratcoeff((x + y)^6, x, 3);
ratcoeff((x + y)^6, x, 4);
Substitute a value in expression
subst(3, x, a*x^2+b*x+c);
Summation, Toal power
sum(k, k, 1, 10);
sum(k, k, 1, n), simpsum;
prod(k, k, 1, 10);
is(10!=prod(k, k, 1, 10));

Equation

Solve simultaneous equations
linsolve ([3*x+4*y=5, 2*x+3*y=3], [x, y]);
Find root of equation
solve(a*x^2+b*x+c=0, x);

Limit

Evaluate limit
limit( sin(x)/x, x, 0 );

Define function, Evaluate it at some value

Assign expression to letter, Evaluation
u:x+y;
v:(x+y)^3;
subst(5, x, u);
ev(u, x: 5);
ev(v, [x: 3, y: 2]);
Use assigned letter: 4 operations
u+v;
expand(u+v);
factor(u+v);
expand(u*v);
u/v;
Use assigned letter: differentiation
diff(u, x);     /* 1st partial derivative of u with respect to x */
diff(u, y);     /* 1st partial derivative of u with respect to y */
diff(v, y, 2);     /* 2nd partial derivative of v with respect to y */
is(0=diff(u, x, 1)-diff(u, x));
Use assigned letter: Integration
integrate(u, x);   /* Indefinite integral of u over x */
integrate(u, x, x1, x2);   /*definite integral of u over x from x1 to x2 */
integrate(v, y);
Define function, Differential, Integral, Taylor expansion, Substitution
f(x):=log(1+x)/x$
integrate(f(x), x);
diff(f(x), x, 1);
taylor(f(x), x, 0, 5);  /* Taylor expansion of f(x) with x around x=0 up to order 5 */
g(x):= x^2$
h(x):=g(f(x))$
subst(5, x, h(x));
Extract LHS, RHS of equation, Extract Denominator, Numerator
F(x):=x+1$
G(x):=x^2+x-2$
eq: x+1 = F(x)/G(x)$
rhs(eq);     /* RHS of eq */
lhs(eq);     /* LHS of eq */
denom(rhs(eq));
num(rhs(eq));
solve(eq, x);

Differential equation

Solve ordinary differential equation
assume(k>0)$
desolve( diff( u(t), t, 2 ) = - k^2*u(t), u(t)  );

Manipulation of trigonometric function (Hyperbolic function)

Expand argument sum
trigexpand(sin(a+b));
trigexpand(cos(a+b));
trigexpand(cosh(a+b));
trigexpand(tanh(a+b));
Simplification
trigsimp(sin(a)^2+cos(a)^2);
trigsimp(sinh(a)^2-cosh(a)^2);
Reduction
trigreduce(sin(a)^2);
trigreduce(cosh(a)^3);
Display in exponential function
exponentialize: true$  /* To display in trigon. change "true" ==>> "false" */
sin(a);
cosh(a);

List

Make List, Refer its element
S:[a, b, c];
S[1];
S[3];
Use list
T:[1, 10, 100, 1000]$
sum( T[i], i, 1, 3);
Number of list elements
length(S);
length(T);
Generate a list
n[k] := k$
n[10];
N[n]:=makelist(n[k], k, 1, n)$
N[10];

Iterative process

WHILE
i:0$ while i<5 do(i:i+1,print("i=", i));
FOR
for j:1 step 1 thru 5 do print(j);
Advanced: Numerical solution via iterative substitution

A numerical solution to an equation  x+e^x=0 can be found by iterative substitution
starting with  x_0=0 and generating a sequence by iteration given by

 \displaystyle{\quad x_{n+1}=-e^{x_n} }

indeed

kill(all)$
x[0]:0$
for i:1 step 1 thru 100 do x[i]:bfloat(-exp(x[i-1]))$
x[100];
bfloat(x[100]+%e^(x[100]));

or using "while"

kill(all)$
x[0]:0$
i:0$ while i < 100 do(
i:i+1,
x[i]:bfloat(-exp(x[i-1]))
)$
x[100];
bfloat(x[100]+%e^(x[100]));

Display the output in TeX style

Eq:a*x^2+b*x+c=0$
sol:solve(Eq, x)$
sol1:rhs(sol[1]);
sol2:rhs(sol[2]);
tex(sol2);

Conditional branch

H(x):=if  x < 0  then 0 else 1$

This is the Heaviside step function,
which returns 1 for non-negavite input, and otherwise 0.

Advanced: Numerical solution via bisection method

Let us find a numerical solution to  \cos(x)=x
Here is an example of "if-then-else" and
"block" which regards and carries out several process as a single process.

f(x):=bfloat( cos(x)-x )$
a[0]:bfloat(0)$
b[0]:bfloat(1)$
i:0$ while i<10 do(
if  f((a[i]+b[i])/2) < 0  then block(a[i+1]:bfloat(a[i]), b[i+1]:bfloat((a[i]+b[i])/2))
else block(a[i+1]:bfloat((a[i]+b[i])/2), b[i+1]:bfloat(b[i])),
i:i+1);
c[n]:=bfloat((a[n]+b[n])/2)$
makelist(a[i], i, 0, 9);
makelist(b[i], i, 0, 9);
makelist(c[i], i, 0, 9);
makelist(f(c[i]), i, 0, 9);

Linear algebra

Input matrix
s1: matrix([0,1], [1,0]);
s2: matrix([0,-%i], [%i,0]);
s3: matrix([1,0], [0,-1]);
M: matrix([ a11, a12, a13 ], [ a21, a22, a23 ]);
Refer matrix element
M[1][3];

or

M[1,3];
Sum, Product
s1+s3;
s1.s3;
Determinant
determinant(s2);
Inverse matrix
invert(s2);
Transposed matrix
transpose(s2);
Eigen value
eigenvalues(s2);
Eigen value, Eigen vector
eigenvectors(s2);

KeywordsMaxima

プライバシーポリシー