Engineering Workshop 2 (Beee1313)
Engineering Workshop 2 (Beee1313)
[email protected],
LESSON OUTCOMES
At the end of this lesson, you should be able to:
1. Understand the concept of a matrix and array
2. Understand with the basic matrix manipulation and notation in MATLAB
3. Perform basic matrix algebra
4. Apply matrix for solving engineering application.
5. Understand the concept of graph plotting in MATLAB
6. Apply graph plotting to display graph related to engineering application.
7. Familiarize the SIMULINK environment
8. Perform basic SIMULINK simulation related to engineering application
9. Apply SIMULINK for solving engineering application.
MATLAB MATRIX
1. In Mathematics, a matrix is collection of numerical values
that are organized in terms of rows and columns.
2. A matrix can be express in MATLAB by by typing each
element of a row, row by row, with a space or a comma
separating the consecutive elements in a row, and
semicolons to separate consecutive rows of a matrix.
7
3. Example, 𝑥 = [1 9 −10ሿ and y = 4 can expressed in
2
MATLAB using the following MATLAB command (refer Fig. 1):
>> x = [1 9 -10] % Or x = [1, 9, -10]
>> y = [7; 4; 2] Fig 1. Example matrix in MATLAB
MATLAB MATRIX
4. A few more example to help you get the hang of the concept,
given 𝑎 = 1 2 3 and 𝑏 = 1 2 can be written (refer Fig. 2):
4 5 6 3 4
>> a = [1 2 3; 4 5 6]
>> b = [1 2; 3 4]
5. There also two commands to help you out in manipulating
the matrix that you created in MATLAB. The commands are:
• size()command will return the size of the matrix
• length()command will return the largest dimension
of the matrix
Fig 2. Example matrix in MATLAB
MATLAB MATRIX
6. By taking the earlier example where 𝑎 = 1 2 3 and 𝑏 = 1 2 ,
4 5 6 3 4
writing the command size(a) will return two numerical values:
2 and 3 which means 2 is the number of rows and 3 is the number
of columns in matrix a (refer Fig. 3).
7. Then, if you try writing down command size(b), MATLAB will
return the values of 2 and 2 which means matrix b has 2 columns
and rows (refer Fig. 3).
8. As stated earlier the command length(a) will return the
largest dimension of the matrix. For matrix a, the value will be 3
because the largest dimension of matrix a is its column which is 3.
While length(b) will return 2 as both column and row of
matrix b is 2 (refer Fig. 3). Fig 3. Example function
size and length
MATLAB ARITHMETICS
9. MATLAB can perform all basic mathematical arithmetic for matrix that you can
think of. Table 1 shows the list of the mathematical operation that we will try
out later. Let say we have wrote z = [1 2; 3 4];
Table 1. Basic MATLAB arithmetic commands
Symbol Operation Example Answer
A =
+ Addition A = Z + Z 2 4
6 8
A =
- Subtraction A = Z - Z 0 0
0 0
A =
A = Z * Z
* Multiplication 7 10
15 22
A =
.’ Transpose A = Z.’ 1 3
2 4
MATLAB ARITHMETICS
10. On top of that, Table 2 listed additional functions that are commonly used.
𝑇
B =
transpose(a) Transpose B = transpose([1 2; 3 4]) 1 2 1 3
𝐵=
3 4 2 4
𝐵 B =
det(a) Determinant B = det([1 2; 3 4]) 1 2 𝑇
= det( ) -2
3 4
MATLAB MATRIX
11. Now, let see how we can apply what we had learned in solving electrical circuit.
Hopefully, you still can recall what you have learned in ECF & Technical Mathematics.
Figure A shows an electrical circuit consists of several resistors. Find 𝐼1 , 𝐼2 and 𝐼3 for the given
electrical circuit
title(‘Sine Waveform’):
display tittle with given sentences
legend(‘Sine’):
display legend with
given sentences
ylabel(‘Output’: display
grid ON: turn ON the
the label for y-axis with given
sentences grid for the graph
xlabel(‘Angle(radian)’:
display the label for x-axis with
given sentences
Fig 5. Plotting sine wave on MATLAB
MATLAB GRAPH PLOTTING
9. Another cool feature of MATLAB graph plotting is you can plot more than one output
in a single graph. Let just say we want to plot cosine and sine wave together in one
graph, the command as follows
>> a = [0:pi/180:2*pi];
>> y = sin(a); z = cos(a);
>> plot(a,y,’red’); hold;
>> plot(a,z,’blue’); grid ON
>> legend(‘Sine’, ‘Cosine’);
>> title(‘Trigonometry Waveforms’);
>> xlabel(‘Angle (radian)’);
>> ylabel(‘Output’);
Fig 5. Plotting sine and cosine wave on
a single figure
MATLAB GRAPH PLOTTING
10. Let us try out what we had learned earlier in the following engineering application:
Based on the circuit connection shown in Figure A, Ir. Ts. Syahrin decides to create his own
MATLAB program that plot the values of Voltage across capacitor, 𝑉𝑐 for defined time (𝑡)
during the charging phase. Values of Voltage Supplied (𝑉𝑠 ) is 240 V, Resistance (𝑟) is 5 kΩ,
Capacitance (C) is 0.6 µF, and time (𝑡) from 0 µs to 20,000 µs with interval time of 1 µs.
4th Order: 𝑦 𝑡 = −4 + (𝑡 − 1) 2
2nd Order:(𝑡 − 1) 2
1st Order: 𝑡 − 1
3rd Order:−4 + (𝑡 − 1) 2