Tutorial:JMathLab/1 Introduction

From HandWiki

jMathLab Tutorial

About

jMathLab is a clone of Matlab and Octave written in Java. Unlike Matlab, it's free. Unlike Octave, it is available on all platforms where Java is installed. You can also run it using the Web browser. The web page of jMathLab is here. From this web page you can access the reference manual for all functions included with this program (limited access for non-members).

The program is also a part of the DataMelt data analysis program. Every script that is posted on this tutorial can be ran inside DMelt in the GUI or a batch mode.

How to use this tutorial

Left window is a code editor which can be used to type commands in the Matlab/Octave syntax. Press the [Run] button on the right to run these commands and to see the output. The output will be shown on the right window. You can change the divider location using the mouse. Let's get familiar with the interactive prompt. Type:

<jc lang="math"> disp('message'); </jc>

and press [Run]. You will see "message". Try to change the divider position with the mouse. This means that you can talk to the interactive shell. In fact, now you have learned how to print a string (“ok”). For example, let's print ok on different lines using "\n" as a separator:

<jc lang="math"> disp('message\n message') % comment </jc> where "%" indicates your comment for this code. Again, press [Run]. You will see a pop-up window with the 3 lines of "ok". The reason why you got a pop-up window instead inline output, is because the text did not fit to the on-line window. You can type several commands on one line, but separated them with ";"

<jc lang="math"> disp('ok'); disp('ok'); disp('ok'); % comment </jc>

You can also print numbers using formatted outputs.

<jc lang="math"> printf('%f',100)  % you can edit this command and run it </jc>

In some cases you can edit an example and run the modified code. In such cases, you will see a green border around the code. In the example below, please try to change '100' to other number and press "Run"

<jc lang="math_edit"> printf('%f',100) % you can edit this command and run it </jc>

Just to show the power of the symbolic calculations, let take definite integral of <m>x^2+x-3</m>:

<jc lang="math"> syms x a=integrate(x^2+x-3,x) printf('%f',a) </jc>

If you are not a registered member, you cannot run the code and cannot see the outputs.

Version information

To determine the version of information, type "version" ([ENTER]). You will see a pop-up window which shows the version number and the build date Check this out by running this code:

<jc lang=math"> version </jc>

Running scripts

To run a MatLab like script (with the extension "m"), use loadfile functions:

<jc lang="math"> loadfile("/home/myfile.m") </jc>

Using a standalone application

jMathLab is a part of the DataMelt project. But you can download the standalone application to work with jMathLab which is only 2MB in size. This application runs on any computer (Windows, Linux, Mac). However, you should be [a full member] of DataMelt.

Credits

The jMathLab is a derivative of two Java programs: JMathLib and Jasymca. Both are GNU-licensed thus jMathLab is also distributed under the GNU public license. Thus we fully acknowledge contributions to this project by H. Dersch (HFU Furtwangen),