1. Scilab: Computing Tool for Engineers
P. R. Naren
School of Chemical & Biotechnology
SASTRA University
E-mail: prnaren@scbt.sastra.edu
National Conference on Advances in Process Engineering
CAPE-2015
SASTRA University
Thanjavur, Tamilnadu 613 401 INDIA
9th October 2015
Progress Through Quality Education
2. Why are we here?
• To learn about Scilab
– Syntax
– Advantages
– Limitation
• To master programming skills
• To become efficient programmer
Familiarize
programming tool
Scilab
and
complement our
learning process !
9-Oct-15 Scilab - A Computing Tool for Engineers
2
3. Outline
• What is Scilab ?
• Basics
– Variables, Matrices,
– Std. I/O function
• Linear algebra
• Functions and Subroutines
• Control / Looping statements
• ODE
• File operations and GUI
• Plot Functions
9-Oct-15 Scilab - A Computing Tool for Engineers
3
4. Scilab
• Computing tool
– Scripts / programming environment
– Mathematical operations
A place where we can compute / calculate !!!
Numerically solve equations
• Free and Open source
http://www.scilab.org
– Free to download
– Lot of help material available over net
http://wiki.scilab.org/
http://help.scilab.org/docs/5.5.2/en_US/index.html
9-Oct-15 Scilab - A Computing Tool for Engineers
4
5. FOSSEE Project
• Free and Open Source Software for Education
• FOSSEE on Scilab: http://www.scilab.in
– Spoken Tutorials
10 min short videos on scilab functions http://spoken-tutorial.org/
Take workshop and attend objective test
IITB MHRD certificate
– Textbook Companion Project
http://www.scilab.in/Textbook_Companion_Project
Code all solved examples of standard textbook
– Codes for most textbooks already available – Use and learn !!
Get paid ! Honorarium (INR 12k) from IITB
– Lab Migration Project
Convert lab exercises to Scilab
9-Oct-15 Scilab - A Computing Tool for Engineers
5
11. Script Files
• Script file
– .sce
– .sci
e - executable i – functions
e – main script files i - for functions or sub-rountines
• “//” comment a statement
– Good programing etiquettes !
• clc
• clear
9-Oct-15 Scilab - A Computing Tool for Engineers
11
12. Tutorials
• Tut1: Product of two nos.
• Tut2: Product of two nos. + user input
• Tut3: Matrix calculations based on user
choice
• Tut4: Matrix calculations based on user
choice with condition check
• Tut5: Spline curves
• Tut6: Building blocks
• Tut7: Equation of motion : v
• Tut8: Equation of motion: v and x
• Tut9: Roots of polynomial
• Tut10: Smart Input for Tut4
• Tut11: Write output into text file
• Tut12: Sum on n numbers
• Tut1: Print statements
• Tut2: Input function
• Tut3: Switch case
• Tut4: If then else
• Tut5: Plot functions
• Tut6: Function (Sub routines)
• Tut7: ODE function : I order
• Tut8: Simultaneous ODE : Two I order
• Tut9: Inbuilt function fsolve
• Tut10: GUI
• Tut11: File operations
• Tut12: For looping
9-Oct-15 Scilab - A Computing Tool for Engineers
12
13. Tutorial 1
Multiplication of two numbers (23.4 and 21) and get
their product
• Objective
– General programming structure
clear
clc
different sections in program
– Different options for output (result display on console)
disp
mprintf
Tutorial-1 Script File
9-Oct-15 Scilab - A Computing Tool for Engineers
13
14. Tutorial 2
Multiplication of two numbers (user input) and get their
product
• Objective
– input function
Obtain user input and then perform computation
Makes program more generic
reusable !!
Tutorial-2 Script File
9-Oct-15 Scilab - A Computing Tool for Engineers
14
15. Tutorial 3
Perform operations on matrix based on user choice
• Objective
– Control statement – “select – case – end”
Obtain two matrices from user
Perform arithmetic operations on the matrices based on user
choice
– Add two matrix
– Matrix multiplication
– Element wise multiplication
Tutorial-3 Script File
9-Oct-15 Scilab - A Computing Tool for Engineers
15
16. Tutorial 4
Perform operations on matrix based on user choice
with conditional check
• Objective
– Control statement – “if - then – else - end”
Obtain two matrices from user
Perform arithmetic operations on the matrices based on user
choice
– Add two matrix / Matrix multiplication / Element wise multiplication
Check whether the user entered value is within bounds / range !!
Tutorial-4 Script File
9-Oct-15 Scilab - A Computing Tool for Engineers
16
17. Tutorial 5
Graphical nature of functions
• Objective
– Plot functions
Generate equi-spaced data (data range)
Generate splines
– Smooth polynomial
Plot the generated spline to know its nature
Tutorial-5 Script File
9-Oct-15 Scilab - A Computing Tool for Engineers
17
18. Tutorial 6
Building Block
• Objective
– Use of sub-routines or functions
Define function once and call it wherever required
Given dimensions of unit building block, how many blocks are
required to build a wall
Tutorial-6 Script File
9-Oct-15 Scilab - A Computing Tool for Engineers
18
19. Tutorial 7
Equation of motion : Velocity of a moving body under
constant linear acceleration
• Objective
– Solve first order ODE
Equation of motion for a moving body under constant acceleration
Acceleration “a”
– Constant
– Variable
Tutorial-7 Script File
0 0t t u u
9-Oct-15 Scilab - A Computing Tool for Engineers
19
20. Tutorial 8
Equation of motion : Velocity and Location of a moving
body under constant linear acceleration
• Objective
– Solve two first order ODE’s
Equation of motion for a moving body under constant acceleration
Acceleration “a”
– Constant
– Variable
Tutorial-8 Script File
0 0t t u u
9-Oct-15 Scilab - A Computing Tool for Engineers
20
21. Tutorial 9
Roots of Polynomial
• Objective
– To determine the roots of polynomial
Find x such that f(x) = 0
Quadratic equation
– Define f(x)
– Guess a value for xroot such that f (xroot) = 0
– Use in-built function fsolve to determine a actual root
Tutorial-9Script File
0 0t t u u
2
0 1 2f (x) a a x a x
9-Oct-15 Scilab - A Computing Tool for Engineers
21
22. Tutorial 10
Perform operations on matrix based on user choice
! Obtain data in Smart Way !
• Objective
– Use of simple GUI function to obtain data
Avoids error previously encountered in Tutorial 4 !
Tutorial-10 Script File
9-Oct-15 Scilab - A Computing Tool for Engineers
22
23. Tutorial 11
Write output data into a file
• Objective
– Use file I/O commands and write result into a file
Water tank of known dimensions (B X W X H) at elevated position
Z from ground level
Fluid of known density ( r )
Compute Total and specific potential energy
Tutorial11-File-operation.sce
tank tank
t
V BW H m V
U
U mg Z U
m
r
9-Oct-15 Scilab - A Computing Tool for Engineers
23
24. Tutorial 12
Sum on N numbers
• Objective
– Use looping statement – For loop
Determine the sum of N numbers
Tutorial12-File-operation.sce
N
i
i 1
S x
9-Oct-15 Scilab - A Computing Tool for Engineers
24
25. To Sum Up
• Scilab as computing tool for engineers
• Basic arithmetic operations
• Computing abilities in Scilab
• Generic programming etiquette
• Use Tutorials and Web documents
• Improvise, learn (re-learn / un-learn)
• Use Scilab to complement your engineering
education
9-Oct-15 Scilab - A Computing Tool for Engineers
25
26. Gratitude
• CAPE-2015 and IIChE Student Chapter
– For this wonderful opportunity
• PR Team for their registration drive !!
• Technical and Infra support team
• Audience
9-Oct-15 Scilab - A Computing Tool for Engineers
26
27. THANK YOU
A person who never made a mistake never tried
anything new
- Albert Einstein
- 1879 -1955
Entities must not be
multiplied beyond necessity
- William of Ockham
- 12th A.D.
9-Oct-15 Scilab - A Computing Tool for Engineers
27
Notas do Editor
Console: Simple arithmetic operations can be directly performed on console / Output is displayed on console
Command history stores all commands from console !
Variable browser window lists all the variable that are currently in use
Semi-colon “;” is used to suppress printing / display on the command window. For instance, command “a=3” assigns 3 to variable “a” and also displays the output on console
In contrast, “a=3;” assigns 3 to variable a but suppress the display on console
Q: How to retrieve the elements of matrix? Extraction of elements from matrix
Colon “:” operator