5 views

Uploaded by Anonymous f3e25V6Pn

Scilab Workshop

Scilab Workshop

© All Rights Reserved

- Multivariable Calculus Lecture Notes
- 2015-16 Mcet Cse Stu Handout Version 1
- 10th Class Maths Model Question Paper
- Algebra 2 Semester 1 Standards
- Homework 1 AMATH 301 UW
- alg2 ccssm syllabus
- Multivariable calc notes
- Matlab Basics 2575
- Array
- LP SB123 Week 3 Session 2 (Pers&SPLDV)
- MATLAB R Dictionary
- ASTROS_Theoretical_Manual.pdf
- 04 Matrices
- Rules Of Study
- Simultaneous Equations
- Neutrosophic Linear Equations and Application in Traffic Flow Problems
- 25Appendix D
- [Bertsekas D., Tsitsiklis J.] Parallel and Distrib(Book4You)
- Clase de Ingeniería de Control Con Matlab
- Divide and Conquer

You are on page 1of 32

Ramesh Vulavala

Professor in Chemical Engineering

D. J. Sanghvi College of Engineering

Mumbai

What is Scilab?

Computational Tool

Programming Language

Special-purpose Tool Boxes

Graphical Tools

GUI Tool Box

Scilab Objects

Matrices

Strings

Polynomials

Structures

Matrices

// Defining three vectors:

A = [1,2,3];

B = [4,5,6];

C = [7,8,9];

// Defining a matrix by putting the row vectors together:

D = [A;B;C];

D =

1. 2. 3.

4. 5. 6.

7. 8. 9.

// Defining another vector:

E = [10,11,12];

Matrices

// Combining a vector and a matrix to define a new matrix:

F = [D;E];

F = 1. 2. 3.

4. 5. 6.

7. 8. 9.

10. 11. 12.

// Defining a new column vector:

G = ones(4,1);

G = 1.

1.

1.

1.

// Combining a matrix and a column vector:

H = [F G];

Matrices

H = 1. 2. 3. 1.

4. 5. 6. 1.

7. 8. 9. 1.

10. 11. 12. 1.

// Reshaping the matrix in new dimensions:

HA = matrix(H,2,8);

HA = 1. 7. 2. 8. 3. 9. 1. 1.

4. 10. 5. 11. 6. 12. 1. 1.

HA([1,2],[3,5]) = zeros(2,2);

HA = 1. 7. 0. 8. 0. 9. 1. 1.

4. 10. 0. 11. 0. 12. 1. 1.

Operations with Matrices

Addition of two matrices:

A = [1 2 3;4 5 6;7 8 9];

A = 1. 2. 3.

4. 5. 6.

7. 8. 9.

B = A + A;

B = 2. 4. 6.

8. 10. 12.

14. 16. 18.

Operations with Matrices

// Multiplication of a matrix by a scalar:

C = 2*A;

C = 2. 4. 6.

8. 10. 12.

14. 16. 18.

D = B - C;

// Multiplication of a matrix by another matrix:

M = A*A;

66. 81. 96.

102. 126. 150.

Operations with Matrices

// Multiplication of a matrix element-wise:

N = A.*A;

N = 1. 4. 9.

16. 25. 36.

49. 64. 81.

// Multiplication of a matrix by each element of another matrix:

P = A.*.A;

Check this matrix by running your program!!!

Application of For Loop

// The following code shows the use of the for loop:

for i = 1:10,

printf('This is iteration No. %d \n',i );

end

This is iteration No. 1

This is iteration No. 2

This is iteration No. 3

This is iteration No. 4

This is iteration No. 5

This is iteration No. 6

This is iteration No. 7

This is iteration No. 8

This is iteration No. 9

This is iteration No. 10

Application of While Loop

// The following code shows the use of the while loop:

n = 1;

while (n<=5),

printf('This is iteration No. %d \n',n );

n = n + 1;

end

This is iteration No. 1

This is iteration No. 2

This is iteration No. 3

This is iteration No. 4

This is iteration No. 5

Functions

// This program shows the use of functions:

function x = my_fn(a,b);

x(1) = a + b;

x(2) = b- a;

endfunction

y = my_fn(2,5);

y = 7.

3.

Functions

function x = my_fn(a,b);

global c;

printf('value of c within the function = %d \n',c);

x(1) = a + b;

x(2) = b- a;

c = 2*c;

endfunction

global c;

a = 5;

b = 10;

c = 15;

printf('value of c before the function call = %d \n',c);

y = my_fn(a,b);

printf('value of c after the function call = %d \n',c);

Functions

value of c before the function call = 15

value of c within the function = 15

value of c after the function call = 30

Plots

// This program shows how to plot two dimensional plots:

x = [0:0.1:2*%pi];

y = sin(x);

plot(x,y);

xgrid;

xlabel('x');

ylabel('Sin x');

xtitle('Plot of Sin x');

Plots

Polynomials

// Defining a polynomial with its roots:

p = poly([0,1],'x');

2

p = -x+x

rt = roots(p);

q = p-1;

r = poly([0.5,1.5],'x');

2

q= -1-x+x

Polynomials

// Defining a polynomial in terms of its co-efficients:

v = poly([1,2],'s','coeff');

v = 1 + 2s

u = poly([1,2],'s','coeff');

w = u*v;

w= 2

1 + 4s + 4s

Polynomials

// This program shows how to define and use polynomials:

xi = input('Type the value of the damping co-efficient: ');

// Defining the polynomial:

s=poly(0,"s");

p = tou^2 * s^2 + 2*tou*xi*s + 1;

// Defining the transfer-function:

gofs = 1/p;

t = [0:0.05:20];

[rt,ct] = size(t);

us = ones(1,ct);

Polynomials

// Defining the impulse input:

ui = zeros(1,ct);

ui(1,1) = 1;

// Calculating the Step-response:

ys = csim(us,t,gofs);

// Plotting the Response

clf(0);

figure(0);

plot2d(t,ys);

xgrid;

xlabel('time');

ylabel('output');

xtitle('Step Response');

Polynomials

Polynomials

Solution of Linear Equations

// This program shows how to solve a system of linear equations:

// x + 2y = 5

// 2x + 3y = 8

A = [1,2;2,3];

b = [5;8];

// Solving the system:

x = A\b;

Solution of Non-Linear Equations

// The program solves a set of NLE using fsolve:

function z=fct(x)

z(1) = x(1)^2 + 2*x(2) - 10;

z(2) = 3*x(1) - x(2)^3 + 21;

endfunction

[x,v]=fsolve(x0,fct);

x = 2. 3.

v = 10^(-12) *

0.1101341 0.9556800

Solution of ODE

// This program solves a set of odes:

function dx = fun1(t,x);

dx(1) = x(1) + 0.05*x(2) - 0.01*x(1)*x(2);

dx(2) = 0.5*x(1) + x(2) - 0.01*x(1)^2;

Endfunction

t0 = 0;

tt = 0:0.01:5;

x0 = [0.5;0.5];

x = ode(x0,t0,tt,rtol=1.0e-12,atol=1.0e-12,fun1);

figure(1);

plot(tt,x(1,:));

xgrid;

ylabel('x(1)');

Solution of ODE

Solution of ODE

Chemical Reactions

Chemical Reactions

function dx = chemical(t,x)

f1 = k1*x(1)*x(2)

f2 = k2*x(1)*x(1)*x(3)

dx(1) = -f1 - 2*f2

dx(2) = -f1 + f2

dx(3) = f1 - f2

dx(4) = f1

endfunction

Chemical Reactions

k1 = 1e2

k2 = 1

t = 0:0.001:0.1;

x0 = [1 ;1; 0; 0];

x = ode(x0,0,t,chemical);

// Plotting the outputs:

plot2d(t,x(1,:),style=1)

plot2d(t,x(2,:),style=2)

plot2d(t,x(3,:),style=3)

plot2d(t,x(4,:),style=4)

legends(['A','B','C','D'],[1 2 3 4],"ur")

xtitle('Chemical ODE')

Chemical Reactions

Thank You !!!

Any Questions?

- Multivariable Calculus Lecture NotesUploaded byZetaBeta2
- 2015-16 Mcet Cse Stu Handout Version 1Uploaded byrazaravi
- 10th Class Maths Model Question PaperUploaded bysomeshgunda
- Algebra 2 Semester 1 StandardsUploaded byfrankdan
- Homework 1 AMATH 301 UWUploaded byargo82
- alg2 ccssm syllabusUploaded byapi-288059630
- Multivariable calc notesUploaded byJason Leung
- Matlab Basics 2575Uploaded byElenaa
- ArrayUploaded byPAWAN KUMAR
- LP SB123 Week 3 Session 2 (Pers&SPLDV)Uploaded byRensha LiLy
- MATLAB R DictionaryUploaded byJoão Paulo Versiani Ladeia
- ASTROS_Theoretical_Manual.pdfUploaded byrobcfu
- 04 MatricesUploaded byNaveenKumar
- Rules Of StudyUploaded byTaral jain
- Simultaneous EquationsUploaded byOmar Lopez C.
- Neutrosophic Linear Equations and Application in Traffic Flow ProblemsUploaded byMia Amalia
- 25Appendix DUploaded byYadana1
- [Bertsekas D., Tsitsiklis J.] Parallel and Distrib(Book4You)Uploaded byAdam Robinson
- Clase de Ingeniería de Control Con MatlabUploaded byEber Gómez Sandoval
- Divide and ConquerUploaded byskelskel
- LADE7 Intro to Linear EquationsUploaded byRoumen Guha
- Consolidated Test2 AnsUploaded bySvr Ravi
- pre-sessiomathsbook.pdfUploaded byBom Villatuya
- ArtigoUploaded byOdair Vieira
- Cal Dow EL9900bidUploaded byLuis Murillo
- C Lab ProgramsUploaded byRutvik Sheth
- L2Uploaded byrajpd28
- Network State VariableUploaded byddm
- Input of ProgramUploaded byBadr Ammar
- MC0066 AssignmentUploaded byDeekshith Shetty

- biomaterialsUploaded byakseolu
- Google NetUploaded byNitin Panj
- Comparison of MethodsUploaded bymy.nafi.pmp5283
- Timing Control User Guide XILINX.pdfUploaded byavdhesh7
- EEE 311 Project Journal ReportUploaded byzakariansu
- edu555 course info mac15-jul15Uploaded byapi-289382914
- Biometric Electronic Voting MachineUploaded byjagoorisuraj
- Instructions for Authors - ChemCommUploaded byFrauholle
- DisplayLink 7.4M2 Release-notesUploaded bysenthil_suruli
- 122258 eUploaded bykutare
- Hulme 10 Years on - Surf ReportUploaded byPaul Mason
- reflective essayUploaded byapi-285864331
- Emergency Shred_ 2-Week Routine to Get Shredded _ Muscle & FitnessUploaded byaysh2383
- The Uniform Force MothodUploaded byJoaquin Ignacio Concha Núñez
- Green Office GuideUploaded bydmuren
- Literature Review of McdonaldsUploaded byVishvas Jaiswal
- Command & Control Research GuideUploaded byREBogart
- Final Essay-Case Study Questions Week 8Uploaded byDalila Melendez
- new energy writing lesson planUploaded byapi-252179322
- The Ethics of Care Virtue Ethics and the Flourishing FamilyUploaded byPeter Lührs
- Suspension PolymerizationUploaded byHuynh Hoang Huy
- 3D Geological Modeling for Mineral Resource Assessment of the Tongshan Cu Deposit, Heilongjiang Province, ChinaUploaded byAndry Ferdian
- Effects of Surface Topography on Seismic Ground Response in the EgionUploaded byshilp88
- Tropical Medicine & International Health Volume 15 issue 12 2010 [doi 10.1111%2Fj.1365-3156.2010.02645.x] L. Otero; R. Ugaz; G. Dieltiens; E. González; K. Verdonck; C. S -- Duration of cough, TB suspeUploaded byAnonymous BnOI4J
- mechanicUploaded byapi-78191601
- Comments and Errata for KittelUploaded byTej Choksi
- An Overview of the Public Relations FunctionUploaded byBusiness Expert Press
- 2018 Molecular-Type Specific Multiplex PCR produces a distinct VNII PCR.pdfUploaded byMohamed
- AssignmentUploaded byakshay patri
- me_2014.pdfUploaded byBhawani Singh Rajawat