Chapter 2. Common Pitfalls

Table of Contents
2.1. The Infamous Dot
2.2. Vector Construction
2.3. Function head
2.4. Last Newline
2.5. Variable Lifetime And Scoping
2.6. Dangerous Range Generation
 

The nice thing about Scilab? It is almost usable!

  Enrico Segre

There are several peculiarities in Scilab's way of interpreting an expression that will trip the unwary. Some of them are a result of "compatability" to a certain commercial product of similar sounding name (which one?), others are home grown quirks.

2.1. The Infamous Dot

In Scilab a digit in front or after the decimal point is not enforced. This is similar to e.g. Fortran and C, but contrary to Ada. Thus, for Scilab the following three numbers are well formed


87.492211
.32493
6857.

As an aside:


    digit+.0
    digit+.
    digit+

e.g. 123.0, 123., and 123 are considered identical. The last of the three examples, a decimal point at the end of the numeral, baffles users who want to invert a vector or matrix component-wise.


-->1 ./ [1 2 3]
 ans  =
!   1.    0.5    0.3333333 !

But, hey this is correct! Then, let us squeeze out the spaces in front of the ./ operator.


-->1./ [1 2 3]
 ans  =
!   0.0714286 !
!   0.1428571 !
!   0.2142857 !

Oops! What happened? The last expression is not interpreted as


(1) ./ ([1 2 3])

but as


(1.) / ([1 2 3])

where the parentheses have been introduced for clarity. This behavior is described in SCI/README, and in the Scilab FAQ .

We suggest to avoid whitespace that influences the calculation by not letting the decimal point stick out on either side. That way expressions with numerals will always be interpreted correctly. For our example this means


-->1.0./ [1 2 3]
ans  =
!   1.    0.5    0.3333333 !

which gives what we had in mind.