Monday, November 7, 2011

Free the research #1

So this is the "second episode" of my article about Free Open Source tools for doing research, and we are going to talk about Maxima. It's just a collection of the main commands you will use.
Maxima
Website: http://maxima.sourceforge.net/
Maxima is a program similar to the more famous Derive. Really, Maxima is a CLI (Command Line Interface) application, but we can use wxMaxima: this is a GUI (Graphic User Interface) that makes the use of Maxima and its language very easy.

For example, the command solve (from the menu Equations/Solve) allows you to solve an equation in one variable (this means that the other characthers will be taken as constants):
solve([4*x^2-3*x+6=0], [x]);
This will solve the equation 4*x^2-3*x+6=0 using x as variable.
In a similar way, the command linsolve tries to solve a system of linear equations (Equations/Solve Linear System):
linsolve([3*x+4*y+6*z, x/2+y+5*z, x^2+7*y+z], [x,y,z]);
as you can see the comma is used to separate both equations and variables. And these are all easy tasks. But Maxima can do a lot more: the command ode2 (Equations/Solve ODE) finds the solution of differential equations. For example, we can look for the value of y function with the variable x:
ode2('diff(y,x,2) - y = 1, y,x);
here, 'diff(y,x,2) means the second derivate of y in function of x. The apostrophe is used to tell Maxima that we don't need the numeric value of the y derivate, but only the "concept".
In fact, obiously, it's also possibile to execute derivates (Calculus/Differentiate) and integrals (Calcolo/Integrate).
This is an undefined integral in x:
integrate(4*sin(x^2), x);
Wheter this is a defined integral in x from 0 to 1:
integrate(4*sin(x^2), x, 0, 1);
And this is a second derivate in x (please take note that, this time, we don't use the apostrophe, because we want the numeric value):
diff(4*sin(x^2),x,2);
There is a bunch of useful commands, like ratsimp,that rationalizes decimal numbers:
ratsimp(0.25);
or the functions trigsimp e trigexpand, that simplifiy or expand a trigonometric expression:
trigexpand(sin(2*x)+cos(2*x));
trigsimp(2*cos(x)^2 + sin(x)^2);
The function factor, if applied to a number returns its factorization in prime numbers, while if it's applied to an expression it factorizes polinomials.
factor(30!);
factor(x^2 + x -6);
If we want to obtain the result directly in Latex format, just use the tex function:
tex(x^2-1)/(x+1));
Obiously, there are the main constants: %e is the Neper number, %pi is π, %i is the immaginary number, %phi is the golden ratio, inf is the infinity (real), minf is the negative infinity (real), and infinity is the complex infinity.
You can also draw plots in 2 or 3 dimensions with the functions wxplot2d (Draw/Plot2D) and wxplot3d (Draw/Plot3D):
wxplot2d([x^2+3*x+2], [x,-5,5]);
this will draw the plot putting the x variable as abscissa, making it change from -5 to +5. Plots con be saved as images (click on them with the right button of the mouse).
Last, but not the least, the menù Algebra allow us to work with matrix (no, this time I'm not talking about Neo and Morpheus) and find autovalues, determinant.

9 comments:

  1. Hi!

    I just wanted to say that your post doesn't look so good on PlanetKDE.
    For some reason the text is white there too :P

    ReplyDelete
  2. Have you ever used SymPy? It's a Python library for symbolic mathematics, so similar to Maxima. However, it uses normal Python, rather than some (new) invented language, so it should in general be easier to use/learn. I've never used Maxima personally, but it would be interesting to compare the two... What do you think? :)

    ReplyDelete
  3. Hi Jan, this is because I selected "white" as text color (and I don't really know why...). Now I changed it back to black, but it may need some time to update the blog entry in planetkde.
    Answering to Vladimir, SymPy is interesting, but I seen that a person that never used programming languages works better with a program like Maxima.

    ReplyDelete
  4. Cantor [1] also integrates maxima. Please give it a try if you haven't yet.

    [1] http://edu.kde.org/cantor/

    ReplyDelete
  5. Cantor is a really interesting project, but actually it does not have a complete set of GUI menus for Maxima: wxmaxima is nicer for "common" users.

    ReplyDelete
  6. There exists also Sage (http://www.sagemath.org), which is similar in scope to Maxima and actually also includes an interface to Maxima. Personally I dislike very much the fact that you have to install a server and log in to it if you want to use the GUI version of Sage instead of having a normal GUI application.

    ReplyDelete
  7. Maxima Code is NOT a newly invented language. The syntax is highly inspired (nearly compatible) with Maple - one of the first applications doing symbolic maths.

    Most probably the maxima syntax is much older than python. ;)

    ReplyDelete
  8. Yes, saLOUt, python is quite a new language (and nobody said that maxima is newer). Anyway maxima is easier than python. At least for non programmers.

    ReplyDelete
  9. @glad
    It is possible to use Sage with Cantor.

    @saLOUt
    Well, the Maple syntax just sucks, but Python has a really nice, elaborated, consistent and simple syntax. I have not done a lot of stuff with Maxima, but the Python syntax seems to be much clearer.

    ReplyDelete