Simultaneous Equation With Matrices
Simultaneous Equation With Matrices
Simultaneous Equation With Matrices
𝐴𝑋 = 𝐵
There are two methods to solve the simultaneous equations with matrices,
we use in this lecture:
𝑋 = 𝐴−1 𝐵
1
Therefore, we can use formula above to solve any set of
simultaneous equations that have solutions. We will refer to this method
as the inverse matrix method of solution of simultaneous equations.
2𝑥1 + 3𝑥2 + 𝑥3 = 9
{𝑥1 + 2𝑥2 + 3𝑥3 = 6}
3𝑥1 + 𝑥2 + 2𝑥3 = 8
Compute the unknowns x1, x2 and x3 using the inverse matrix method.
Solution:
2 3 1 𝑥1 9
𝐴 = [1 2 3] , 𝑋 = [𝑥2 ] , 𝐵 = [ 6]
3 1 2 𝑥3 8
Then,
𝑋 = 𝐴−1 𝐵
𝑥1 2 3 1 −1 9
[𝑥2 ] = [1 2 3] [6]
𝑥3 3 1 2 8
In MATLAB
2
A=[231;123;312];
B=[9;6;8];
X = A\ B
or
X = inv (A) * B
Ex.2\ For the electric circuit of Figure below, the mesh equations are:
10𝐼1 − 9𝐼2 = 100
−9𝐼1 + 20𝐼2 − 9𝐼3 = 0
−9𝐼2 + 15𝐼3 = 0
Use the inverse matrix method to compute the values of the currents I1, I2
and I3.
Solution:
10 −9 0 100 𝐼1
𝑅 = [−9 20 −9] , 𝑉 = [ 0 ], 𝐼 = [𝐼2 ]
0 −9 15 0 𝐼3
Then,
𝐼 = 𝑅−1 𝑉
3
𝐼1 10 −9 0 −1 100
[𝐼2 ] = [−9 20 −9] [ 0 ]
𝐼3 0 −9 15 0
In MATLAB
R = [ 10 -9 0 ; -9 20 -9 ; 0 -9 15 ] ;
V = [ 100 ; 0 ; 0 ] ;
I = R\V
or
I =inv (R) * V
and let
Cramer’s rule states that the unknowns x, y and z can be found from the
relations
𝑑𝑒𝑙𝑡𝑎 = [𝑎11 𝑎12 𝑎13 ; 𝑎21 𝑎22 𝑎23 ; 𝑎31 𝑎32 𝑎33 ];
4
𝐷1 = [𝐴 𝑎12 𝑎13 ; 𝐵 𝑎22 𝑎23 ; 𝐶 𝑎32 𝑎33 ];
𝐷2 = [𝑎11 𝐴 𝑎13 ; 𝑎21 𝐵 𝑎23 ; 𝑎31 𝐶 𝑎33 ];
𝐷3 = [𝑎11 𝑎12 𝐴; 𝑎21 𝑎22 𝐵; 𝑎31 𝑎32 𝐶];
𝑥 = det(𝐷1 ) /det(𝑑𝑒𝑙𝑡𝑎)
𝑦 = det(𝐷2 ) /det(𝑑𝑒𝑙𝑡𝑎)
𝑧 = det(𝐷3 ) /det(𝑑𝑒𝑙𝑡𝑎)
Ex.3\ Use Cramer’s rule to find v1, v2 and v3 for the following equation
system:
2𝑣1 − 5 − 𝑣2 + 3𝑣3 = 0
−2𝑣3 − 3𝑣2 − 4𝑣1 = 8
𝑣2 + 3𝑣1 − 4 − 𝑣3 = 0
Solution:
2𝑣1 − 𝑣2 + 3𝑣3 = 5
−4𝑣1 − 3𝑣2 − 2𝑣3 = 8
3𝑣1 + 𝑣2 − 𝑣3 = 4
2 −1 3 5 −1 3 2 5 3
∆= [−4 −3 −2] 𝐷1 = [8 −3 −2] 𝐷2 = [−4 8 −2] 𝐷3
3 1 −1 4 1 −1 3 4 −1
2 −1 5
= [−4 −3 8]
3 1 4
5
In MATLAB
delta = [ 2 -1 3 ; -4 -3 -2 ; 3 1 -1 ] ;
D1 = [ 5 -1 3 ; 8 -3 -2 ; 4 1 -1 ] ;
D2 = [ 2 5 3 ; -4 8 -2 ; 3 4 -1 ] ;
D3 = [ 2 -1 5 ; -4 -3 8 ; 3 1 4 ] ;
v1 = det (D1) / det (delta)
v2 = det (D2) / det (delta)
v3 = det (D3) / det (delta)
Homework
1- Input Commands:
6
These commands used to identify the values of variable in the
program.
Identify Variable:
𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒_𝑛𝑎𝑚𝑒 = 𝑣𝑎𝑙𝑢𝑒
Ex.1\ N = 4
B = 25.77
Na =’MATLAB’
Ex.2\ A = 1:5
C = 2:-1:-3
(Input) Command:
𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒_𝑛𝑎𝑚𝑒 = 𝑖𝑛𝑝𝑢𝑡(′𝑡𝑒𝑥𝑡 ′ )
solution:
a=input('value of a ?');
b=input('value of b ?');
7
R=sqrt(a^2+b)+sin(pi)
value of a ?30
value of b ?15
R=
30.2490
2- Output Commands:
(Display) Command:
𝑑𝑖𝑠𝑝(′𝑡𝑒𝑥𝑡 ′ )
𝑑𝑖𝑠𝑝(𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒)
Ex.4\ Find the value of y from the following equation with explanatory
words print about result.
𝑦 = 𝑏 2 − 2𝑎𝑐 𝑖𝑓 𝑏 = 3, 𝑎 = 3 & 𝑐 = 1
solution:
a=input('value of a ?');
b=input('value of b ?');
c=input('value of c ?');
y=b^2-2*a*c;
disp('Result of y is'),disp(y)
value of a ?3
value of b ?3
value of c ?1
Result of y is