On line Yamwi help system

Introduction

You can make all sorts of mathematical and graphical computations with this web interface to Maxima.

Write in the text area de code you want to be executed and then press the button below.

Examples included in this page can be copied and pasted (CTRL-C and CTRL-V) in the form before pressing the button. You can make your own variations, since the form is editable.

The documentation in this page is very basic. For a deeper introduction on Maxima's syntax:

The output obtained is like a dialog. Our questions are preceded by label %i followed by numbers and the results are labeled with %o followed by the corresponding number.


Contents


Numerical operations

Maxima likes exact results. Here we make rational operations. Sentences must end with semicolons (;).

1 + 5 * (5 - 7/9)^4 ;

But it is also possible to get floting point approximations. Here we store in variable x (with a colon :) a rational expression and then we call function float.

x : 1 + 5 * (5 - 7/9)^4 ;
float(x);

The same result can be obtained with only one sentence.

float (1 + 5 * (5 - 7/9)^4) ;

Another example with variables. Since comments are written between symbols /* and */, this is a self explained example.

/* Bind variable 'a' to a value */
a : 8 / 24;

/* Bind variable 'b' to another value */
b: 1/5 ;

/* Squaring the sum of 'a' and 'b' */
(a + b)^2;

Function float returns numbers in double precission. Let's calculate number π with five thousand decimal digits. First, we give global variable fpprec the desired precission and then we call function bfloat. Remember that the Maxima symbol for π is %pi. We also calculate the square root of 2 with 5000 decimal digits.

fpprec : 5000;
bfloat(%pi);

/* The square root of two */
bfloat( sqrt(2) );

Algebra

We can make operations with variables. Look how we transform algebraic expressions.

1 + x + 5 * y - 2/3 * x + y + 2 ;

(5*x^2 * u * r) / (u^2 * t) ;

Expanding products.

expand( (x+1)^2 * (x+5) * (x-a) ) ;

Factoring polynomials.

factor(u^6 - 14*u^5 - 23*u^4 + 808*u^3 - 320*u^2 - 12800*u) ;

Make use of function subst if you want to calculate the numerical value of an algebraic expression. Square brackets in Maxima are very important, since we can build lists with them.

f : 6.67 * 10^-11 * m1 * m2 / r^2 ;

subst([m1 = 4, m2 = 5, r = 7], f) ;
subst([m1 = mass, m2 = mass], f) ;

If you want to get information on some Maxima function or global variable, make use of describe.

describe(subst);

Equations

In general, we use function solve. Two arguments are needed, the list of equations followed by the list of unknowns.

A simple linear equation.

solve([5 * (x + 1/2) = 1 + x /3], [x]) ;

Linear equation with parameter.

solve([5 * (x + 1/2) = k + x /3], [x]) ;

A quadratic equation. Remember that sqrt is the square root and %i is the Maxima symbol for the imaginary unit.

solve([2*x^2 - 3*x + 5 = 0], [x]) ;

A system of equations. We can edit more than one line for entering a sentence. We also call for the floating point result.

sol : solve([5*x + y/8 = 4, x^2 = y],
            [x,y]) ;

float(sol);

Calculus

Make use of function limit for calculating limits.

Infinity is represented by inf and minus infinity by minf.

limit( (x-1) / (2*x + 3), x, 1);

limit( (x-1) / (2*x + 3), x, inf);

Limits from above and from below.

limit( 1 / (x-1), x, 1, minus);

limit( 1 / (x-1), x, 1, plus);

Derivatives.

fun : sin(x) * x^4 ;

diff( fun, x);

/* derivative of order three */
diff( fun, x, 3);

Indefinite and definite integrals. The base of natural logarithms is %e.

integrate(sin (2 + 3 * x), x) ;

integrate( x * exp(x), x, 1, 2) ;

Matrices

Function matrix builds matrices; its arguments are the rows of the matrix in list form. We define two matrices and then we add and subtract them.

a : matrix([1, 2, 3], [4, 5, 6]) ;
b : matrix([7, 1/9, 2], [z, x+y, -5]) ;

a + b ;
a - b ;

The operator for the matrix product is the dot (.)

a : matrix([1, 2, 3], [4, 5, 6]) ;
b : matrix([7, 1/9], [z, -5], [1, 0]) ;

a . b ;

The operator for matrix exponentiation is ^^

a : matrix([1, 2, 3], [4, 5, 6], [7, 8, 9]) ;
a^^3 ;

Other operations with matrices.

a : matrix([1, 4, 3], [7, 5, 6], [3, 8, 9]) ;

/* Inverse */
invert(a) ;

/* Transpose */
transpose(a) ;

/* Determinant */
determinant(a) ;

Graphics

The best reference for package draw is the html document A Maxima-Gnuplot interface, which contains lots of examples. You can find more examples in the Maxima manual.

In Yamwi, 2D drawings are made with function draw2d. Yamwi does not execute command plot2d, but wxdraw2d is also accepted.

A red explicit function.

draw2d (
  color = red,
  explicit(x^3-2*x^2+x-1, x, -3, 3) ) ;

An explicit function together with a parametric one. A grid is added in the background.

draw2d (
  explicit(x^3-2*x^2+x-1, x, -3, 3),
  grid = true,
  color = red,
  line_width = 4,
  parametric(sin(t), t^2, t, -2*%pi, 2*%pi) ) ;

For 3D graphics, the function to be used is draw3d.

draw3d(
  surface_hide = true,
  explicit(20*exp(-x^2-y^2)-10,x,-3,3,y,-3,3));

The last example is an animation.

draw(terminal   = animated_gif,
     delay      = 40,
     dimensions = [300,300],
     makelist(gr2d(explicit(x^(k/10),x,0,1)), k, 1, 10) ) $

Statistics

Statistical functions are defined in package descriptive and we have to load them before performing our calculations.

Statiscal graphics defined in package descriptive must be written with first letter in upper case: Scatterplot, Histogram, Barsplot, Piechart, Boxplot, and Starplot.

Our records here are stored in a list.

load(descriptive) $
sample :
  [4, 7, 6, 1, 5, 10, 3, 6, 6, 6, 9, 9, 5, 2,
   2, 7, 7, 4, 6, 7, 8, 4, 10, 10, 4] $

mean(sample) ;

median(sample) ;

/* standard deviation */
std(sample) ;

/* piechart */
Piechart(sample) $

In case of bivariate records, pairs are inroduced as a two columns matrix.

load(descriptive) $
sample:
  matrix(
    [125.1,140.7], [130.6,155.1], [135.1,160.3],
    [140.0,167.2], [145.4,169.8], [142.7,168.5])$

/* mean vector */
mean(sample) ;

/* covariance vector */
cov(sample) ;

/* correlations matrix */
cor(sample) ;

/* dispersion cloud */
draw2d(
   point_type = circle,
   point_size = 3,
   color = navy,
   points(sample)) $

User Packages

You can ask your Yamwi administrator to add your own Maxima packages, so that you can have your own code accesible from anywhere ready to be used in any moment. Here is an example of a user package.

Package mypackage.mac is installed in folder yamwi/packages, and do not forget to call function load before calculations.

We want to calculate some results on parabolic trajectories. The function to be used is tiro, which admits four arguments:

  1. Initial velocity, in m/s.
  2. Tossing height, in m.
  3. Tossing angle, in degrees, from 0 to 90.
  4. Heavenly body (T, Earth; L, Moon; S, Sun; M, Mars; X, Jupiter).

In this example, an object is tossed on Mars at ground level, with velocity 35 m/s and angle 47 degrees.

The output returned by function trajectory contains the acceleration of gravity on Mars, the parabolic equation, horizontal range, maximum height and a graphical simulation.

load("mypackage") $
trajectory(35, 0, 47, M) ;