Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

8_Programming with MATLAB[1]

Uploaded by

Ertan Akçay
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

8_Programming with MATLAB[1]

Uploaded by

Ertan Akçay
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 22

PROGRAMMING WITH MATLAB

LINEAR ALGEBRAIC EQUATIONS

ANKARA UNIVERSITY
DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING
LINEAR ALGEBRAIC EQUATIONS

◾ Consider the two equations ax + by = c and dx + ey = f.


◾ These equations represent two lines in the xy-plane.
◾ The simultaneous solution of these two equations (i.e. those points (x,y) that
satisfy both equations) is the intersection of the two lines.

2
LINEAR ALGEBRAIC EQUATIONS

For example,
The equations
6x – 10y = 2
3x – 4y = 5
have graphs that intersect at the
solution: y = 4, x = 7.

3
LINEAR ALGEBRAIC EQUATIONS

Another Example:
3x - 4y = 5
6x - 8y = 3
It has no solution.
The graphs of these two equations are distinct
but parallel.
They do not intersect  No solution exists.

4
LINEAR ALGEBRAIC EQUATIONS
◾ For 2 Equations and 2 Unknowns, the solution is the intersection of the two lines.
◾ For 3 Equations and 3 Unknowns, the solution is the intersection of three planes.

5
LINEAR ALGEBRAIC EQUATIONS
◾ Consider the following set of homogeneous equations (which means that their
right sides are all zero)
6x + ay = 0
2x + 4y = 0
where a is a parameter. Multiply the second equation by 3 and subtract the result
from the first equation to obtain
(a - 12)y = 0
◾ The solution is y = 0 only if a ≠ 12.
◾ If a = 12, there is an infinite number of solutions for x and y, where x = -2y. 6
LINEAR ALGEBRAIC EQUATIONS
◾ It is often convenient to represent a system of equations as a matrix equation.
◾ Matrix notation enables us to represent multiple equations as a single matrix equation.
◾ Consider the system of equations:
2x1 + 9x2 = 5
3x1 - 4x2 = 7
◾ This set can be expressed in vector-matrix form as
2 x1 
5
9 x2 7
3 4
which can be represented in the following compact form

Ax = b 7
LINEAR ALGEBRAIC EQUATIONS

◾ For square systems of equations (i.e. the number of equations and the unknowns
are equal), the most powerful tool to determine the number of solutions the system
has is determinant:
◾ For the equation set Ax = b,
◾ if |A| = 0, then there is no unique solution.
◾ A n x n nonhomogeneous system of linear equations has a unique solution if and
only if its determinant is non-zero (det(A) command).

8
𝑎𝑥+𝑏𝑦
The simplest form of two equations:

𝑑𝑥+𝑒𝑦
=𝑐

=𝑓
Write in vector-matrix form:

Solve for solution vector 𝑧 by multiplying both sides by 𝐴−1 (Inverse of A


(Matrix)) :

9
MATLAB:
◾ The MATLAB command inv(A) computes the inverse of the matrix A. The
following MATLAB session solves the following equations using MATLAB.
2x + 9y = 5
3x - 4y = 7
>>A = [2,9;3,-4];b = [5;7]
>>x = inv(A)*b OR

x = >> x = A\b
x =
2.3714 2.3714
0.0286
0.0286
◾ If you attempt to solve for an A matrix whose determinant is zero, the inv command 10

in
EXISTENCE AND UNIQUENESS OF SOLUTIONS
◾ The set Ax = b with m equations and n unknowns has solutions if and only

if rank[A] = rank[A b]
◾ If rank[A] ≠ rank[A b], a Unique Solution Does Not Exist
◾ If rank[A] = rank[A b] = Number of Unknowns, a Unique Solution Exists
◾ If rank[A] = rank[A b] but rank[A] ≠ Number of an Infinite Number of Solutions
Unknowns, Exist

11
WHAT IS RANK?
Find the rank of the given
matrix.

Now, we transform matrix A to echelon form by using elementary


transformation.
R2 → R2 –
2R1 R3 → R3
– 3R1

R3 → R3 –
R2

12
Number of non-zero rows = 2
Hence, the rank of matrix A =
EXISTENCE AND UNIQUENESS OF SOLUTIONS

% One Unique Solution:


% x-y = -1, 3x+y = 9
A = [1 -1; 3 1];
B = [-1; 9];
AB = [A B];
rank_A = rank(A);
rank_AB = rank(AB);
Det_A = det(A);
Inv_A = inv(A);
z = Inv_A*B
13
UNDER-DETERMINED SYSTEMS

◾ An under-determined system does not contain enough information to solve for


all of the unknown variables.

14

Solve Under-Determined Systems using Pseudo-Inverse pinv


UNDER-DETERMINED SYSTEMS

% pseudo inverse: Used When There are More Unknowns than


Equations
% x+3y-5z = 7, -8x-10y+4z = 28
A = [1 3 -5; -8 -10 4];
B = [7; 28];
AB = [A B];
rank_A = rank(A);
rank_AB = rank(AB);
z= pinv(A)*B

15
OVER-DETERMINED SYSTEMS

◾ More Independent Equations than Unknowns.


◾ For such a system the matrix inverse method will not
work because the A matrix is not square.
◾ However, some overdetermined systems have exact
solutions, and they can be obtained with the left division
method x = A\b.
◾ If rank[A] = rank[A b], A Unique Solution Exists: Use
Left Division Method to find the Solution: z = A\B
◾ If rank[A] ≠ rank[A b], No Solution Exists: The Left
Division Method gives a Least-Squares Solution, NOT
16
an Exact Solution.
OVER-DETERMINED SYSTEMS

% Over-Determined System:
% 4x+3y = 7; x-2y = -1; 3x+5y = 8
A = [4 3; 1 -2; 3 5];
B = [7; -1; 8];
AB = [A B];
rank_A = rank(A)
rank_AB = rank(AB)
z= A\B

17
OVER-DETERMINED SYSTEMS

% Over-Determined System:
% 4x+3y = 6; x-2y = -1; 3x+5y = 8
A = [4 3; 1 -2; 3 5];
B = [6; -1; 8];
AB = [A B];
rank_A = rank(A)
rank_AB = rank(AB)
z= A\B

18
EXAMPLE #1
◾ Consider the following 2 x 2 system of equations:

𝑥1 + 2𝑥2 = 3
𝑥1 − 2𝑥2 = 3
Find the intersect point.
Let's write these equations in the form y = mx + b.
𝑦 = −0.5𝑥 + 1.5
𝑦 = 0.5𝑥 − 1.5
We can plot these straight-line equations in MATLAB:
x = -5:5;
y1 = -0.5*x + 1.5; The intersection of the lines is the point
(3,0) 19

y2 = 0.5*x - 1.5;
plot(x, y1, x, y2)
Alternative way to solve Example #1:

Write this system of equations in matrix form: A x =


b
1 x1 
3
2 x2 3
1 -
2

A = [1,2;1,-2];
b = [3;3];
x = inv(A)*b
x =

3
0

20
EXAMPLE #2
◾ Consider the following 2 x 2 system of equations:
y1 = (6 - 4x) / 5
y2 = (14 - 4x) / 5
Find x.

21
EXAMPLE #3

y1 = (-4x + 6)/5;
y2 = (3x -14)/2;
y3 = 7x - 25;
Find x.

22

You might also like