Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab...
Transcript of Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab...
![Page 1: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/1.jpg)
Scilab: basic/matrix operations
Dr. Madhu N. Belur
Control & Computing groupDepartment of Electrical Engineering
Indian Institute of Technology BombayEmail: [email protected]
![Page 2: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/2.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Outline
1 Vectors/matrices
2 Plotting
3 if-then-else-end and for-end loops
4 Polynomials
5 Other useful commands
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 3: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/3.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Today’s focus
Scilab is free.
Matrix/loops syntax is same as for Matlab.
Scilab provides all basic and many advanced tools.
Signal processing, Control systems, block-diagram-simulation(xcos), Electrical, networks, op-amps, device simulation, ++
Toolboxes: image/video processing, wavelets, neural networks,filter design, hardware-interfacing for real time control, ++
French National Space Agency (CNES) (like India ISRO) usesonly Scilab (search google Martin CNES Scilab )
Teaching Matlab is like MBBS colleges teaching to-be-doctorshow to use only very expensive medicines
Today: basic matrix operations and loops syntax, plotting
Also: signal processing: DSP,
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 4: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/4.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Today’s focus
Scilab is free.
Matrix/loops syntax is same as for Matlab.
Scilab provides all basic and many advanced tools.
Signal processing, Control systems, block-diagram-simulation(xcos), Electrical, networks, op-amps, device simulation, ++
Toolboxes: image/video processing, wavelets, neural networks,filter design, hardware-interfacing for real time control, ++
French National Space Agency (CNES) (like India ISRO) usesonly Scilab (search google Martin CNES Scilab )
Teaching Matlab is like MBBS colleges teaching to-be-doctorshow to use only very expensive medicines
Today: basic matrix operations and loops syntax, plotting
Also: signal processing: DSP,
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 5: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/5.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Today’s focus
Scilab is free.
Matrix/loops syntax is same as for Matlab.
Scilab provides all basic and many advanced tools.
Signal processing, Control systems, block-diagram-simulation(xcos), Electrical, networks, op-amps, device simulation, ++
Toolboxes: image/video processing, wavelets, neural networks,filter design, hardware-interfacing for real time control, ++
French National Space Agency (CNES) (like India ISRO) usesonly Scilab (search google Martin CNES Scilab )
Teaching Matlab is like MBBS colleges teaching to-be-doctorshow to use only very expensive medicines
Today: basic matrix operations and loops syntax, plotting
Also: signal processing: DSP,
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 6: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/6.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Today’s focus
Scilab is free.
Matrix/loops syntax is same as for Matlab.
Scilab provides all basic and many advanced tools.
Signal processing, Control systems, block-diagram-simulation(xcos), Electrical, networks, op-amps, device simulation, ++
Toolboxes: image/video processing, wavelets, neural networks,filter design, hardware-interfacing for real time control, ++
French National Space Agency (CNES) (like India ISRO) usesonly Scilab (search google Martin CNES Scilab )
Teaching Matlab is like MBBS colleges teaching to-be-doctorshow to use only very expensive medicines
Today: basic matrix operations and loops syntax, plotting
Also: signal processing: DSP,
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 7: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/7.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Today’s focus
Scilab is free.
Matrix/loops syntax is same as for Matlab.
Scilab provides all basic and many advanced tools.
Signal processing, Control systems, block-diagram-simulation(xcos), Electrical, networks, op-amps, device simulation, ++
Toolboxes: image/video processing, wavelets, neural networks,filter design, hardware-interfacing for real time control, ++
French National Space Agency (CNES) (like India ISRO) usesonly Scilab (search google Martin CNES Scilab )
Teaching Matlab is like MBBS colleges teaching to-be-doctorshow to use only very expensive medicines
Today: basic matrix operations and loops syntax, plotting
Also: signal processing: DSP,
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 8: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/8.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Today’s focus
Scilab is free.
Matrix/loops syntax is same as for Matlab.
Scilab provides all basic and many advanced tools.
Signal processing, Control systems, block-diagram-simulation(xcos), Electrical, networks, op-amps, device simulation, ++
Toolboxes: image/video processing, wavelets, neural networks,filter design, hardware-interfacing for real time control, ++
French National Space Agency (CNES) (like India ISRO) usesonly Scilab (search google Martin CNES Scilab )
Teaching Matlab is like MBBS colleges teaching to-be-doctorshow to use only very expensive medicines
Today: basic matrix operations and loops syntax, plotting
Also: signal processing: DSP,
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 9: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/9.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Today’s focus
Scilab is free.
Matrix/loops syntax is same as for Matlab.
Scilab provides all basic and many advanced tools.
Signal processing, Control systems, block-diagram-simulation(xcos), Electrical, networks, op-amps, device simulation, ++
Toolboxes: image/video processing, wavelets, neural networks,filter design, hardware-interfacing for real time control, ++
French National Space Agency (CNES) (like India ISRO) usesonly Scilab (search google Martin CNES Scilab )
Teaching Matlab is like MBBS colleges teaching to-be-doctorshow to use only very expensive medicines
Today: basic matrix operations and loops syntax, plotting
Also: signal processing: DSP,
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 10: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/10.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Defining a matrix
A=[1 3 4 6] and A=[1 3 4 6];
B=[1 3 4 6;5 6 7 8] // next row by ;
length(A), ones(A), zeros(B), zeros(3,5)
size(A), size(A,’c’), size(A,’r’)
B(1,3)
B(1,3) = -45
quote ( ’ ) for transpose of A
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 11: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/11.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Defining a matrix
A=[1 3 4 6] and A=[1 3 4 6];
B=[1 3 4 6;5 6 7 8] // next row by ;
length(A), ones(A), zeros(B), zeros(3,5)
size(A), size(A,’c’), size(A,’r’)
B(1,3)
B(1,3) = -45
quote ( ’ ) for transpose of A
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 12: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/12.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Defining a matrix
A=[1 3 4 6] and A=[1 3 4 6];
B=[1 3 4 6;5 6 7 8] // next row by ;
length(A), ones(A), zeros(B), zeros(3,5)
size(A), size(A,’c’), size(A,’r’)
B(1,3)
B(1,3) = -45
quote ( ’ ) for transpose of A
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 13: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/13.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Defining a matrix
A=[1 3 4 6] and A=[1 3 4 6];
B=[1 3 4 6;5 6 7 8] // next row by ;
length(A), ones(A), zeros(B), zeros(3,5)
size(A), size(A,’c’), size(A,’r’)
B(1,3)
B(1,3) = -45
quote ( ’ ) for transpose of A
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 14: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/14.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Random numbers/matrices
rand(9) generates a 1× 1 random number (uniformly distributedbetween 0 and 1, etc: see help).If A is an n × p matrix, thenB = rand(A) // defines a random matrix B of the size of A.(A is not overwritten. The matrix B is defined.)
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 15: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/15.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Random numbers/matrices
rand(9) generates a 1× 1 random number (uniformly distributedbetween 0 and 1, etc: see help).If A is an n × p matrix, thenB = rand(A) // defines a random matrix B of the size of A.(A is not overwritten. The matrix B is defined.)
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 16: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/16.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Random numbers/matrices
rand(9) generates a 1× 1 random number (uniformly distributedbetween 0 and 1, etc: see help).If A is an n × p matrix, thenB = rand(A) // defines a random matrix B of the size of A.(A is not overwritten. The matrix B is defined.)
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 17: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/17.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Random numbers/matrices
rand(9) generates a 1× 1 random number (uniformly distributedbetween 0 and 1, etc: see help).If A is an n × p matrix, thenB = rand(A) // defines a random matrix B of the size of A.(A is not overwritten. The matrix B is defined.)
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 18: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/18.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Multiplication and addition
(Vectors are also matrices: with number of rows/columns = 1).Suppose A and B are matrices of 3 rows and 4 columns.A+B // same sizes of A and B requiredA*B // Not defined. size(A,’c’) 6= size(B,’r’)A*B’ // dimensions allow multiplicationA+4 // understood as elementwise additionA*4 and 4*A // understood as elementwise multiplicationA•*B // understood as elementwise multiplication of matrices
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 19: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/19.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Multiplication and addition
(Vectors are also matrices: with number of rows/columns = 1).Suppose A and B are matrices of 3 rows and 4 columns.A+B // same sizes of A and B requiredA*B // Not defined. size(A,’c’) 6= size(B,’r’)A*B’ // dimensions allow multiplicationA+4 // understood as elementwise additionA*4 and 4*A // understood as elementwise multiplicationA•*B // understood as elementwise multiplication of matrices
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 20: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/20.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Multiplication and addition
(Vectors are also matrices: with number of rows/columns = 1).Suppose A and B are matrices of 3 rows and 4 columns.A+B // same sizes of A and B requiredA*B // Not defined. size(A,’c’) 6= size(B,’r’)A*B’ // dimensions allow multiplicationA+4 // understood as elementwise additionA*4 and 4*A // understood as elementwise multiplicationA•*B // understood as elementwise multiplication of matrices
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 21: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/21.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Multiplication and addition
(Vectors are also matrices: with number of rows/columns = 1).Suppose A and B are matrices of 3 rows and 4 columns.A+B // same sizes of A and B requiredA*B // Not defined. size(A,’c’) 6= size(B,’r’)A*B’ // dimensions allow multiplicationA+4 // understood as elementwise additionA*4 and 4*A // understood as elementwise multiplicationA•*B // understood as elementwise multiplication of matrices
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 22: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/22.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Multiplication and addition
(Vectors are also matrices: with number of rows/columns = 1).Suppose A and B are matrices of 3 rows and 4 columns.A+B // same sizes of A and B requiredA*B // Not defined. size(A,’c’) 6= size(B,’r’)A*B’ // dimensions allow multiplicationA+4 // understood as elementwise additionA*4 and 4*A // understood as elementwise multiplicationA•*B // understood as elementwise multiplication of matrices
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 23: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/23.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
for and if-then-end
v = -3:10 // vector from -3 to 20 (default increment 1)
v=1:2.3:10 // vector of ‘suitable length’
for i=1:10, // (or for i=v,)disp(i)
end
i==4 // check this for undefined i, for i=5 and i=4
if (true or false) thendo something
end
(else, elseif-else, etc possible)
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 24: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/24.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
for and if-then-end
v = -3:10 // vector from -3 to 20 (default increment 1)
v=1:2.3:10 // vector of ‘suitable length’
for i=1:10, // (or for i=v,)disp(i)
end
i==4 // check this for undefined i, for i=5 and i=4
if (true or false) thendo something
end
(else, elseif-else, etc possible)
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 25: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/25.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
for and if-then-end
v = -3:10 // vector from -3 to 20 (default increment 1)
v=1:2.3:10 // vector of ‘suitable length’
for i=1:10, // (or for i=v,)disp(i)
end
i==4 // check this for undefined i, for i=5 and i=4
if (true or false) thendo something
end
(else, elseif-else, etc possible)
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 26: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/26.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
commands into a file
Write all commands, etc in a file (using Notepad or Scilab-editor).sce extension recommendedexec filename or exec(’filename’,2) // does not echo your filefilename could be a ‘function’ : very important
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 27: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/27.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
commands into a file
Write all commands, etc in a file (using Notepad or Scilab-editor).sce extension recommendedexec filename or exec(’filename’,2) // does not echo your filefilename could be a ‘function’ : very important
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 28: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/28.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
function
Recommended .sci extensionfile1.sci (can have multiple functions with different function names)These names should not already exist!// —- file1.sci begins blah-blahfunction total = addition(a,b)total = a+bendfunction// — file1.sci endsScilab prompt:–¿ exec(’file1.sci’,2)–¿ q = addition(4,5)
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 29: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/29.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
eigenvalues (spectrum), trace
det(A), spec(A), trace(A)
sum prod
disp(i) (display i) or disp(’Text to be
displayed’)
rank, svd
find
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 30: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/30.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
eigenvalues (spectrum), trace
det(A), spec(A), trace(A)
sum prod
disp(i) (display i) or disp(’Text to be
displayed’)
rank, svd
find
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 31: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/31.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
eigenvalues (spectrum), trace
det(A), spec(A), trace(A)
sum prod
disp(i) (display i) or disp(’Text to be
displayed’)
rank, svd
find
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 32: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/32.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
plot and plot2d
x = 0:0.3:3
y = x•ˆ2 // elementwise squaring
plot(x) and plot(x,y) // independent, dependent-variable(s)
plot(x’,y’) // Now 2nd argument can have many columns
x = 0:0.3:3’; y2 = x•ˆ2; y3 = x•ˆ3;
plot(x, [y2 y3]),
plot2d(x, [y2 y3], [2, -4]) // help plot and plot2d
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 33: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/33.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
plot and plot2d
x = 0:0.3:3
y = x•ˆ2 // elementwise squaring
plot(x) and plot(x,y) // independent, dependent-variable(s)
plot(x’,y’) // Now 2nd argument can have many columns
x = 0:0.3:3’; y2 = x•ˆ2; y3 = x•ˆ3;
plot(x, [y2 y3]),
plot2d(x, [y2 y3], [2, -4]) // help plot and plot2d
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 34: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/34.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Defining polynomials
Polynomials play a very central role in control theory: the transferfunction is a ratio of two polynomials.Key commands:
• s=poly(0,’s’) • s=poly(0,’s’,’roots’)
• p=s^2+3*s+2 • p=poly([2 3 1],’s’,’coeff’)
• roots(p) • horner(p,5)
• a = [1 2 3] • horner(p,a) • horner(p,a’)
• w=poly(0,’w’) • horner(p,%i*w)
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 35: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/35.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Differentiation
p=poly([1 3 4 -3],’s’,’coeff’)
cfp=coeff(p) constant term first
diffpcoff=cfp(2:length(cfp)).*[1:length(cfp)-1]
diffp=poly(diffpcoff,’s’,’coeff’)
degree(p) can be used instead of length(cfp)-1
Of course, derivat(p)
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 36: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/36.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Differentiation
p=poly([1 3 4 -3],’s’,’coeff’)
cfp=coeff(p) constant term first
diffpcoff=cfp(2:length(cfp)).*[1:length(cfp)-1]
diffp=poly(diffpcoff,’s’,’coeff’)
degree(p) can be used instead of length(cfp)-1
Of course, derivat(p)
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 37: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/37.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Differentiation
p=poly([1 3 4 -3],’s’,’coeff’)
cfp=coeff(p) constant term first
diffpcoff=cfp(2:length(cfp)).*[1:length(cfp)-1]
diffp=poly(diffpcoff,’s’,’coeff’)
degree(p) can be used instead of length(cfp)-1
Of course, derivat(p)
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 38: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/38.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Differentiation
p=poly([1 3 4 -3],’s’,’coeff’)
cfp=coeff(p) constant term first
diffpcoff=cfp(2:length(cfp)).*[1:length(cfp)-1]
diffp=poly(diffpcoff,’s’,’coeff’)
degree(p) can be used instead of length(cfp)-1
Of course, derivat(p)
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 39: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/39.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Differentiation
p=poly([1 3 4 -3],’s’,’coeff’)
cfp=coeff(p) constant term first
diffpcoff=cfp(2:length(cfp)).*[1:length(cfp)-1]
diffp=poly(diffpcoff,’s’,’coeff’)
degree(p) can be used instead of length(cfp)-1
Of course, derivat(p)
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 40: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/40.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Differentiation
p=poly([1 3 4 -3],’s’,’coeff’)
cfp=coeff(p) constant term first
diffpcoff=cfp(2:length(cfp)).*[1:length(cfp)-1]
diffp=poly(diffpcoff,’s’,’coeff’)
degree(p) can be used instead of length(cfp)-1
Of course, derivat(p)
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 41: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/41.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
csv: comma separated values filewrite csv : writes data into a csv file.read csv : reads data from a csv file.horner find inv and pinvdft (+ and − 1: options compulsory!)Useful inbuilt variables:%i, %s, %z, %e, %epsa=5×10−3 : a = 5D-3also a = 5d-3 & 5e-3 & 5E-3Commands/variables are case sensitive!
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 42: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/42.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
csv: comma separated values filewrite csv : writes data into a csv file.read csv : reads data from a csv file.horner find inv and pinvdft (+ and − 1: options compulsory!)Useful inbuilt variables:%i, %s, %z, %e, %epsa=5×10−3 : a = 5D-3also a = 5d-3 & 5e-3 & 5E-3Commands/variables are case sensitive!
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 43: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/43.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
csv: comma separated values filewrite csv : writes data into a csv file.read csv : reads data from a csv file.horner find inv and pinvdft (+ and − 1: options compulsory!)Useful inbuilt variables:%i, %s, %z, %e, %epsa=5×10−3 : a = 5D-3also a = 5d-3 & 5e-3 & 5E-3Commands/variables are case sensitive!
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 44: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/44.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
csv: comma separated values filewrite csv : writes data into a csv file.read csv : reads data from a csv file.horner find inv and pinvdft (+ and − 1: options compulsory!)Useful inbuilt variables:%i, %s, %z, %e, %epsa=5×10−3 : a = 5D-3also a = 5d-3 & 5e-3 & 5E-3Commands/variables are case sensitive!
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 45: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/45.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
The command ‘find’
find([%T %F %T %F %T %F %F])gives ‘indices’ of TRUE’s.x=[4 5 6 7]x < 5.5true indices of x=find(x < 5.5)y=[5 6 7 8 9 0 -1]y(true indices of x)
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra
![Page 46: Control & Computing group Department of Electrical ...belur/scilab/virtual_labs_basic.pdf · Scilab provides all basic and many advanced tools. Signal processing, Control systems,](https://reader030.fdocuments.in/reader030/viewer/2022040402/5e80b97711ecc964701ded61/html5/thumbnails/46.jpg)
Outline Vectors/matrices Plotting if-then-else-end and for-end Polynomials Other useful commands
Conclusions
Matrices and polynomials provide rich source of problems
Due to good (and cheap/free) computational tools availablecurrently, the future lies in computational techniques
Scilab provides powerful tools
We saw: for horner poly coeff roots find
Madhu Belur, CC group, EE, IITB Scilab/Linear Algebra