Marking
Marking
Marking
Department:
Name of Student:
Student ID No:
Year/Trimester:
Date of Experiment:
EXPERIMENT NO. A
OBJECTIVE: STUDY OF BASIC MATRIX OPERATIONS
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
>> 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 =
>> inv(B)
ans =
>> inv(A)+inv(B)
ans =
>> inv(A)*inv(B)
ans =
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 =
>> inv(C)
ans =
>> inv(D)
ans =
>> inv(C)+inv(D)
ans =
>> inv(C)*inv(D)
ans =
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
>> 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 =
>> 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
>> 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 =
>> 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
>> 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 =
>> inv(K)
ans =
>> inv(M)
ans =
>> inv(K)+inv(M)
ans =
>> inv(K)*inv(M)
ans =
Important note; copy ALL YOUR WORK FROM MATLAB COMMAND WINDOR AND PASTE IN
YOUR REPORT.
CONCLUSION:
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 /):
CONCLUSION:
Exercise
Write a program
1. 10x – 15y +8 = 10z
15y + z = 10 -13x
12x + y = 13z +9
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