Activity 1
Activity 1
Activity 1
Ditucalan
Course and Year: BS ECE 4th
EE 179.1 Section: M456
Laboratory Schedule: 1:00PM 4:00PM M
1 Objectives
2 List of equipment/software
vPersonal Computer
Installation of SCILAB
3.1 Variable
In Scilab, you can easily create and instantiate variables anytime. Unlike the C
language, Scilabs variables are dynamic and dont have to be created before they
are stored with values.
Open you Scilab now and try the following in the console.
--> clear
--> a = 1
The console should respond with the value of a. Now, after the above command, try
doing the following:
--> b = a
The console should respond with the value of b which is just the value of a in the
previous command.
with
[ ]
1 2 3
4 5 6
7 8 9
3.2 Operators
Scilab has a lot of operators in addition to basic arithmetic operations. Since Scilab
operates on matrices by default, basic arithmetic operations are applied on
matrices.
Operat
or
+
*
/
\
^
Description
Matrix addition
Matrix subtraction
Matrix Multiplication
Matrix division.
A / B= AB1
Matrix back-division.
A = A1B
Matrix exponential.
Transpose
If you want element-wise operation using those operators, the operator is preceded
with a .
--> a = [1, 2; 3, 4]
--> b = [3, 4; 5, 6]
--> a + b
ans =
4.
6.
8.
10.
4. Do a matrix multiplication and element-wise multiplication on a and b.
What are the results? Are the results equal?
9. Call the function you created in #8 and pass as parameters the values 3
and 9. What is the result?
10. What will your function return if the parameters are [1,2,3] and [4;
6;7]?
11. How about [1, 2, 3 ; 3, 5, 1; 5 6 -1] and [3, -1, 4 ; -3, 5, 1; -5 6 -1]?
2. What will you enter in the command line if you want to assign a_matrix
with
[ ]
1 2 3
4 5 6
7 8 9
a_matrix = [ 1 2 3; 4 5 6; 7 8 9]
Matrix multiplication:
Element-wise:
3 8
15 24
13 16
29 36
[ ]
1 3
2 4
What is the result or the behavior of the above statements in the console
after executing the script?
The first line declares an array of floating numbers representing 0 rad to 2
pi rad with intervals of 0.1 rad. For the 2nd line, we declare a string
variable and for the 3rd line, a plot function is executed with a as the xaxis and sin(2*a) as y-axis in a rectangular plane.
8. Write a function called myfunct that accepts two parameters A and B.
The function will return the result of (A+B)*B. Execute the script what is
the result?
//start of program
function [R]=myfunct(A, B)
R = (A+B)*B
endfunction
9. Call the function you created in #8 and pass as parameters the values 3
and 9. What is the result?
108.
10. What will your function return if the parameters are [1,2,3] and [4;
6;7]?
-->myfunct([1,2,3],[4;6;7])
!--error 8
Inconsistent addition.
at line
myfunct([1,2,3],[4;6;7])
11. How about [1, 2, 3 ; 3, 5, 1; 5 6 -1] and [3, -1, 4 ; -3, 5, 1; -5 6 -1]?
-->myfunct([1,2,3;3,5,1;5,6,-1],[3,-1,4;-3,5,1;-5,6,1])
ans =
- 26.
43.
10.
- 40.
62.
8.
- 36.
60.
14.
4 Conclusion
As to my experience in using MatLab, SciLab is pretty much the same with
MatLab. SciLab offers functions and variable handling capabilities, same as
MatLab does, which enables us to perform mathematical task and numerical
method techniques. SciLab is capable in handling arrays and matrices which is
vital in numerical method, finding a solution of an equation,etc. Furthermore, we
can declare a symbolic variable (same as in MatLab) which gives us more
mathematical features like finding roots, poles and zeros, partial fractions and
more.
SciLab is of great help in simulating systems that we will use and analyze in
EE 179. We can simplify directly a frequency domain representation of using the
symbolic variable along with the arithmetic functions available in SciLab.
Frequency domain representation can then be transformed back into time
domain by hand but not if we have a complicated frequency domain
representation. In order to simplify this, we have to do partial fraction
expansion which can be readily solved by the pfss function in SciLab. We can
also convert our transfer function to State-space representation and vice-versa
like tf2ss and ss2tf.