Chapter 2. Common Pitfalls

 

The nice thing about Scilab? It is almost usable!

  es
Table of Contents
The Infamous Dot
Vector Construction
Last Newline
Variable Lifetime And Scoping

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, others are home grown quirks.

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. Therfore, the following three numbers are well formed

    87.492211
    .32493
    6857.

As an aside: digit+.0, digit+., and 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 !

Hey, but 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.