Experiences with Scilab – 1

Scilab is a free clone of Matlab. Since this is in some way competing with Euler Math Toolbox I feel obligated to keep an eye on it. As I said many times, I wished the open community would have bundled its efforts to create an open library instead of cloning an existing tool. But let us take it as it is and see what we can do with it.

I have the Windows version. The Linux version should not look much different, however. The initial layout is very similar to Matlab with a file explorer in the left tab, a history and a variable list in the right tab, and the command shell in the middle. Scilab does not offer a notebook interface like EMT, Maple or many other software. The interface works like a shell with input and output. This is not the best idea.

Unbenannt

The main problem with shell interfaces becomes clear immediately when a demo is started. There is no space to comment the command or the output properly. For a start, I took the „Inverse Pendulum“ demo. It has nice graphics with fast and smooth animations. For explanations, it opens dialog windows which the user must close after the reading. Unfortunately, the dialog texts were not very helpful. It seems that the demo relies on some documentation outside the program unless the graphics are self-explaining. While I could guess what this demo does, I did not understand „Tracking“ demo at all.

There was also a bug in the Windows version. After clearing the history and the command shell. The demo window hangs. It can neither be closed nor can a demo be started. Closing Scilab does not help. I had to close it the task manager. No need to worry! Such things happen and are usually fixed in the next version.

For an introduction to the program, I took a PDF file by a „Consortium Scilab“ in English. It is from 2010. There are many more files available in the Scilab site. I plan to look inside some of these documents and report my findings here.

So, how does Scilab compare to EMT at first sight? Besides the bad interface it looks well done. The help in the program seems to be okay as a reference. To discover a topic you are interested in, you will need an external tutorial, since there are no complete notebooks to look at. It feels more like learning a programming language. Scilab has most advanced features of Matlab, so there should not be any problem with missing features.

For the speed, I did a first check only. The result was in favor of Scilab.

-->rand("normal");

-->A=rand(1000,1000);

-->b=sum(A,"c");

-->tic; x=A\b; toc
 ans  =

    0.041  

-->sum(x-1)
 ans  =

  - 1.438D-11

As you see, you have to put the random number generate in the correct mode for normal random variables. The function sum() takes a string to determine the sum of columns and rows. As in Matlab, the default are rows, which means that the rows are added. I want to add the columns since the solution is then all 1. In EMT, such flags are done with assigned arguments. Scilab uses strings.

EMT is slower on this. Most likely, Scilab is not doing some advanced checks and balancing to take care of badly conditioned matrices.

>A=random(1000,1000);
>b=sum(A);
>tic; x=A\b; toc;
   Used 0.729 seconds
>longest sum(x'-1)
    2.682964961309153e-012

It will need further experiments to see more details. However, I have no doubts that Scilab uses the best algorithms available.

Here is an example with a loop. Both Scilab and EMT are not very good at loops. In Scilab, I started SciNotes. This is an internal editor which helps to edit scripts. I defined a function g() there.

function y = g(x)
    y=0;
    for i=1:length(x)
        y=y+x(i);
    end
endfunction

The script can be loaded into Scilab with the arrow keys. Then we can use it.

-->tic; g(1:1000000); toc
 ans  =

    0.589

The same function in EMT can be programmed inside the notebook. It is slower. But it is also demonstrated in this notebook that any solution in C is a thousand times quicker.

>function g(v) ...
$  s=0;
$  for i=1 to cols(v); s=s+v[i]; end;
$  return s;
$  endfunction
>tic; g(1:1000000); toc
   Used 1.442 seconds
   1.442
>tic; sum(1:1000000); toc
   Used 0.003 seconds
   0.003

In EMT, you could define this simple function with Tiny C. And it would run faster than the build in sum() which can sum complex numbers or intervals and rows of matrices too.

I will continue this comparison to demonstrate the differences between the two programs.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.