Download Scilab Notes and ETC and more Slides Mathematics in PDF only on Docsity!
Introduction to Scilab
application to feedback control
Yassine Ariba
Brno University of Technology - April 2014
Sommaire
1 Introduction
2 Basics
3 Matrices
4 Plotting
5 Programming
6 For MATLAB users
7 Xcos
8 Application to feedback control
9 Classical control design
Introduction What is Scilab?
What is Scilab?
Scilab is the contraction of Scientific Laboratory. Scilab is :
a numerical computing software,
an interpreted programming environment,
used for any scientific and engineering applications,
multi-platform : Windows, MacOS et Linux,
Created by researchers from
Inria in the 90’s, the software
is now developed by Scilab
Entreprises
www.scilab.org
Introduction What is Scilab?
Scilab includes hundreds of functions for various applications
Mathematics and simulation
2D and 3D visualization
Optimization
Statistics
Control system design and analysis
Signal processing
Application development
More informations : www.scilab.org
Introduction Getting started
Getting started
Firstly, Scilab can be used in an interactive way by typing instructions on
the console.
type scilab code on the prompt -->
type enter, to execute it.
Scilab return its answer on the console or in a new window for graphics.
Introduction Getting started
A first simple example :
--> A = 2;
--> t = [0:0.01:10]; --> y = A * sin (3* t ); --> plot (t , y );
Line 1 : assign the value 2 to the variable A.
Line 2 : define a vector t that goes from 0 to 10 with a step of 0.01.
Line 3 : compute a vector y from some mathematical operations.
Line 4 : plot y with respect to t on a 2D graphic.
Note that “ ; ” prevents from printing the result of an instruction.
Introduction Getting started
A second simple example :
Let consider a system of linear equations
2 x 1 + x 2 = − 5
4 x 1 − 3 x 2 + 2x 3 = 0
x 1 + 2x 2 − x 3 = 1
Let solve it with Scilab
--> A = [2 1 0 ; 4 -3 2 ; 1 2 -1];
--> b = [ -5;0;1]; --> x = inv ( A )* b x =
Introduction Getting started
Scilab provides a graphical environment with several windows.
the console
command history
file browser
variable browser
and others : editor, graphics, help, ...
Basics Elementary operations
Elementary operations
Simple numerical calculations :
ans =
--> 4^2/ ans =
--> 2(1+2 %i ) ans =
--> %i ^ ans =
--> cos (3)^2 + sin (3)^ ans =
--> exp (5) ans =
--> abs (1+ %i ) ans =
Basics Elementary operations
elementary operations
+ addition
* multiplication
/ right division
\ left division
ˆ exponents
elementary functions
sin cos tan cotg
asin acos atan sec
sinh cosh tanh csc
abs real imag conj
exp log log10 log
sign modulo sqrt lcm
round floor ceil gcd
--> conj (3+2* %i ) ans =
--> log10 (10^4) ans =
Basics Variables
Variables
A variable can be directly defined via the assignment operator : “ = ”
--> a = 2.5; --> b = 3; --> c = a * b c =
--> c + d ! - - error 4 Undefined variable : d
Variable names may be defined with letters a → z, A → Z, numbers 0
→ 9 and few additional characters %, , !, #, ?, $.
Scilab is case sensitive.
Do not confused the assignment operator “ = ” with the mathematical
equal.
Variable declaration is implicit, whatever the type.
Basics Variables
Pre-defined variables
%i imaginary number i =
%e Euler’s number e
%pi constant π
%inf infinity ∞
%t ou %T boolean true
%f ou %F boolean false
--> cos (2* %pi ) ans =
--> %i ^ ans =
Matrices Defining and handling vectors
Defining and handling vectors
A vector is defined by a list of numbers between brackets :
--> u = [0 1 2 3] u =
Automatic creation
--> v = [0:0.2:1] v =
- 0.2 0.4 0.6 0.8 1.
Syntax : start:step:end
Mathematical functions are applied element-wise
--> cos ( v ) ans =
- 0.980 0.921 0.825 0.696 0.
Matrices Defining and handling vectors
column vectors can also be defined with semi colon separator “ ; ”
--> u = [1;2;3] u =
Some useful functions :
length return the length of the vector
max return the maximal component
min return the minimal component
mean return the mean value
sum return the sum of all components
prod return the product of all components
--> length ( v ) ans =
--> mean ( v ) ans =