Lab Activity 1 Engineering Control Systems
Lab Activity 1 Engineering Control Systems
Lab Activity 1 Engineering Control Systems
Abstract
Scilab is a free and open-source, cross-platform numerical computational package and a high-level,
numerically oriented programming language. It can be used for signal processing, statistical analysis,
image enhancement, fluid dynamics simulations, numerical optimization, and modeling, simulation of
explicit and implicit dynamical systems and (if the corresponding toolbox is installed) symbolic
manipulations.
Scinotes is an embedded Scilab text editor. It can be started with a fresh text buffer pressing the "Editor"
button on top of the main Scilab window, or from Scilab command line with the instruction editor(), or it
can open specific files if invoked with any of the calling sequences (whithout any parameters, it opens
editor with a blank file).
In this activity, the students will be introduced to Scilab and some of its capabilities, including creating
variables and assigning values to them (from integers to strings to polynomials), operators (including
matrix operations), creating functions, and batch commands or scripting. The student is expected to
learn the basics of using Scilab and Scinotes to be used in future lab activities.
1 Objectives
To introduce students to a mathematical software that can be used to simulate control systems.
2 List of equipment/software
Personal Computer
Installation of SCILAB
For this activity, you will be introduced to the basic command line interface as well as scripting of a set
of commands in SciNotes. Some basic features of Scilab such as variable declarations, operations and
flow control will be examined in this activity. Some commonly used functions will also be introduced.
3.1 Variable
In Scilab, you can easily create and instantiate variables anytime. Unlike the C language, Scilab’s
variables are dynamic and don’t have to be created before they are stored with values.
Open you Scilab now and try the following in the console.
--> clear
--> a = 1
The console should respond with the value of a. Now, after the above command, try doing the following:
--> b = a
The console should respond with the value of b which is just the value of a in the previous command.
--> b = aaa
Since aaa has not been assigned a value yet, it still does not exist.
Another convenient feature of Scilab is that you can assign any datatype to a variable even after you had
previously assigned a different datatype. For example:
--> b = 1
--> b = “Hi, this is a string”
--> b = [“this”,”is”, “a”, “vector/array”]
These commands will not produce an error. The datatype of the variables in Scilab adapt to whatever
value you store in it.
You may have noticed that the last command is an array. Arrays in Scilab are values enclosed in “[“ and
“]” with values separated by spaces or commas. You can also create a matrix by separating rows with a
semicolon.
[ ]
2. What will you enter in the command line if you want to assign a_matrix with 4 5 6 ?
7 8 9
3.1.1 Polynomial
You can easily create polynomial using the poly function read the help file for different methods of using
the poly function. The simplest way is the following:
3.2 Operators
Scilab has a lot of operators in addition to basic arithmetic operations. Since Scilab operates on matrices
by default, basic arithmetic operations are applied on matrices.
Operator Description
+ Matrix addition
- Matrix subtraction
* Matrix Multiplication
/ Matrix division. A/ B= A∗B−1
\ Matrix back-division. A ¿=A−1∗B
^ Matrix exponential.
‘ Transpose
If you want element-wise operation using those operators, the operator is preceded with a “.”
--> a = [1, 2; 3, 4]
--> b = [3, 4; 5, 6]
--> a + b
ans =
4. 6.
8. 10.
4. Do a matrix multiplication and element-wise multiplication on a and b. What are the results? Are
the results equal?
Accessing an element in an array or matrix is by calling the variable with a parenthesis. For example, to
access the 1st element of b:
You can use the $ to indicate the index of the last element.
--> b(1,$) //returns the last element of the first row.
Sub-matrices can be extracted by putting an array or matrix as index. The content of the matrix index
will be the rows/columns that will be included in the sub-matrix. You can use “:” to include all elements
on that row/column.
--> c = [1, 2 ,3; 4, 5, 6; 7, 8, 9]
--> d = c([1,3],[1,2])
ans =
1. 2.
3. 8.
--> e = c(:,1) //returns all the rows in the first column.
ENDFUNCTION
What is the result or the behavior of the above statements in the console after executing the script?
8. Write a function called myfunct that accepts two parameters A and B. The function will return the
result of (A+B)*B. Execute the script what is the result?
9. Call the function you created in #8 and pass as parameters the values 3 and 9. What is the result?
10. What will your function return if the parameters are [1,2,3] and [4; 6;7]?
11. How about [1, 2, 3 ; 3, 5, 1; 5, 6, -1] and [3, -1, 4 ; -3, 5, 1; -5 6 -1]?
1
# 4)
# 5)
a’ = [ 12 34]
1. 3.
3. 4.
# 6)
3
c(1:3, $) = 6
9 []
# 7)
[
# 11) myFunct([1, 2, 3; 3, 5, 1; 5, 6, -1], [3, -1, 4; -3, 5, 1; -5, 6, -1])= −40 62 8
−26 48 14 ]
# 12) No need because the function is already stored into memory as long as the console is not
closed after executing the SciNotes file.
4 Conclusion
I learned that SciLab works similarly to Python as I also learned programming with it and also preferred
to use the built-in IDLE. The console works as the IDLE, allowing you to quickly solve problems with it.
The SciNotes works as if you create a Python file by using Ctrl+N, allowing you to create functions or a
collection of commands to execute at once in SciLab Console.
I learned about how powerful the SciLab is from using it to solve basic arithmetic, to storing various
kinds of data, to even create functions that satisfy the root values. It is also powerful in operating with
matrices, making an awesome program.