Scilab Basics - Control Systems For Maritime Professionals Book - 1 by Kalyan Chatterjea
Scilab Basics - Control Systems For Maritime Professionals Book - 1 by Kalyan Chatterjea
5. Transfer Functions
9. Maritime Examples
The series ‘Control Systems for Maritime Professionals’ is divided into ten
parts. Each part is published as an individual book. Each part has several
Sections and these Sections have measurable learning objectives, which are
outlined at the beginning of each Section. A companion website (Companion
Website for Competency Monitoring) is created for formative learning of the
content in the books.
IV Acknowledgment
I am thankful to the open-source communities, without which this series of
books will not be possible. This Book-I of the series is developed using open-
source software exclusively. I acknowledge using the following software:
LibreOffice
Sigil
Calibre
Scilab
Various Linux Distributions - Peppermint Linux, Ubuntu, Linux
Mint, MX Linux
Gimp
Inkscape
Zotero
Dropbox
Bluefish
htmlTidy
Grammarly
Google
The main inspirations for the book came after reading "Introduction to Scilab
- Application to Feedback Control", 2014, by Yassin Ariba of Brno
University of Technology, and "Feedback Control with Scilab and Arduino",
2016, by Varodom Toochinda of Kasetsart University. I am deeply indebted
to them. These two references serve as the main resources for this
publication.
Kalyan Chatterjea
Singapore
May 2020
V Table of Contents
I. Title Page
II. Series Contents
III. Series Introduction
IV. Acknowledgment
V. Table of Contents
VI. List of Figures
VII. Bibliography
VIII Index
IX. Other Books by Author
X. About the Author
V List of Figures
Fig. 4.1 Scilab environment
Fig. 14.1 SciNotes Ikon to start the Scilab’s embedded text editor
Fig. 24.3 Control system seen from time and frequency domains
Finally, the book is also for anyone interested to get a head-start in Scilab,
which has so many applications in science and engineering.
Once the file is written, one needs to provide permission to use the file using
the following code in the terminal.
Bash Program
#!/bin/bash
cd
cd /home/kalyansg
cd scilab
cd bin
./scilab
For a MS Windows 10 installation, download the exe file and run the exe file
and follow the prompts. It will end up with a starting icon. The program can
be easily started by double-clicking the starting icon.
For Apple Mac users, follow these steps below:
File Browser: Set up your default data site for storing Scilab files. Go to
Scilab Preferences, choose under General>Start-up directory>Use default
directory (shown in the picture below).
Figure 4.2 Scilab preferences
Variable Browser: It lists the variables used and details their names, values,
type, and visibility. Any change in the values is also updated.
--> A=10
A=
10.
--> b="Trial"
b=
Trial
--> B=25
B=
25.
--> C=A+B
C=
35.
--> K=[2 3 4;6 7 8;9 1 4]
K=
2. 3. 4.
6. 7. 8.
9. 1. 4.
News Feed: It displays news about Scilab products and activities to keep the
users updated.
5 Scilab as a Simple Calculator
Scilab can work as a
By the end of this Section, you will be able simple calculator and it
to… can also be used to
define variables and
1. Undertake arithmetic operation in the
store values in them for
'Scilab Console'.
subsequent
2. Evaluate trigonometric functions in Scilab calculations. This is
interactive mode. shown in the following
3. Assign variables with specified values. Scilab examples.
(Ariba, “Introduction
4. Carry out logical operations in Scilab to Scilab.”)
interactive mode.
--> 4+4
ans =
8.
--> 25*4
ans =
100.
--> a=12;b=3;
--> c=a*b;
--> disp(c) // ’disp’ is command for ‘display’ the variable value
36.
--> d=%pi/3;//Here %pi is 3.14159265 (π)
--> disp(d)
1.0471976
--> a=12;
--> b=sqrt(a) // ’sqrt’ is the command for ‘square root’
3.4641016
--> b=a^2; // 'b' is redefined
--> disp(b)
144.
--> disp (sqrt(b))
12.
Elementary Operators
+ addition
- subtraction
* multiplication
/ right division
\ left division
^ exponent
Scilab Implementation:
--> a=10
a =
10.
--> b=2
b =
2.
--> a+b
ans =
12.
--> a-b
ans =
8.
--> a/b
ans =
5.
--> a\b
ans =
0.2
--> a^b
ans =
100.
--> b/a
ans =
0.2
Note: All follow normal rules of arithmetic except the left division, where a\b
= b/a
Logical Operators
Scilab
Built-in Description
Constants
%s Polynomials=poly(0,'s')
%z Polynomials=poly(0,'z')
6 Matrix Operation Using Scilab
Matrices are
By the end of this Section, you will be able rectangular grids,
to… frequently used in
science and
1. Enter a matrix in Scilab.
engineering for
2. Edit a matrix in Scilab. representing
3. Create arrays in Scilab. mathematical
equations. Matrices are
4. Describe characteristics of also used for storing
matrices/arrays/vectors in Scilab. and manipulation of
various types of data.
Complicated calculations can be solved through the manipulation of matrices.
(Hardesty 2013)
Matrices, a great tool from linear algebra, are increasingly used to analyse
control systems. This text will cover all the basics of matrix operations using
Scilab, which simplifies these calculations.
A matrix can be entered in Scilab 6.1.0 in several ways as shown below in the
three examples:
--> A = [10 4 20 5 // Type the first line then press Enter
> 3 4 7 10 // Type the second line then press Enter matrix
> 5 1 6 1] // Type the last line with a closing bracket at the end
A =
10. 4. 20. 5.
3. 4. 7. 10.
5. 1. 6. 1.
3. 4. 5.
7. 8. 9.
3. 2. 1.
--> C = [7 2 4;3 2 10] // Type the entire matrix in one line using gap &
semi colon
C =
7. 2. 4.
3. 2. 10.
Once a variable is defined, it can be edited as shown below with the variable
A: (SHASHIKANT, “Editing Vectors and Matrices in Scilab – x-
Engineer.Org.”)
10. 4. 20. 5.
3. 4. 7. 10.
5. 1. 6. 1.
10. 4. 20. 5.
3. 4. 7. 10.
5. 1. 6. 75.
Figure 6.2 Editing element values using editvar command A34 changed from
75 to 60
--> A
A =
10. 4. 20. 5.
3. 4. 7. 10.
5. 1. 6. 60.
--> A = [1 4 7 8
>3289
> 2 5 1 1]
A =
1. 4. 7. 8.
3. 2. 8. 9.
2. 5. 1. 1.
--> B = [7 3 2 1
>5632
> 1 2 9 2]
B =
7. 3. 2. 1.
5. 6. 3. 2.
1. 2. 9. 2.
--> C=A+B
C =
8. 7. 9. 9.
8. 8. 11. 11.
3. 7. 10. 3.
--> D=A-B
D =
-6. 1. 5. 7.
-2. -4. 5. 7.
1. 3. -8. -1.
8 Matrices – Multiplication
Assuming the
By the end of this Section, you will be able following two matrices
to… are to be multiplied.
1. Multiply two matrices in Scilab.
2. State the rules of matrix-multiplication.
where,
a = (first row * first column)
= (3*6 + 4*1 + 7*6) = 64
b = (first row * second column)
= (3*2 + 4*5 + 7*4) = 54
c = (second row * first column)
= (2*6 + 3*1 + 1*6) = 21
d = (second row * second column)
= (2*2 + 3*5 + 1*4) = 23
--> A = [3 4 7
> 2 3 1] // entering the first matrix into Scilab
A =
3. 4. 7.
2. 3. 1.
--> B =[6 2
>15
> 6 4] // entering the second matrix into Scilab
B =
6. 2.
1. 5.
6. 4.
--> C=A*B // multiplying the two matrices in Scilab - it matches the
manual results shown above.
C =
64. 54.
21. 23.
Extending the above problem with the following two matrices - the second
matrix is modified by adding row [8 1].
--> A = [3 4 7
> 2 3 1] // entering the first matrix into Scilab
A =
3. 4. 7.
2. 3. 1.
--> B = [6 2
>15
>64
> 8 1] // entering the second matrix into Scilab
B =
6. 2.
1. 5.
6. 4.
8. 1.
--> C = A*B // trying to multiply the two matrices in Scilab
Inconsistent row/column dimensions.
One can generate an identity matrix using the ‘eye’ command in Scilab.
--> I=eye(4,4)
I =
1. 0. 0. 0.
0. 1. 0. 0.
0. 0. 1. 0.
0. 0. 0. 1.
--> I = eye(3,3)
I =
1. 0. 0.
0. 1. 0.
0. 0. 1.
10 Solve Linear Equations by Matrices
With the basic
By the end of this Section, you will be able knowledge of Scilab,
to… detailed in the previous
sections, it will be
1. Represent linear equations in a matrix
possible to solve linear
format.
equations. Assuming
2. State X = A-1 .B as the solution in the the following three
matrix format for a set of linear equations. equations are given,
3. Solve linear equations in Scilab.
7x+5y-3z = 16 (1)
3x-5y+2z = -8 (2)
5x+3y-7z = 0 (3)
7x+5y-3z = 16 (1)
3x-5y+2z = -8 (2)
5x+3y-7z = 0 (3)
Rewriting in the format of the 3 equations,
Or, A.X = B
To eliminate A, multiplying both sides by A-1
Or, A-1.A.X = A-1 .B [But A-1.A = I]
Or, I.X = A-1 .B [But I.X = X]
Or, X = A-1 .B [This is the final solution]
There are four unknowns in the following set of linear equations. Four
unknowns are to be solved using Scilab.
3w + 5x - 3y - 2z = 34
- 2w + 2x + 6y + 3z = 2
w + 4x + 2y - z = 31
6w + x + y + z = 7
(w, x, y, z) = (_, _, _, _)
--> A=[3 5 -3 -2
> -2 2 6 3
> 1 4 2 -1
> 6 1 1 1]
A =
3. 5. -3. -2.
-2. 2. 6. 3.
1. 4. 2. -1.
6. 1. 1. 1.
--> B=[34;2;31;7]
B =
34.
2.
31.
7.
--> C=inv(A)
C =
-0.0461538 -0.0666667 0.0512821 0.1589744
0.2076923 0.1333333 -0.0641026 -0.0487179
-0.2384615 -0.0666667 0.3205128 0.0435897
0.3076923 0.3333333 -0.5641026 0.0512821
--> X=C*B
X =
1.
5.
2.
-6.
Assume a matrix A =
2 4 6 8
3 7 9 3
8 9 7 1
Transpose of A = A’ =
2 3 8
4 7 9
6 9 7
8 3 1
--> A = [ 2 4 6 8
>3793
> 8 9 7 1]
A =
2. 4. 6. 8.
3. 7. 9. 3.
8. 9. 7. 1.
--> B=A'
B =
2. 3. 8.
4. 7. 9.
6. 9. 7.
8. 3. 1.
12 Determinant of Matrix
Determinants of
By the end of this Section, you will be able matrices are useful in
to… solving a system of
linear equations. It
1. Evaluate the determinant of a matrix
applies to only square
using Scilab.
matrices. For a square
2. State the type of matrix for which matrix A it’s
determinant could be found. determinant is denoted
3. Calculate the determinant of a 2x2 matrix by ∣A∣
manually.
In Scilab,
--> A=[5 4
> 3 6]
A =
5. 4.
3. 6.
--> B=det(A)
B =
18.
The top part of the above figure shows which elements to be avoided by
struck-out lines.
A numerical example:
In Scilab:
--> A=[1 4 3
>721
> 5 8 3]
A =
1. 4. 3.
7. 2. 1.
5. 8. 3.
--> B=det(A)
B =
72.
13 Eigenvalues and Eigenvectors
This topic will be
By the end of this Section, you will be able useful in the state-
to… space form of analysis
(a state-space
1. State that if a system has a strictly real
representation is a
eigenvalue, the system will either
mathematical model of
exponentially decrease or increase in the
a physical system as a
corresponding eigenvector direction.
set of input, output, and
2. State that if a system has a pair of state variables related
complex conjugate eigenvalues, the system by first-order
will oscillate around the directions given by differential equations.
the corresponding eigenvectors while either “Wikipedia - State-
exponentially decreasing towards the origin, Space
or increasing away from it according to the Representation”),
signal of the eigenvalues real part. especially, while
3. State that det(A−λI) = |A−λI| = 0 is called dealing with the
the characteristic equation of the matrix A stability of a system.
Eigenvalues are
4. Evaluate eigenvalues and eigenvectors related to poles of the
using Scilab. system, which deal
with stability. Each
pole of a system (In Transfer Function form), is an eigenvalue of the relevant
matrix (In State-Space form). Eigenvalues with negative real parts indicate
that poles of the system are in the left half-plane and are stable. The topic
will be covered in greater detail under the state-space and stability topics. The
underlying discussion can be revisited prior to covering these topics. Link
here refers to a good discussion on the topic. (“What Is the Intuition of
Eigenvector and Eigenvalue from a Control System Perspective?” - Forum
Post)
13.1 Example
Or,
Or,
Or,
Or,
Or,
Or,
Hence, there are three eigenvalues for the given 3 x 3 matrix 1, 4 & - 0.5
--> A=[1 0 0
> 0 2 2.5
> 0 2 1.5]
A =
1. 0. 0.
0. 2. 2.5
0. 2. 1.5
--> spec(A)// outputs the eigenvalues
ans =
-0.5 + 0.i
4. + 0.i
1. + 0.i
To find the corresponding eigenvector for, say, when the eigenvalue is 4, the
expressions are written in the matrix form.
Or,
Or,
Or,
This section deals with the working of the SciNotes, which can be started
clicking the SciNotes ikon shown below.
Figure 14.1 SciNotes Ikon to start the Scilab’s embedded text editor
After saving the execution button ⊳ in SciNotes would execute the saved
program. Alternatively, the save-execute button (shown above in figure
14.2) can be used, which saves the file first and subsequently executes the
program in the Console.
Startup execution:
loading initial environment
"Kalyan"
However, the output is not formatted and the name comes in the second line,
which is not ideal.
The code could be improved with the following modification using a '+'
operator:
Console Output:
"Your name is Sam, your age is 26 and you are from Singapore"
Console output:
--> type(B)
ans =
10.
'10' refers to variable type 'string'. The code is modified with default variable
type without specifying string:
Console output:
Enter a number: 20
Enter another number: 30
--> type(A)
ans =
1.
--> type(B)
ans =
1.
'1' refers to variable type 'real'.
--> typeof(A)
ans =
"string"
--> typeof(A)
ans =
"constant"
Here %i stands for integer (first for 'a' and then for 'b') and %f stands for float
(h). \n transfers the output to a new line.
There are two under-mentioned mandatory fields needed for the function
'mprintf' to work. The other fields, in square brackets [ ] above, are optional.
1. percent sign (%): this informs the function that a formatting sequence
begins
2. specifier: this describes what type of data will be displayed
SciNotes Code:
Console Output:
SciNotes Code:
0001 i=1
0002 a= input("Enter length of side-one in cm: ")
0003 b= input("Enter length of side-two in cm: ")
0004
0005 disp('SIDE-1, SIDE-2 & HYPOTENUSE OF A RIGHT-ANGLE
TRIAGE')
0006
0007 for i=1:5 // for-end loop: index i between 1 & 5 incrementing by
+1 in every loop
0008 c(i)=a
0009 d(i)=b
0010
0011 h1=sqrt(a^2 + b^2)
0012 h(i)=h1
0013
0014 disp('Side_1='+string (a)+'cm '+ 'Side_2='+string (b)+'cm
'+'Hypotenuse= '+string (h(i))+'cm')
0015
0016 a=a+1//incrementing by +1
0017 b=b+1//incrementing by +1
0018 end
Console Output:
exec('/home/kalyansg/Dropbox/scilab-data/User-Input-008.sce', -1)
Enter length of side-one in cm: 3
SciNotes Code:
0001 i=1
0002 a= input("Enter length of side-one in cm: ")
0003 b= input("Enter length of side-two in cm: ")
0004
0005 mprintf('\nSide-1\tSide-2\tHypoteneuse\n')
0006 mprintf('[cm]\t[cm]\t[cm]\n')
0007
0008 for i=1:5 // for-end loop: index i between 1 & 5 incrementing by
+1 in every loop
0009 c(i)=a
0010 d(i)=b
0011
0012 h1=sqrt(a^2 + b^2)
0013 h(i)=h10014
0015 mprintf('%d \t %d\t%.2f\n',c(i),d(i),h(i))
0016
0017 a=a+1//incrementing by +1
0018 b=b+1//incrementing by +1
0019 end
Else
Task(s) for if-condition False
End
SciNotes Code:
Console Output:
Enter a number: 10
Enter a string e.g E,F, etc: E
"A is constant"
"B is string"
"A is of course a CONSTANT"
"B is of course a STRING"
SciNotes Code:
0001 clear
0002 clc
0003
0004 A = input('Please enter a number either 40 or 50 or some other
number: ', "string")//It is better to get the input as a string
0005 A=strtod(A)//conversion of string to a number
0006
0007 if (A == 40) then disp("The number is forty")
0008
0009 elseif (A == 50) then disp("The number is fifty")
0010
0011 else disp("The number is neither forty nor fifty") 0012
end
Console Output:
SciNotes Code:
Console Output:
exec('/home/kalyansg/Dropbox/scilab-data/User-Input-010.sce', -1)
1.
2.
3.
4.
5.
1.
1.5
2.
2.5
3.
3.5
4.
4.5
5.
Two sets of values of output for two indexes i & k - 1 to 5 with increment 1
& 1 to 5 with increment 0.5
Here, the inner loop [referring to the diagram - condition II - for_end loop 2]
does 2 tasks, which is repeated a number of times depending on the
requirements.
Assuming these repeated tasks are required for three different cases - done
by the outer loop 3 times [referring to the diagram - condition I - for_end
loop 1] .
SciNotes Code:
Console Output:
x-value y-value
1 0.667
1 0.833
1 1.000
1 1.167
1 1.333
1 1.500
1 1.667
2 0.667
2 0.833
2 1.000
2 1.167
2 1.333
2 1.500
2 1.667
3 0.667
3 0.833
3 1.000
3 1.167
3 1.333
3 1.500
3 1.667
Inside a for-loop, the command break forces the end of the loop. This
command may be required, as an example, while going through an array of
numbers, it is required to find when the array element exceeds a specified
value. This is shown in the following example.
SciNotes Code:
Console Output:
Console Output:
0.1
0.2
0.3
18 While Loop
SciNotes Code:
Console Output:
2.
5.4142136
10.732051
18.
27.236068
SciNotes Code:
10.456789
10.457
2.
5.41
10.73
18.
27.24
SciNotes Code:
Console Output:
8.
32.
72.
128.
"index i = 4"
The program breaks the while-loop when it reaches the given 'if-condition'.
19 Select Case Conditional Statements
While choosing from a
By the end of this Section, you will be able list of options, select-
to… case is considered a
better structure.
1. Write executable codes using select-case
(“SELECT CASE
conditional statements.
Conditional Statements
– x-Engineer.Org.”)
SciNotes Code:
0001 clear
0002 clc
0003 month = 0;
0004
0005 while (month<1 | month>6) //Limits of entry set between minimum
- 1 and maximum - 6
0006
0007 month = input('Please choose your option between 1 and 6: ',
"string")//It is better to get the user input as a string
0008 month=strtod(month)//conversion of string to a number
0009 if (isnan(month)) then month = 0;end//nan-not a number,
isnan checks if the month is a nan, if it is a nan then month is allocated a
value of 0
0010 end
0011
0012 select month
0013 case 1
0014 disp("Month is January")
0015 case 2
0016 disp("Month is February")
0017 case 3
0018 disp("Month is March")
0019 case 4
0020 disp("Month is April")
0021 case 5
0022 disp("Month is May")
0023 case 6
0024 disp("Month is June")
0025 else
0026 disp("Wrong Month number")
0027
0028 end
0029
0030 disp("Your selected month number is: "+ string (month))
Lines 0005 to 0009 shows the codes for user-input and user-input-validation.
This is an important routine, which could be used while getting a numerical
input from a user. The routine takes care of user-input errors.
Console Output:
SciNotes Code:
--> exec('SingleNumberInput.sci');
--> [r]=SingleNumberInput(10,15)
Choose your option between 10, and 15
Enter your option: 89
89.
Choose your option between 10, and 15
Enter your option: 9
9.
Choose your option between 10, and 15
Enter your option: 10
10.
r =
10.
SciNotes Code:
--> exec('SinePlot.sci');
--> SinePlot(0,0.1,15)
The arguments e1, e2, ... are input variables, while s1, s2, ... are the output
variables. 'text' would be character strings.
Assuming, there is a function ax^2 +bx + c, the following code shows the
online function definition. This is the case for multiple inputs and multiple
outputs.
--> deff('[x1,x2]=quadratic(a,b,c)',['m=sqrt(b^2-4*a*c)';'n1=(-
b+m)/(2*a)';'n2=(-b-m)/(2*a)';'x1=n1';'x2=n2'])
Screen Output: Shown for two cases with real and imaginary outputs.
--> [x1,x2]=quadratic(1,-7,12)
x1 =
4.
x2 =
3.
--> [x1,x2]=quadratic(4,3,6)
x1 =
-0.375 + 1.1659224i
x2 =
-0.375 - 1.1659224i
Checking which variables are stored after the operation, the following results
are found:
--> m
Undefined variable: m
--> n1
Undefined variable: n1
--> n2
Undefined variable: n2
--> a
Undefined variable: a
--> x1
x1 =
4.
--> x2
x2 =
3.
It checks out with variable browser report, shown below:
So, only variables stored in the system are the output variables x1 & x2.
Others are all internal variables of the function and these variables can be
reused later in the program.
For a single input and a single output, the code will be as shown in the
following example:
--> deff('y=f(x)','y=5*x+3')
Screen Output:
--> f(3)
ans =
18.
For a multiple input and a single output, the code will be as shown in the
following example:
--> deff('y=myfct(a,b)','y=a*b^2')
Screen Output:
--> myfct(3,4)
ans =
48.
A B
1 0
2 20
3 38
4 55
5 66
6 67
7 57
8 40
9 21
10 -5
SciNotes Code:
Console Output:
--> exec('/home/kalyansg/Dropbox/scilab-data/Plot-from-Array-01.sce',
-1)
1. 0.
2. 20.
3. 38.
4. 55.
5. 66.
6. 67.
7. 57.
8. 40.
9. 21.
10. -5.
By the end of this Section, you will be able Scilab has the two
to… following in-built
functions for x-y
1. Plot 2d graphs using both 'plot2d' and
plotting: (“Polyline
'plot' commands.
Properties -
2. Use polyline properties in the plots. Description of the
3. Provide 'titles', 'axes', 'legends' and control Polyline Entity
their fonts and use 'LaTeX' to write Properties.”)
equations.
4. Draw multiple plots in one window using
'subplot' command.
plot2d
plot
plot2d ([logflag,][x,],y[,style[,strf[,leg[,rect[,nax]]]]])
Optional Arguments:
style - It sets the line type. Positive integers are for continuous line (e.g 1-
black & 5-red). The negative integers are for the given curve points drawn
using marks as per the mark_style property given below.
strf - It is a string of length 3 "xyz" (by default strf= "081")
x=0
no caption.
x=1
captions are displayed. They are given by the optional argument leg.
y=0
no computation, the plot use the previous (or default) scale
y=1
from the rect arg
y=2
from the min/max of the x, y data
y=3
built for an isometric scale from the rect arg
y=4
built for an isometric plot from the min/max of the x, y data
y=5
enlarged for pretty axes from the rect arg
y=6
enlarged for pretty axes from the min/max of the x, y data
y=7
like y=1 but the previous plot(s) are redrawn to use the new scale
y=8
like y=2 but the previous plot(s) are redrawn to use the new scale
z - controls the display of information on the frame around the plot. If axes
are requested, the number of tics can be specified by the nax optional
argument.
z=0
nothing is drawn around the plot.
z=1
axes are drawn, the y=axis is displayed on the left.
z=2
the plot is surrounded by a box without tics.
z=3
axes are drawn, the y=axis is displayed on the right.
z=4
axes are drawn centred in the middle of the frame box.
z=5
axes are drawn so as to cross at point (0,0). If point (0,0) does not lie
inside the frame, axes will not appear on the graph.
leg - This option may be used to sets the curve captions. It must be a string
with the form "leg1@leg2@...." where leg1 , leg2 , etc. are respectively the
captions of the first curve, of the second curve, etc. The default is " ".
rect - This option may be used to set the minimal bounds requested for the
plot. If this option is specified, the associated value should be a real vector
with four entries: [xmin,ymin,xmax,ymax]. xmin and xmax defines the
bounds on the abscissae while ymin and ymax defines the bounds on the
ordinates.
nax - This option may be used to specify the axes labels and tics definition.
The associated value should be a real vector with four integer entries
[nx,Nx,ny,Ny]. Nx gives the number of main tics to be used on the x-axis (to
use autoticks set it to -1), nx gives the number of subtics to be drawn between
two main x-axis tics. Ny and ny give similar information for the y-axis. If
axesflag option is not set nax option supposes that axesflag option has been
set to 9.
As the above are optional arguments, all of them need not be selected. The
following example shows a simplified selection.
SciNotes Code:
clear;//kills variables
y1 = M*sin(t);//define y1 in terms of t
y2 = N*sin(t);//define y2 in terms of t
plot2d (t,y1,style=-6, rect=[0,-6,10,6]);//plot t-y,style, define area
coordinates
plot2d (t,y2, style=5);
xgrid(2);//style;
xtitle("t-y Plot for 5sint & 3sint", "t Axis", "y Axis");//title, x-axis, y-axis
legend ("y1=5sint","y2=3sint",[4]);//legend for y1,y2,[legend location
options - 1/2/3/4]
clear;//kills variables
Linspace - linearly spaced vector - minimum, maximum & divisions (x1, x2,
d) - bigger the value of d smoother will be the graph. Default value of d is
100.
SciNotes Code:
SciNotes Code:
'plot' Command
The next example shows the printing of two 2-d graphs and the use of
'handle' to enhance a presentation. (“gcf - Return Handle of Current Graphic
Window.”)
SciNotes Code:
For example, for two plots in one window, the first plot (on the left) will have
the command 'subplot(1,2,1)' and the second plot (on the right) will have the
command 'subplot(1,2,2)'. An example, showing the application is given
below.
SciNotes Code:
The next example shows six plots in a single window and is modified
from a stackoverflow aricle.
Some of the attributes of the four figures were changed to show how these
could be altered with relevant codes.
SciNotes Code:
0001 clf()
0002 figure;
0003 rand(10); // Seed for Random Number Generator
0004 subplot(2,3,1);
0005 x = rand(100,1);
0006 y = rand(100,1);
0007 plot(x,y,'b.');
0008 title('First plot','fontsize',4);
0009 subplot(2,3,2);
0010 x = rand(100,1);
0011 y = rand(100,1);
0012 plot(x,y,'r.');
0013 title('Second plot');
0014 a=get("current_axes")//get the handle of the newly created axes
0015 a.axes_visible="on"; // makes the axes visible
0016 a.font_size=3; //set the tics label font size
0017
0018 subplot(2,3,3);
0019 x = rand(100,1);
0020 y = rand(100,1);
0021 plot(x,y,'b.');
0022 title('Third plot','fontsize',4);
0023 subplot(2,3,4);
0024 x = rand(100,1);
0025 y = rand(100,1);
0026 plot(x,y,'g.');
0027 title('Fourth plot');
0028 subplot(2,3,5);
0029 x = rand(100,1);
0030 y = rand(100,1);
0031 plot(x,y,'b.');
0032 title('Fifth plot','fontsize',4);
0033 subplot(2,3,6);
0034 x = rand(100,1);
0035 y = rand(100,1);
0036 plot(x,y,'y.');
0037 title('Sixth plot');
SciNotes Code:
It is probably a good idea to write out the detailed objectives for the exercise
before writing codes to ensure that all aspects are taken care of during coding.
Task 1 - Prepare the spreadsheet file - While importing data into Scilab
only numerical values will be accepted. So, rows and columns with
strings (for example header rows and leftmost column with descriptions)
should be deleted. The file should also be saved in csv text-file format.
The file should then be brought into the working directory of Scilab.
Task 2 - Ask user for the 'csv' filename - Prompt user for the filename.
Read user-input as a string. Show the filename on the screen to get
confirmation from the user. If there is an error, go through the process
again. Read confirmed user-input and assign it to a variable. A flowchart
for the task is shown below and the code for this task is saved as a
function 'FileName.sci'.
Figure 23.1 FileName flowchart
SciNotes Code:
function [a]=FileName()
i=1;
while (i>0)
a=input('Enter the filename: ',"string");
disp(a);
n=input('Confirm filename Y/N: ',"string");
if n=="Y" then i=0;end
if n=="N" then disp ('Re-enter');i=1;end
end
disp('So,the filename is '+ string (a));
endfunction
Screen Output:
--> exec('/home/kalyansg/Dropbox/scilab-data/Graph-Drawing-
Application/FileName.sci', -1)
--> [a]=FileName()
Enter the filename: test
"test"
Confirm filename Y/N: N
"Re-enter"
Enter the filename: test
"test"
Confirm filename Y/N: Y
"So,the filename is test"
a =
"test"
After this, the following command could be used to check if the file is
actually available at the working directory.
[fd,err]=mopen(a)
fd = 1. err = 0.
If the err=-2 then the file is not there and the program should stop and
user should be asked to recheck the name & location of the file.
Task 4 - Read csv-file as a matrix - Read the csv-file and assign a
variable to capture the data (as data type - double). Screen output is
shown below with the dummy data (10 rows x 6 columns), which is in
test.csv. Row and column sizes of the matrix are also ascertained at the
same time using the 'size' command.
--> a='test.csv'
a =
"test.csv"
--> exec('/home/kalyansg/Dropbox/scilab-data/Graph-Drawing-
Application/csv_FileOpen.sci', -1)
--> [b]=csv_FileOpen(a)
b =
--> [row,column]=size(b)
row =
10.
column =
6.
While presenting the matrix dat to user, there is a need to create index
column (while selecting row) and index row (while selecting column).
This is done using the following codes:
function [ ]=DisplayRow_Index()
a=[0+1:row]
dsi=a' //dsi-Display Row Index
//disp(dsi)
dsi_tb=[dsi,b]//dsi_tb - Display Row Index Table
disp(dsi_tb)
endfunction
function [ ]=DisplayColumn_Index()
a=[0+1:column]
dsi=a //dsi-Display Column Index
//disp(dsi)
dsi_tb=[dsi;b]//dsi_tb - Display Column Index Table
disp(dsi_tb)
endfunction
5.
307. 319. 330. 320. 320. 330.
Task 5 - Ask the user to choose an option for the graph - The following
options are to be presented:
a. singe row
b. single column
c. multi-row
d. multi-column
e. row vs column (for square matrix - not to be included in the
text)
f. column vs row (for square matrix - not to be included in the
text)
SciNotes Code:
function [op,c]=GraphOption()
op = 0;
while (op<1 | op>6)
disp(op,c);
n=input('Confirm Option Y/N: ',"string");
if n=="Y" then end
if n=="N" then disp ('Re-enter');op=0;end
end//end while
endfunction
Screen Output:
--> exec('GraphOption.sci');
--> [op,c]=GraphOption()
Task 6 - Select Case to do the plotting - This is the final step of the
application, where the actual plotting is done with some interaction with
users. Select Case command is used to go through the six options,
defined earlier.
select op
case 1 then
File Save: A routine should be done to save the file. Before that the user
should be given an option for the file name. The following function-
object is created for this purpose.
SciNotes Code:
function [fs]=FileSave()
i=1;
while (i<>0)
fs=input('Enter the filename [e.g. Plot-01.png] for saving
your plot: ',"string");
disp(fs);
if (isfile(fs)) then disp("Filename already there in working
directory: Overwrite - Y New name - N");end
n=input('Confirm filename Y/N: ',"string");
if n=="Y" | n=="y" then i=0;end
if n=="N" | n=="n" then disp ('Re-enter');i=1;end
end
endfunction
//File-saving routine
exec('FileSave.sci');
[fs]=FileSave();
xs2png(0,fs);//saving plot with the user-given filename saved with
variable fs
//format - xs2png(win_num, file_name)...win_num - an
integer, ID of the figure to export.
mprintf('Plot saved as %s',fs)
Screen Output:
--> exec('/home/kalyansg/Dropbox/scilab-data/Graph-Drawing-
Application/2dPlot-SlectCase.sci', -1)
Enter Row Number for your Graph
Choose your option between 0,and 10
Enter your option: 4
4.
309. 320. 324. 319. 336. 318.
Enter your text for Title
Enter your text: Plot of Row-4
"Plot of Row-4"
Confirm text Y/N: y
Enter your text for X-Axis
Enter your text: X-Axis
"X-Axis"
Confirm text Y/N: y
Enter your text for Y-Axis
Enter your text: Y-Axis
"Y-Axis"
Confirm text Y/N: y
Enter your text for Legends
Enter your text: Row-4
"Row-4"
Confirm text Y/N: y
Enter the filename [e.g. Plot-01.png] for saving your plot: aa.png
"aa.png"
Confirm filename Y/N: y
Plot saved as aa.png
Figure 23.5 Polyline property and thickness changed
The following code shows the completed code for polyline control for the
above figure (Fig. 23.5). The relevant code lines are boldened.
select op
case 1 then
xtitle([txt_title],[x_axis],[y_axis])
l1=legend([l],5)
fz.font_size=4 // Using the handle axis fontsize is increased
fz.x_label.font_size=4 // Using the handle x-label fontsize is
increased
fz.y_label.font_size=4
fz.title.font_size=6
l1.font_size=4//Legend font-size set to 4 (between 1 to 10)
//File-saving routine
exec('FileSave.sci');
[fs]=FileSave();
xs2png(0,fs);//saving plot with the user-given filename saved with
variable fs
//format - xs2png(win_num, file_name)...win_num - an
integer, ID of the figure to export.
mprintf('Plot saved as %s',fs)
The above code is used for the 'select-case-1', which is for plotting a
particular row of a matrix. When it comes to 'select-case-2', which is for
plotting a particular column, the code should be the same except that the
selection should be for columns, and the limit for the x-axis will also change.
The relevant codes are shown below:
Scilab Code:
case 2 then
mprintf('Enter Column Number for your Graph\n')
[z]=SingleNumberInput(0, column);//A function within function
x = linspace (0,row,row);//x-min, x-max, divisions
y = b(:,z)//for column selection
disp(y);
clf();
plot2d(x,y)
//xgrid(6)
fz=gca() // This routine returns the handle of the current axes for
the current figure.
fx=gcf();
fz.thickness=1.5 // Using the handle all line-thicknesses are
increased
fz.grid=[1 1]
tmp=fz.x_ticks
tmp.locations=[0:row]
tmp.labels=string(tmp.locations);
fz.x_ticks=tmp;
fx.children.children(1).children.line_style = 4;
fx.children.children(1).children.thickness = 4;
xtitle([txt_title],[x_axis],[y_axis])
l1=legend([l],5)
fz.font_size=4 // Using the handle axis fontsize is increased
fz.x_label.font_size=4 // Using the handle x-label fontsize is
increased
fz.y_label.font_size=4
fz.title.font_size=6
l1.font_size=4//Legend font-size set to 4 (between 1 to 10)
//File-saving routine
exec('FileSave.sci');
[fs]=FileSave();
xs2png(0,fs);//saving plot with the user-given filename saved with
variable fs
//format - xs2png(win_num, file_name)...win_num
- an integer, ID of the figure to export.
mprintf('Plot saved as %s',fs)
For 'select-case-3', which is for multi-row plotting, the code would quite
different. The input from the user has to capture an unknown number of
inputs. So, a row vector is used for user-input. The relevant code is shown
below:
Scilab Code:
i=1;
while (i<>0)
rs=input('Enter rows for plotting, e.g. [3,4,7] for Row-3,
Row-4 & Row-7 Your Choice: ')
disp(rs);
n=input('Confirm text Y/N: ',"string");
if n=="Y" | n=="y" then i=0;end
if n=="N" | n=="n" then disp ('Re-enter');i=1;end
end
For 'select-case-4', which is for multi-column plotting, the code would very
similar to case-3. Case-5 and case-6 are not covered in the text. These cases
are exclusively for square matrix, where the number of rows equal the
number of columns. These are left as exercises for the reader.
001 clc
002 clearglobal();
003 clear();
004 clf();
004 close;
005
006 mprintf('\n\n ==== Matrix 2D Plot Utility Version 0.4
====\n\nEnter matrix filename to start.\n')
007
008 exec('SingleNumberInput.sci');
009 exec('FileName.sci');
010
011 [a]=FileName();
012 exec('csv_FileOpen.sci');
013 [b]=csv_FileOpen(a);
014 [row,column]=size(b);
015 i=0;
016 exec('GraphOption.sci');
017 [op,c]=GraphOption();
018
019
020 select op
021 case 1 then
022 exec('DisplayRow_Index.sci');
023 DisplayRow_Index();
024 mprintf('\n Enter Row Number for your Graph\n\n')
025 [z]=SingleNumberInput(0, row);//A function within function
026 x = linspace (1,column,column);//x-min, x-max, divisions
027
028 y = b(z,:)//for row selection
029 disp(y);
030 clf();
031 plot2d(x,y,5)
032 //xgrid(6)
033 fz=gca() // This routine returns the handle of the current axes
for the current figure.
034 fx=gcf();
035 fz.thickness=1.5 // Using the handle all line-thicknesses are
increased
036 fz.grid=[1 1]
037 tmp=fz.x_ticks
038 tmp.locations=[0:column]
039 tmp.labels=string(tmp.locations);
040 fz.x_ticks=tmp;
041 fx.children.children(1).children.line_style = 5;
042 fx.children.children(1).children.thickness = 4;
043
044 //Text Input for Title
045 mprintf('Enter your text for Title\n')
046 exec('TextInput.sci');
047 [txt_title]=TextInput()
048 if isempty(txt_title)
049 row_number=string(z)
050 plot_title='Plot for Row-'+row_number
051 txt_title=plot_title//default title
052 end
053
054 //Text Input for X-Axis
055 mprintf('Enter your text for X-Axis\n')
056 [x_axis]=TextInput()
057 if isempty(x_axis)
058 x_axis="X-Axis"
059 end
060
061 //Text Input for Y-Axis
062 mprintf('Enter your text for Y-Axis\n')
063 [y_axis]=TextInput()
064 if isempty(y_axis)
065 y_axis="Y-Axis"
066 end
067
068 //Text Input for Legend
069 mprintf('Enter your text for Legends\n')
070 [l]=TextInput()
071 if isempty(l)
072 default_legend='Row-'+row_number
073 l=default_legend
074 end
075
076 xtitle([txt_title],[x_axis],[y_axis])
077 l1=legend([l],5)
078 fz.font_size=4 // Using the handle axis fontsize is increased
079 fz.x_label.font_size=4 // Using the handle x-label fontsize is
increased
080 fz.y_label.font_size=4
081 fz.title.font_size=6
082 l1.font_size=4//Legend font-size set to 4 (between 1 to 10)
083
084 //File-saving routine
085 exec('FileSave.sci');
086 [fs]=FileSave();
087 xs2png(0,fs);//saving plot with the user-given filename saved
with variable fs
088 //format - xs2png(win_num, file_name)...win_num - an
integer, ID of the figure to export.
089 mprintf('Plot saved as %s',fs)
090
091 case 2 then
092 exec('DisplayColumn_Index.sci');
093 DisplayColumn_Index();
094 mprintf('\nEnter Column Number for your Graph\n\n')
095 [z]=SingleNumberInput(0, column);//A function within
function
096 x = linspace (1,row,row);//x-min, x-max, divisions
097 y = b(:,z)//for column selection
098 disp(y);
099 clf();
100 plot2d(x,[y],style=[color("red")])
101 //plot2d(x,[sin(x),cos(x)],style=[color("red"),color("green")]);
102 //xgrid(6)
103 fz=gca() // This routine returns the handle of the current axes
for the current figure.
104 fx=gcf();
105 fz.thickness=1.5 // Using the handle all line-thicknesses are
increased
106 fz.grid=[1 1]
107 tmp=fz.x_ticks
108 tmp.locations=[0:row]
109 tmp.labels=string(tmp.locations);
110 fz.x_ticks=tmp;
111 fx.children.children(1).children.line_style = 3;
112 fx.children.children(1).children.thickness = 3;
113
114 //Text Input for Title
115 mprintf('Enter your text for Title\n')
116 exec('TextInput.sci');
117 [txt_title]=TextInput()
118 if isempty(txt_title)
119 column_number=string(z)
120 plot_title='Plot for Column-'+column_number
121 txt_title=plot_title//default title
122 end
123
124 //Text Input for X-Axis
125 mprintf('Enter your text for X-Axis\n')
126 [x_axis]=TextInput()
127 if isempty(x_axis)
128 x_axis="X-Axis"
129 end
130
131 //Text Input for Y-Axis
132 mprintf('Enter your text for Y-Axis\n')
133 [y_axis]=TextInput()
134 if isempty(y_axis)
135 y_axis="Y-Axis"
136 end
137
138 //Text Input for Legend
139 mprintf('Enter your text for Legends\n')
140 [l]=TextInput()
141 if isempty(l)
142 default_legend='Column-'+column_number
143 l=default_legend
144 end
145
146 xtitle([txt_title],[x_axis],[y_axis])
147 l1=legend([l],5)
148 fz.font_size=4 // Using the handle axis fontsize is increased
149 fz.x_label.font_size=4 // Using the handle x-label fontsize is
increased
150 fz.y_label.font_size=4
151 fz.title.font_size=6
152 l1.font_size=4//Legend font-size set to 4 (between 1 to 10)
153
154 //File-saving routine
155 exec('FileSave.sci');
156 [fs]=FileSave();
157 xs2png(0,fs);//saving plot with the user-given filename saved
with variable fs
158 //format - xs2png(win_num, file_name)...win_num - an
integer, ID of the figure to export.
159 mprintf('Plot saved as %s',fs)
160
161 case 3 then
162
163 mprintf('\n== Multi-row Plotting ==\n\n');
164 exec('DisplayRow_Index.sci');
165 DisplayRow_Index();
166 mprintf('\n');
167
167 i=1;
168 while (i<>0)
169 rs=input('Enter rows for plotting, e.g. [3,4,7] for Row-3,
Row-4 & Row-7 Your Choice: ')
170 disp(rs);
171 n=input('Confirm text Y/N: ',"string");
172 if n=="Y" | n=="y" then i=0;end
173 if n=="N" | n=="n" then disp ('Re-enter');i=1;end
174 end
175
176 x=[0+1:column]
177 L_rs=length(rs)
178 for i=1:L_rs
179 r(i)=rs(:,i)
180 //disp(r(i))
181 y = b(r(i),:)
182 plot(x,y,'color',rand(1,3),'LineWidth',2)
183 j(i)=string(r(i))
184 j(i)='Row-'+j(i)
185 //disp(j(i))
186 xgrid
187
188 title('Multi-plot of Rows','fontsize',6)
189 xlabel('X-Axis','fontsize',4)
190 ylabel('Y-Axis','fontsize',4)
191 end
192
193 L1=legend(j,5)
194 L1.font_size=3;
195 fntsz = gca();// Activate the handle "Axes"
196 // display the properties of the handle "Axes"
197 fntsz.font_size = 3; //controlling fontsize of axes
198
199 //File-saving routine
200 exec('FileSave.sci');
201 [fs]=FileSave();
202 xs2png(0,fs);//saving plot with the user-given filename saved
with variable fs
203 //format - xs2png(win_num, file_name)...win_num - an
integer, ID of the figure to export.
204 mprintf('Plot saved as %s',fs)
205
206 case 4 then
207 mprintf('\n== Multi-column Plotting ==\n\n');
208 exec('DisplayColumn_Index.sci');
209 DisplayColumn_Index();
210 mprintf('\n');
211
212 i=1;
213 while (i<>0)
214 cs=input('Enter column for plotting, e.g. [1,2,4] for
Column-1, Column-2 & Column-4 Your Choice: ')
215 disp(cs);
216 n=input('Confirm text Y/N: ',"string");
217 if n=="Y" | n=="y" then i=0;end
218 if n=="N" | n=="n" then disp ('Re-enter');i=1;end
219 end
220
221 x=[0+1:row]
222 L_cs=length(cs)
223
224 for i=1:L_cs
225 cc(i)=cs(:,i)
226 y=b(:,cc(i))
227 plot(x,y','color',rand(1,3),'LineWidth',2)//Need to
transpose one of the arrays,
228 //to make them identical in
dimensions
229 j(i)=string(cc(i))
230 j(i)='Column-'+j(i)
231 //disp(j(i))
232 xgrid
233
234 title('Multi-plot of Columns','fontsize',6)
235 xlabel('X-Axis','fontsize',4)
236 ylabel('Y-Axis','fontsize',4)
237 end
238
239 L1=legend(j,5)
240 L1.font_size=3;
241 fntsz = gca(); // Activate the handle "Axes"
242 // display the properties of the handle "Axes"
243 fntsz.font_size = 3; //controlling fontsize of axes
244
245 //File-saving routine
246 exec('FileSave.sci');
247 [fs]=FileSave();
248 xs2png(0,fs);//saving plot with the user-given filename saved
with variable fs
249 //format - xs2png(win_num, file_name)...win_num - an
integer, ID of the figure to export.
250 mprintf('Plot saved as %s',fs)
251
252
253 case 5 then
254 disp("This works with a square matrix - not included in the
text - left as an exercise for the reader")
255 case 6 then
256 disp("This works with a square matrix - not included in the
text - left as an exercise for the reader")
257 else
258 error("Error")
259 end
1. SingleNumberInput.sci
z=0
while z<x1 | z>x2 | z==0 // condition for while
mprintf('Choose your option between %i,and %i',x1,x2) //
guiding the user
z=input('Enter your option: ',"string") // user input in string
z=strtod(z);disp(z) // string to number
if (isnan(z)) z=0;end // if no number is entered by mistake
end
endfunction
2. FileName.sci
function [a]=FileName()
i=1;
while (i>0)
a=input('Enter the filename: ',"string");
disp(a);
n=input('Confirm filename Y/N: ',"string");
if n=="Y" | n=="y" then i=0;end
if n=="N" | n=="n" then disp ('Re-enter');i=1;end
end
disp('So,the filename is '+ string (a));
[fd,err]=mopen('a');
if err==0 then disp('good');end
endfunction
3. csv_FileOpen.sci
function [b]=csv_FileOpen(a)
b=csvRead(a)
endfunction
4. GraphOption.sci
function [op,c]=GraphOption()
op = 0;
while (op<1 | op>6)
disp(op,c);
n=input(' Confirm Option Y/N: ',"string");
if n=="Y" then end
if n=="N" then disp (' Re-enter');op=0;end
end//end while
endfunction
5. DisplayRow_Index.sci
function [ ]=DisplayRow_Index()
a=[0+1:row]
dsi=a' //dsi-Display Row Index
//disp(dsi)
dsi_tb=[dsi,b]//dsi_tb - Display Row Index Table
disp(dsi_tb)
endfunction
6. TextInput.sci
function [txt]=TextInput()
i=1;
while (i<>0)
txt=input('Enter your text or {Return} for default]:
',"string");
while (i<>0)
disp(txt);
n=input('Confirm text Y/N: ',"string");
if n=="Y" | n=="y" then i=0;end
if n=="N" | n=="n" then disp ('Re-enter');i=1;end
end
end
endfunction
7. FileSave.sci
function [fs]=FileSave()
i=1;
while (i<>0)
fs=input('Enter the filename [e.g. Plot-01.png] for saving
your plot: ',"string");
disp(fs);
if (isfile(fs)) then disp("Filename already there in working
directory: Overwrite - Y New name - N");end
n=input('Confirm filename Y/N: ',"string");
if n=="Y" | n=="y" then i=0;end
if n=="N" | n=="n" then disp ('Re-enter');i=1;end
end
endfunction
8. DisplayColumn_Index.sci
function []=DisplayColumn_Index()
a=[0+1:column]
dsi=a //dsi-Display Column Index
//disp(dsi)
dsi_tb=[dsi;b]//dsi_tb - Display Column Index Table
disp(dsi_tb)
endfunction
1) Single-Row Plotting:
"test.csv"
Confirm filename Y/N: y
1.
5.
Enter the filename [e.g. Plot-01.png] for saving your plot: aa.png
"aa.png"
2) Multiple-Column Plotting:
"test.csv"
Confirm filename Y/N: y
"So, the filename is test.csv"
4.
== Multi-column Plotting ==
1. 2. 3. 4. 5. 6.
315. 320. 335. 315. 340. 319.
313. 318. 330. 318. 338. 315.
310. 323. 325. 318. 336. 317.
309. 320. 324. 319. 336. 318.
307. 319. 330. 320. 320. 330.
305. 350. 335. 322. 310. 345.
307. 357. 335. 320. 302. 367.
308. 367. 330. 320. 300. 387.
308. 380. 328. 319. 300. 390.
309. 395. 330. 319. 295. 400.
Enter column for plotting, e.g. [1,2,4] for Column-1, Column-2 &
Column-4 Your Choice: [2,4,6]
2. 4. 6.
Confirm text Y/N: y
Enter the filename [e.g. Plot-01.png] for saving your plot: aa.png
"aa.png"
To show some examples of XCOS for use on control systems, one needs to
understand the term 'transfer function'. (“How to Find the Transfer Function
of a System – x-Engineer.Org.”)
The transfer function is defined as the ratio of the output and the input in the
Laplace domain, which is a mathematical domain where, instead of viewing
processes in the time domain, the processes are viewed as equations in the
frequency domain. Laplace domain is viewed in what is called a 's-plane'.
Now, the above equation should be transferred to the Laplace domain. (see
Duffy, “Laplace Transform of a First Order System.”)
Once the transfer function of the system is known, the system can be
simulated in XCOS. (see Yaqub, An Introduction to Xcos.)
The XCOS is set up as shown in the diagram: (Yaqub, Making Your First
Simulation in Scilab Xcos [Unit Step Response]).
The following blocks from the Palette browser are used (dragged, dropped
and connected) in the above set up:
Nagar, Sandeep. Introduction to Scilab: For Engineers and Scientists. 1st ed.
edition. New York, NY: Apress, 2017. Amazon Link
“Polyline Properties - Description of the Polyline Entity Properties.”
Accessed May 6, 2020. Scilab Help Link
Scilab Online Help - gcf. “Gcf - Return Handle of Current Graphic Window.”
Scilab Help. Accessed April 23, 2020. Scilab-Link
Stack Overflow. “How Does Subplot Work and What Is the Difference
between Subplot(121) and Subplot(1,2,1) in MATLAB?” Accessed April 26,
2020. Stack Overflow Link
Yaqub, Tahir. Making Your First Simulation in Scilab Xcos [Unit Step
Response]. Accessed May 21, 2020. YouTube-Link
Index
2
2D Plotting 1
A
Acknowledgment 1
App. Development Tasks in Detail 1
Apple Mac 1
Application Development 1
Ask user to choose option 1
Assigning Variable 1
B
Break in a for-end loop 1
Built-in Constants 1
C
Common Built-in Functions 1
companion website 1
Custom Functions 1
D
Defining online custom function 1
Determinant of Matrix 1
Display Data Using mprintf() 1
E
Eigenvalues and Eigenvectors 1
Elementary Operators 1
Error Handling 1
error-handling routines 1
F
For Loops 1
For Loops - Nested 1
I
If Else Conditional Statements 1
Identity Matrix & Inverse of Matrix 1
Importing Data 1
Inputs to Scilab could be in two ways 1
INRIA 1
install Scilab 1
L
Linux 1
List of Figures 1
Logical Operators 1
M
MATLAB 1
Matrices – Addition & Subtraction 1
Matrices – Multiplication 1
Matrix Operation Using Scilab 1
matrix when multiplied by an identity matrix 1
mprintf-Console Output in a table-format 1
MS Windows 10 installation 1
P
plot2d 1
plot 1
R
Read csv-file as a matrix 1
Rule of matrix multiplication 1
S
Scilab as a Simple Calculator 1
Scilab Environment 1
Scilab Installation 1
Scilab Variable List 1
SciNotes - Storage of Programs in Scilab 1
Select Case Conditional Statements 1
Select Case to do the plotting 1
Series Content 1
Series Introduction 1
Silab 1
Solve Linear Equations by Matrices 1
T
Table of Contents 1
Transpose of Matrix 1
type 1
typeof 1
U
user-defined function 1
user-input 1
user-input errors 1
user-input-validation 1
W
While Loop 1
Who This Book Is Intended For 1
X
X = A-1 .B 1
XCOS 1
XCOS Simulations 1
IX IX Other Books by Author
KEY FEATURES
Detailed coverage of non-technical skills required by the IMO s
STCW Tables A-II/1 and A-II/2 for both operational and
management levels (including 2010 Manila Amendments)
Coverage of specific knowledge in the areas of: - effective
management and optimisation of bridge resources required for
the successful conduct of a ship s voyage - management of
human factors - effective communications - processes of team-
building & leadership - guidance of situational awareness
including team situational awareness - decision-making -
contingency planning - task management including fatigue &
workload planning Introduces the concept of behavioural
markers for assessing soft skills to establish performance levels
during a simulation exercise. This book can be used as a
guidebook in a bridge resource management course run on a full-
mission bridge simulator.
TABLE OF CONTENTS
Tables of Figures
Authors
Preface
Introduction
Chapter 1 Human Factors
Chapter 2 Communications
Chapter 3 Teamwork and Leadership
Chapter 4 Managing Bridge Processes
Chapter 5 Assessing Performance Behavioural Markers
Appendix
Index
X About the Author
VII. Bibliography
VIII Index
IX Other Books by Author
X About the Author