Some Scilab tips

Beware of un-declared variables

Scilab has a unique feature which is potentially dangerous and can make debugging very difficult. This has to do with un-initialized variables. Let me give an example. In the code below, func1 calls func2 and func2 is supposed to return the average value of its input vector x.

function y = func1()

n = 10
x = linspace(0,1,n)
y = func2(x)

endfunction

function y = func2(x)

y = sum(x)/n
printf("n = %d\n", n)

endfunction

Note that in func2 I did not initialize the value of n but scilab will not complain. It checks if there is a variable of the same name in the calling function and if it finds it, then it uses the value of that variable. In my example, it will not be a problem since the correct value of n in func2 is the same as in func1. But you can imagine how disastrous this can be.

 
comp/scilab.txt · Last modified: 2006/11/16 08:53 by pc     Back to top
Get Firefox! Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki
This site will render correctly in Mozilla/Firefox.