Scilab: Computing Tool For Engineers

27
Scilab: Computing Tool for Engineers P. R. Naren School of Chemical & Biotechnology SASTRA University E-mail: [email protected] National Conference on Advances in Process Engineering CAPE-2015 SASTRA University Thanjavur, Tamilnadu 613 401 INDIA 9 th October 2015 Progress Through Quality Education

Transcript of Scilab: Computing Tool For Engineers

Page 1: Scilab: Computing Tool For Engineers

Scilab: Computing Tool for Engineers

P. R. NarenSchool of Chemical & Biotechnology

SASTRA University

E-mail: [email protected]

National Conference on Advances in Process Engineering CAPE-2015

SASTRA UniversityThanjavur, Tamilnadu 613 401 INDIA

9th October 2015

Progress Through Quality Education

Page 2: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

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 2

Page 3: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

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 3

Page 4: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

Scilab

• Computing tool – Scripts / programming environment– Mathematical operations

A place where we can compute / calculate !!! Numerically solve equations

• Free and Open sourcehttp://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 4

Page 5: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

FOSSEE Project

• Free and Open Source Software for Education• FOSSEE on Scilab: http://www.scilab.in

– Spoken Tutorials10 min short videos on scilab functions http://spoken-tutorial.org/ Take workshop and attend objective test IITB MHRD certificate

– Textbook Companion Projecthttp://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 ProjectConvert lab exercises to Scilab

9-Oct-15 5

Page 6: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

Familiarization

• Version 5.5.2

Console

Variable List

CommandHistory

File Browser

9-Oct-15 6

Page 7: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

Basic Operators and Functions

• Operators : +, -, *, /, ^• sqrt • %e• %i• %pi• log

– This is based on “e” - Natural logarithm

• log10• Colon “:” operator

• sin cos tan– sind cosd tand– asin acos atan

• factorial • sum • product• Relational

– > >= < <= == ~= <>• Logical

– & | ~

9-Oct-15 7

Page 8: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

Variables

• No class/type definitions or declarations

-->a = 3; -->a a = 3. -->a = "Workshop"; -->a a = Workshop

9-Oct-15 8

Page 9: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

Matrices

• Every variable is n dimension in nature– No need to specify the dimensions / length / size

h = [ 1 24 -5]

-->h = [1 24 -5] h = 1. 24. - 5.

-->h = 1; -->h(1,2) = 24; -->h(1,3) = - 5; -->h h = 1. 24. - 5.

-->h = [1 24]; -->h(1,3) = - 5; -->h h = 1. 24. - 5.

9-Oct-15 9

Page 10: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

Matrices Cont.

-->x = [2 -3 4; 5 10 24] x = 2. - 3. 4. 5. 10. 24.

-->x = [2 -3 4]; -->x(2,:) = [5 10 24]; -->x x = 2. - 3. 4. 5. 10. 24.

-->x(2,:) = [5 10 24]; -->x x = 0. 0. 0. 5. 10. 24. -->x(1,:)=[2 -3 4] x = 2. - 3. 4. 5. 10. 24.

9-Oct-15 10

Page 11: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

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 11

Page 12: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

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 12

Page 13: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

Tutorial 1

Multiplication of two numbers (23.4 and 21) and get their product

• Objective– General programming structure

clear clcdifferent sections in program

– Different options for output (result display on console)dispmprintf

Tutorial-1 Script File

9-Oct-15 13

Page 14: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

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 14

Page 15: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

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 15

Page 16: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

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 16

Page 17: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

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 17

Page 18: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

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 18

Page 19: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

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 19

Page 20: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

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 20

Page 21: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

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

20 1 2f (x) a a x a x

9-Oct-15 21

Page 22: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

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 22

Page 23: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

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

tan k tan k

t

V BWH m VUU mgZ Um

r

9-Oct-15 23

Page 24: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

Tutorial 12

Sum on N numbers• Objective

– Use looping statement – For loop Determine the sum of N numbers

Tutorial12-File-operation.sce

N

ii 1

S x

9-Oct-15 24

Page 25: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

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 25

Page 26: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

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 26

Page 27: Scilab: Computing Tool For Engineers

Scilab - A Computing Tool for Engineers

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 27