Home
Up

Using Scilab, Part 2: Basics

The underlying idea of Scilab is that every quantity is an array, or matrix, and that operations on those quantities (such as addition, subtraction, division, multiplication, inversion, etc.) is automatically carried out as matrix addition, subtraction, division, and so on. Scalars are simply special cases --- 1×1 arrays.

For example, suppose the addition of the numbers 1 and 2 are needed. At the Scilab prompt, the user simply types 1+2 and hits the Return key to see that the answer ("ans") is 3

What this means is that a new variable has been set up, called ans, which currently holds the 1×1 array (i.e., the scalar) 3. It is then possible to use that result in a new calculation. Suppose we want to divide the result of 1+2 by 3. We could then type ans/3 to see

The Scilab variable ans now holds the scalar 1. Equivalently, we could define other Scilab variables, say,

to come up with the same result. This way we could use the scalars a, b, and c in future applications and we wouldn't need to type them all in again.

Such a shortcut becomes important when we remember what Scilab was originally designed for: to operate on matrices. Suppose, for example, that we want to add the two given matrices

together to obtain C = A + B. This can be done by typing

to obtain

Note than the two methods of entering a matrix

Separating rows by pressing Return, and
Separating rows with semicolons ";" are equivalent.

In all cases, elements along a row are separated by spaces.

 

 

This web site copyright © 1999-2000 by Robert A. Luke.  All rights reserved.