MAXIMA PRIMER  (under construction)

Maxima 5.19.2 http://maxima.sourceforge.net
Using Lisp GNU Common Lisp (GCL) GCL 2.6.8 (aka GCL)
Distributed under the GNU Public License. See the file COPYING.
Dedicated to the memory of William Schelter.
The function bug_report() provides bug reporting information.

 

by Reinaldo Baretti Machín

 

Free counter and web stats

 

http://www1.uprh.edu/rbaretti

http://www1.uprh.edu/rbaretti/methodsoftheoreticalphysics.htm

http://www1.uprh.edu/rbaretti/methodsoftheoreticalphysicsPart2.htm

http://www1.uprh.edu/rbaretti/methodsoftheoreticalphysicsPart3.htm

http://www1.uprh.edu/rbaretti/methodsoftheoreticalphysicsPart4.htm

 

e:mail   reibaretti2004@yahoo.com

 

References:

1.  Maxima 5.19.2  http://maxima.sourceforge.net

Remember

There is always more than one way to do it !

1. Some "numerical" constants or calling of functions

!   factorial       4!;    24

%pi    symbol for π

log(10) ,numer ;   2.302585092994046   log(x)   invokes the natural logarithm of the number x

To get log base 10 we can define the function    log10(x):= log(x)/log(10) =  0.43429448190325* log(x)

%i    square root of (-1)  ,  e.g. complex number   3+5*%i

exp(x)   exponential function ,  e.g.   exp(1),numer; 2.718281828459045

inf    symbol for infinity  e.g   integrate(exp(-x),x,0,inf);   1

 

 

 

The    kill command

In the example above kill(a) will clear the variable a. On the other hand  kill(all) will clear everything, all functions, formulas, operation , variables written previously .

 

Complex numbers     

 

 

 

Vectors        ************************

 

 

2. Calling of Functions

Selected Library of functions

 

ALGUNAS FUNCIONES

 

 

Defining a function f(x)

 

 

Calculating the volume a sphere

Notice that  V(2); gives an expression while V(2),numer; produces a numerical value.

 

3. Differentiation

The derivative of f(x) = x3 is defined. It is evaluated with the command subst

To find the second derivative use

d2f(x):=diff(f(x),x,2);d2f(x);   6 x

Find the first  derivative of  y(x)=20 sin(5x) , evaluate at x = π/4

 y(x):=20*sin(5*x);d1y(x):=diff(y(x),x);d1y(x);

        y(x) := 20 sin(5 x)

         d1y(x) := diff(y(x), x)

            100 cos(5 x)

 

subst(%pi/4,x,d1y(x)),numer;    - 70.71067811865477

 

 

4. Integration

Integration when the anti derivative exists

 

integrate(1/(a*x+1),x);   log(ax+1) /a   

 

assume(b>0); integrate(1/(b^2+x^2),x);

atan(x/b) /b

 

definite integral

b:2;integrate(1/(b^2+x^2),x,0,10*b);    atan(10) /2

 

integrate(x^3+2*x+1,x,0,2);  10

 

To obtain a decimal expression

 b:2;integrate(1/(b^2+x^2),x,0,10*b),numer;   0.73556383715187

 integrate(sin(x),x,0,%pi/2); 1

 

Numerical integration  if the anti derivative does not exist

romberg((1+x^5)^(3/2),x,0,2);  48.32994016074022

 

One may also employ the command quad_qags

integration of  x1/2 exp(-x2 )   from 0 to 100

quad_qags(x^(1/2)*exp(-x^2),x,0,100);

 [0.61270835123259, 1.2830558837606532E-9, 399, 0]

The result is 0.612

 

Two dimensional integration

      ∫0101   xy dx dy = 1/4

integrate(integrate(x*y,y,0,1),x,0,1);  

1/4

 

 

020020   exp(-x2 -y2 ) dx dy

 romberg(romberg(exp(-x^2-y^2),y,0,20),x,0,20);

 0.78539817348253

 

5. Plots

V1(t):=110*sin(2*%pi*t); V2(t):=110*sin(2*%pi*t+%pi/6);

 

plot2d(V1(t),[t,0,2]) ;

 

Double plot

plot2d([V1(t),V2(t)],[t,0,2]);

 

Three dimensional plot

Top hemisphere of the sphere   z2 = 4-x2 -y2 .

 z(x,y):=(4-x^2-y^2)^(1/2);

 plot3d(z(x,y),[x,-2,2],[y,-2,2]);

 

 

6.  Linear systems

solve([2*x+y+z=5,3*x-5*y=10,y+2*z=3],[x,y,z]),numer;

[[x = 1.956521739130435, y = - 0.82608695652174, z = 1.91304347826087]]

 

Roots of a quadratic equation

solve(x^2-5*x+6 =0,x);

[x = 3, x = 2]

 

 

 

7.  Matrices

defining matrix A

 

finding the inverse of A

 

Verifying  that  A A-1 = 1

 

Multiplication of matrices A and B

 

 

Eigenvalues of a Matrix H

 

 Interpretation : the roots are the first pair of numbers.  In this case the second root has multiplicity 2.

 [[1, 3], [1, 2]]  ;    meaning   r1= 1  multiplicity one                                    

                                           r2= 3  multiplicity 2

 

 We define an arbitary vector

  vector:matrix([3,-1,2]);   this is a row ....

multiplication of H by the transpose of the said  vector

 

Finding the eigenvalues and eigenvectors of matrix A

The eigenvalues are  2 - 51/2 ;  2 + 51/2 . The eigenvectors are  v1 = ( 1  , - (51/2 -1)/2   )  ;v2 = ( 1  ,  (51/2 +1)/2   )  .

v1 and v2 are  not normalized.

 

 

8.  Differential equations

1rst order

 dy/dx + a y = V  , a and V are constants , initial condition y(0)=0 .

 

Hence y(x) =  (V/a) { 1- exp(-ax) }

An RC circuit has R=100 ohms, Cap= 1E-6 F , V= 6 volts . Initial condition q(0)=0 , find q(t) .

 

R:100; Cap:1.E-6;V:6; ode2(R*'diff(q,t)+q/Cap= V,q,t),numer;

We write explicitly the function q(t)

q(t):=exp(-1.E4*t)*(6E-6*exp(1.E4*t)+c);

solve(q(0)=0,[c]),numer;

[c = - 6.0000000000000002E-6]

define c

(%i12) c:-6E-6;

Define VC and VR

VC(t):=q(t)/Cap;VR(t):=V-VC(t);

plot2d([VC(t),VR(t)],[t,0,3.5*R*Cap]);

 

VC increases as VR decreases. The time range is       0 < t < 3.5 (RC) .

 

2nd order DE

Consider the simple harmonic oscillator whose DE is  d2 x/dt2 = (-k/m) x  . Let the paramteres  k= 4N/meter , m=1kg and the initial conditions are x(0)=1.5 , v(0) = (dx/dt)t=0 = 0 . 

               k:4;m:1;ode2('diff(x,t,2)=-(k/m)*x,x,t);

             x = %k1 sin(2 t) + %k2 cos(2 t)

Define x(t)

x(t):=k1*sin(2*t)+k2*cos(2*t);

Define v(t)

v(t):=diff(x(t),t);v(t);

v(t):=2*k1*cos(2*t)-2*k2*sin(2*t);

Find the constants k1,k2 using the initial conditions

solve([x(0)=1.5,v(0)=0],[k1,k2]);

[[k1 = 0, k2 = 3/2]]

Define k1, k2

k1:0;k2:3/2;

plot2d([x(t),v(t)],[t,0,4*%pi/2]);

x(t) starts at 1.5 and v(t) starts at 0.

 

 

 

9.   Special Functions 

Bessel , Legendre ,Laguerre  Hermite...

 

bessel_j(ν ,x);   invokes  the Bessel function of order ν and argument x  

example :

bessel_j(0,1.5);  

 0.51182767173592

plot2d(bessel_j(0,x),[x,0,15]);

 

 

Fourier integral  transforms

The definitions of the sine and cosine integral transform employed by MAXIMA are

                    F(z) = (2/π) ∫ f(x) sin (z x) dx    ,       0  ≤ x  ≤ ∞

 

                   F(z) = (2/π) ∫ f(x) cos (z x) dx    ,         0  ≤ x  ≤ ∞.

Let    f(x) = exp(-ax)   , a > 0 . One loads first the fourier pack ,

Another example , let f(x) = x exp(-ax)

 

Hermite polynomials

Plot of Hermite polynomials of order 2 and 3 .

plot2d([hermite(2,x),hermite(3,x)],[x,-2,2]);