- •Міністерство освіти і науки, молоді та спорту україни
- •Laboratory Works of Computing and Programming
- •Contents
- •1.2 Base Concepts of Operating Systems
- •1.3 Linux (lubuntu) Operating System
- •1.4 Tasks for Independent Work
- •1.5 Test Questions
- •2 Laboratory work № 2 Word Processor libreoffice.Writer
- •2.1 What Word Processors Can Do
- •2.2 Tasks for Independent Work
- •2.3 Test Questions
- •3 Laboratory work № 3
- •Introduction to the calc spreadsheet
- •3.1 The Basic Opportunities of Spreadsheets
- •3.1.1 Calc’s Environment
- •3.1.2 Calculations in Calc. Creating and Coping Formulas
- •3.2 The Calc charting capability
- •3.3 Tasks for Independent Work
- •4.2 Main Rules of Works in Scilab System
- •Variables
- •Input of vectors (arrays)
- •Input of matrixes
- •Some operations with matrixes with use of the operator ":"
- •Input from keyboard
- •Operators. Expressions use familiar arithmetic operators and precedence rules.
- •Intrinsic scilab Functions
- •Examples of Expressions
- •4.3 Individual Tasks for Laboratory Work
- •4.4 The Tasks for Self-Examination
- •4.5 Test Questions
- •5 Laboratory work № 5
- •5.3.1The plot function
- •5.3.3 Preparing Graphs for Presentation
- •Interactive Plot Editing
- •5.3.4 3D Plotting
- •5.4 Individual Tasks
- •5.6 Test Questions
- •6 Laboratory work № 6 programming in Scilab
- •6.1 Programming in scilab
- •What Happens When You Call a Function
- •Clearing Functions from Memory
- •6.2 Tasks for laboratory work
- •6.3 Example of performance of the laboratory work
- •6.4 Test Questions
- •7 ReferencEs
4.2 Main Rules of Works in Scilab System
Using the prompt line, it is possible to assign values to variables and to perform usual operations:
--> x = 4
x =4
--> y = 2
y =2
--> x + y
ans =6
--> x * y
ans =8
Here, we note that SCILAB assigns the result of the operations to a variable named ans.
We can find out the value of a given variable by typing the name on the prompt line:
--> ans
ans =8
The solution to the above addition has been lost. A good way to prevent that is to assign operation results to a given variable:
--> x = 4; // semi-colons prevent the output on the screen
--> y = 2; // two slash enables comments
--> a = x + y
a =6
--> b = x * y
b =8
Scilab stores numbers (and characters) in matrices. A matrix can be seen as a table, consisting of m rows and n columns; (m*n matrices, also denoted i*j matrices). Scalar variables do not exist per se, they are treated as 1x1 matrices. The general form of a Scilab matrix (here 3x3 matrix) is A = [11 12 13; 21 22 23; 31 32 33] Row elements can also be separated by commas: A = [11, 12, 13; 21, 22, 23; 31, 32, 33]
In both cases semicolons separate rows.
Variables
Like most other programming languages, the SCILAB language provides mathematical expressions, but unlike most programming languages, these expressions are the matrices.
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_students = 25
creates a 1-by-1 matrix named num_students and stores the value 25 in its single element. To view the matrix assigned to any variable, simply enter the variable name.
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. A and a are not the same variable.
Variables can be numeral, text and other types. We shall consider numeral and text variables. It is impossible to admit the repeat of a name of variable with a name of any command.
All numbers in Scilab have 15 digits of accuracy.
Numerical variables are numbers, vectors, matrixes and multivariate files. In a computer all numbers are submitted approximately with 16 decimal signs, under each real number is allocated 8 bites, under complex - 16.
Integers. In system they are not allocated obviously. We shall type and execute separately each command:
a=2 a=2.0 a=2; a=1:6 b=1:20 c=10:-2:5
Real 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. Some examples of legal numbers are
3 -99 0.0001
9.6397238 1.60210e-20 6.02252e23
The range of real numbers is kept in constants: realmax realmin
Some other constants of system Scilab: pi i j eps.
Perform commands
--> rad=2; ht=3;
--> vol=%pi*ht*rad~2
vol =37.6991
Text variables - Text variables enter in inverted commas:
t='Moscow'
Formats to a conclusion of numbers in package Scilab
Function format([type],[long]) set the format of variable to output on screen. Type can be equal ‘v’ for format with decimal point or ‘e’ for science format.
Examples:
x=rand(1,4);
-->format('v',10);x
x = 0.2113249 0.7560439 0.0002211 0.3303271
-->format(20);x
x = 0.21132486546412110 0.75604385416954756 0.00022113462910056 0.33032709173858166
-->format('e',10);x
x = 2.113D-01 7.560D-01 2.211D-04 3.303D-01
-->format(20);x
x = 2.1132486546412D-01 7.5604385416955D-01 2.2113462910056D-04 3.3032709173858D-01
-->x=[100 %eps];
-->format('e',10);x
x = 1.000D+02 2.220D-16