Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Marking

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 20

BAZE UNIVERSITY, ABUJA

Department of Electrical & Computer Engineering

ELECTRICAL AND ELECTRONICS ENGINEERING LABORATORY PRACTICALS


LABORATORY MANUAL

Course Title & Code:

Department:

Name of Student:

Student ID No:

Year/Trimester:

Date of Experiment:

Name of Lecturer: -------------------------------------------------------------------------

EXPERIMENT NO. A
OBJECTIVE: STUDY OF BASIC MATRIX OPERATIONS

APPARATUS/ SOFTWARE REQUIRED:

SR.NO APPARATUS/SOFTWARE SPECIFICATION QUANTITY

GIVEN NUMERICAL:

A= 3 2 1
0 3 4
-1 1 -1

B= 1 3 0

2 6 4
-1 0 2
Where A and B are two 3 X 3 matrix

COMMANDS:

>> A= [3 2 1; 0 3 4; -1 1 -1]
>> B= [1 3 0; 2 6 4; -1 0 2]

Sum: A+ B
Subtraction: A–B
Multiplication: A*B
Division: A/B or A\B
Inverse of A: inv(A)

Exercises
Given.
1. A=5 3 4
9 18 2
6 7 1
B=7 4 3
1 0 2
-9 -7 8
Result
>> A=[5 3 4;9 18 2;6 7 1]

A=

5 3 4
9 18 2
6 7 1

>> B=[7 4 3;1 0 2;-9 -7 8]

B=

7 4 3
1 0 2
-9 -7 8

>> A+B

ans =

12 7 7
10 18 4
-3 0 9

>> A-B

ans =

-2 -1 1
8 18 0
15 14 -7

>> A*B

ans =

2 -8 53
63 22 79
40 17 40

>> A/B

ans =
1.3333 -1.3333 0.3333
13.1852 -38.6296 4.9630
3.8889 -10.2222 1.2222

>> inv(A)

ans =

-0.0265 -0.1656 0.4371


-0.0199 0.1258 -0.1722
0.2980 0.1126 -0.4172

>> inv(B)

ans =

-0.5185 1.9630 -0.2963


0.9630 -3.0741 0.4074
0.2593 -0.4815 0.1481

>> inv(A)+inv(B)

ans =

-0.5450 1.7974 0.1408


0.9431 -2.9482 0.2352
0.5573 -0.3689 -0.2691

>> inv(A)*inv(B)

ans =

-0.0324 0.2465 0.0052


0.0868 -0.3429 0.0316
-0.1543 0.4398 -0.1042
2. C=4 5 2
8 9 10
11 14 2
D=13 25 2
0 1 8
9 10 13
Result
>> C=[4 5 2;8 9 10;11 14 2]

C=

4 5 2
8 9 10
11 14 2
>> D=[13 25 2;0 1 8;9 10 13]

D=

13 25 2
0 1 8
9 10 13

>> C+D

ans =

17 30 4
8 10 18
20 24 15

>> C-D

ans =

-9 -20 0
8 8 2
2 4 -11

>> C*D

ans =

70 125 74
194 309 218
161 309 160

>> C/D

ans =

0.0812 -0.3019 0.3271


0.0241 -0.1438 0.8540
0.2777 -1.1537 0.8211

>> inv(C)

ans =

-15.2500 2.2500 4.0000


11.7500 -1.7500 -3.0000
1.6250 -0.1250 -0.5000

>> inv(D)
ans =

-0.0735 -0.3348 0.2173


0.0790 0.1658 -0.1142
-0.0099 0.1043 0.0143

>> inv(C)+inv(D)

ans =

-15.3235 1.9152 4.2173


11.8290 -1.5842 -3.1142
1.6151 -0.0207 -0.4857

>> inv(C)*inv(D)

ans =

1.2599 5.8957 -3.5143


-0.9728 -4.5368 2.7108
-0.1245 -0.6169 0.3603

>> 1.2599 5.8957 -3.5143


-0.9728 -4.5368 2.7108
-0.1245 -0.6169 0.3603
2. E=8 9 10 12
7 8 5 6
-6 4 9 5
F=-9 10 -11 13
7 8 5 6
8 4 9 15
Result
>> E=[8 9 10 12;7 8 5 6;-9 10 -11 13]

E=

8 9 10 12
7 8 5 6
-9 10 -11 13

>> F=[-9 10 -11 13;7 8 5 6;8 4 9 15]

F=

-9 10 -11 13
7 8 5 6
8 4 9 15

>> E+F
ans =

-1 19 -1 25
14 16 10 12
-1 14 -2 28

>> E-F

ans =

17 -1 21 -1
0 0 0 0
-17 6 -20 -2

>> E*F
Error using *
Inner matrix dimensions must agree.

>> E/F

ans =

0.0005 0.8024 0.4949


-0.0000 1.0000 -0.0000
1.0000 0.0000 -0.0000

>> inv(E)
Error using inv
Matrix must be square.
>> inv(F)
Error using inv
Matrix must be square.

>> inv(E)+inv(F)
Error using inv
Matrix must be square.

>> inv(E)*inv(F)
Error using inv
Matrix must be square.

>>
3. G = 15 16 21 25
13 10 11 9
7 8 6 0
H= 0 -1 -7 -9
10 -5 -8 -10
10 12 -15 -20
Result
>> G=[15 16 21 25;13 10 11 9;7 8 6 0]

G=

15 16 21 25
13 10 11 9
7 8 6 0

>> H=[0 -1 -7 -9;10 -5 -8 -10;11 12 -15 -20]

H=

0 -1 -7 -9
10 -5 -8 -10
11 12 -15 -20

>> G+H

ans =

15 15 14 16
23 5 3 -1
18 20 -9 -20

>> G-H

ans =

15 17 28 34
3 15 19 19
-4 -4 21 20

>> G*H
Error using *
Inner matrix dimensions must agree.

>> G/H

ans =

-5.5296 0.3684 1.0284


-3.3949 0.4691 0.7542
-1.6523 0.0700 0.5710

>> inv(G)+inv(H)
Error using inv
Matrix must be square.
>> inv(G)*inv(H)
Error using inv
Matrix must be square.

>>

4. K= 22 3 7
4 2 3
654
M= 1 3 5
246
2 67
Result
>> K=[22 3 7;4 2 3;6 5 4]

K=

22 3 7
4 2 3
6 5 4

>> M=[1 3 5;2 4 6;2 6 7]

M=

1 3 5
2 4 6
2 6 7

>> K+M

ans =

23 6 12
6 6 9
8 11 11

>> K-M

ans =

21 0 2
2 -2 -3
4 -1 -3

>> K*M

ans =
42 120 177
14 38 53
24 62 88

>> K/M

ans =

-25.6667 31.5000 -7.6667


-4.0000 5.0000 -1.0000
-7.0000 6.5000 0

>> inv(K)

ans =

0.0761 -0.2500 0.0543


-0.0217 -0.5000 0.4130
-0.0870 1.0000 -0.3478

>> inv(M)

ans =

-1.3333 1.5000 -0.3333


-0.3333 -0.5000 0.6667
0.6667 0 -0.3333

>> inv(K)+inv(M)

ans =

-1.2572 1.2500 -0.2790


-0.3551 -1.0000 1.0797
0.5797 1.0000 -0.6812

>> inv(K)*inv(M)

ans =

0.0181 0.2391 -0.2101


0.4710 0.2174 -0.4638
-0.4493 -0.6304 0.8116
FOR EACH OF THE EXERCISES ABOVE FIND:
(a) Sum: A+ B
(b) Subtraction: A–B
(c) Multiplication: A*B
(d) Division: A/B or A\B
(e) Inverse of A: inv(A)
(f) Inverse of B inv(B)
(g) Inverse addition inv(A) + inv(B)
(h) Inverser multiplication inv(A)*inv(B)

Important note; copy ALL YOUR WORK FROM MATLAB COMMAND WINDOR AND PASTE IN
YOUR REPORT.

CONCLUSION:

POST- EXPERIMENTAL QUESTION


Q1. What is a Matrix?

Q2. What is the dimension of a matrix? Q3.


What are the elements of a matrix? Q4.
What is a square matrix?
Q6. What are the basic matrix operations? Q7.
What is the Transpose of a matrix?
Q8. What are the commands in MATLAB to solve the various basic matrix
operations?
EXPERIMENT NO.B
OBJECTIVE: TO SOLVE LINEAR EQUATION

APPARATUS/ SOFTWARE REQUIRED:

SR.NO APPARATUS/SOFTWARE SPECIFICATION QUANTITY


THEORY:

LINEAR EQUATION:

Solving a linear algebraic equation is easy in MATLAB. It is, perhaps, also the most used
computation in science and engineering. We will solve a set of linear algebraic equations
given below:
5x= 3y-2z+10
8y+4z= 3x+20
2x+4y-9z=9

PROCEDURE:

STEP 1: Rearrange equations: Write each equation with all unknown quantities on the left
hand side and all known quantities on the right hand side. Thus, for the equations given
above, rearrange them such that all terms involving x, y, and z are on the left hand side of
the equal sign:

5x-3y+2z = 10
-3x+8y+4z = 20
2x+4y-9z = 9
STEP 2: Write the equations in matrix form: To write the equation in the matrix form [A]
{x}={b} where {x} is the vector of unknowns, we have to arrange the unknowns in matrix A
and the constants on the right hand side of the equations in vector b.
In this particular example, the unknown vector is
XYZ
A=XYZ
XYZ
The coefficient matrix is
5 -3 2
A= -3 8 4
2 4 -9
And the known constant vector is
10
B = [20].
9
Note that the columns of A are simply the coefficients of each unknown from
all the three equations.

STEP 3: Solve the matrix equation in MATLAB: Enter the matrix A and vector B,
and solve for vector x with x=A\B (note that the \ is different from the
division /):

>> A= [5 -3 2; -3 8 4; 2 4 -9]; % enter matrix A


10
>> B=[20].; % enter column vector b
9

CONCLUSION:
Exercise
Write a program
1. 10x – 15y +8 = 10z
15y + z = 10 -13x
12x + y = 13z +9

2. 13z – 7 -10y +10x =0


9 = x +20z -13y
12x +9y -20z =15
3. 5x + 6y +z =6
X +13y +10z =8
8x +y +9z = 7
4. 6x+4z+0=y
8y+4x+3z=4
5z+12+15x+4y=1
5. X+y+z=3
7z+3y+x=5
6x+4y+2z=8

1. 10x-15y-10z=-8
13x+15y+z=10
12x+y-13z=9
>> A=[10 -15 -10;13 15 1;12 1 -13]

A=

10 -15 -10
13 15 1
12 1 -13

>> B=[-8;10;9]
B=

-8
10
9

>> x=A\B;
>> c=A*x

c=

-8.0000
10.0000
9.0000

2. 10x-10y+13z=7
x-13y+20z=9
12x+9y-20z=15
Result
>> A=[10 -10 13;1 -13 20;12 9 -20]

A=

10 -10 13
1 -13 20
12 9 -20

>> B=[7;9;15]

B=

7
9
15

>> x=A\B;
>> c=A*x

c=

7.0000
9.0000
15.0000
3. 5x + 6y + z =6
X +13y +10z =8
8x +y +9z = 7
Result
>> A=[5 6 1;1 13 10;8 1 9]

A=

5 6 1
1 13 10
8 1 9

>> B=[6;8;7]

B=

6
8
7

>> x=A\B;
>> c=A*x

c=

6
8
7

4. 6x-y+4z=0
-4x-8y+3z=4
-15x+4y-5z=1
Result
>> A=[6 -1 4;-4 -8 3;-15 4 -5]

A=

6 -1 4
-4 -8 3
-15 4 -5
>> B=[-0;4;1]

B=

-0
4
1

>> x=A\B;
>> c=A*x

c=

-0.0000
4.0000
1.0000

5. x+y+z=3
-x-3y-7z=5
6z+4y+2z=8
Result
>> A=[1 1 1;-1 -3 -7;6 4 2]

A=

1 1 1
-1 -3 -7
6 4 2

>> B=[3;5;8]

B=

3
5
8

>> x=A\B;
>> c=A*x

c=

3.0000
5.0000
8.0000

You might also like