Expressions

 

Like most other programming languages, SCILAB provides mathematical expressions, but unlike most programming languages, these expressions involve entire matrices. The building blocks of expressions are

 

Variables
Numbers
Operators
Functions

 

 

 

 

Variables

SCILAB does not require any type declarations or dimension statements. When SCILAB encounters a new variable name, it automatically creates the variable and allocates the appropriate amount of storage. If the variable already exists, SCILAB changes its contents and, if necessary, allocates new storage. For example

 

 num_integer = 100
creates a 1-by-1 matrix named num_integer and stores the value 100  in its single element.

 

Variable names consist of a letter, followed by any number of letters, digits, or underscores. SCILAB is case sensitive; it distinguishes between uppercase and lowercase letters. S and s are not the same variable. To view the matrix assigned to any variable, simply enter the variable name.

 

 

 

 

Numbers

SCILAB uses conventional decimal notation, with an optional decimal point and leading plus or minus sign, for numbers. Scientific notation uses the letter e to specify a power-of-ten scale factor. Imaginary numbers use either i or j as a suffix.

Some examples of legal numbers are,

        3                        -199              0.00002

        1.2345667          1.31e-31        1.563e24

        0+1*%i                3-2*%i          1.25e5*%i

 

 

 

 

 

Operators

Expressions use familiar arithmetic operators and precedence rules.

 
+   
Addition
-
Subtraction
*
Multiplication
/
Division
^
Power
'
Complex conjugate transpose
( )
Specify evaluation order

 

 

 

Functions

SCILAB provides a large number of standard elementary mathematical functions, including abs, sqrt, exp, and sin. Taking the square root or logarithm of a negative number is not an error; the appropriate complex result is produced automatically.

Some of the functions are built-in and are very efficient.

 

 

 

 

Expressions

You have already seen several examples of SCILAB expressions. Here are a few more examples, and the resulting values.

 

rho = (1+sqrt(5))/2

rho =
    1.6180

a = abs(3+4*%i)

a =
     5