Download Solutions to Systems of Linear Equations

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Surge protector wikipedia , lookup

Opto-isolator wikipedia , lookup

Rectiverter wikipedia , lookup

Nanofluidic circuitry wikipedia , lookup

Ohm's law wikipedia , lookup

Mathematics of radio engineering wikipedia , lookup

Two-port network wikipedia , lookup

Network analysis (electrical circuits) wikipedia , lookup

Transcript
ECE 1010 ECE Problem Solving I
Solutions to
Systems of Linear
Equations
5
Overview
In this chapter we studying the solution of sets of simultaneous
linear equations using matrix methods. The first section considers the graphical interpretation of such solutions.
Graphical Interpretation
• In engineering problem solving the need to solve a set of
simultaneous linear equations arises frequently
– Note: We keep specializing the system of equations to linear equations since in the modeling of large systems, linear approximations are a reasonable first approach and in
many cases sufficient for design purposes
• To develop an appreciation for what is really happening when
we ask the computer solve a set of simultaneous linear equations, we will explore graphical solutions first
Chapter 5: Overview
5–1
ECE 1010 ECE Problem Solving I
A Pair of Linear Equations with Two Unknowns
• In the x-y plane we can write
y = m1 x + b1
(5.1)
y = m2 x + b2
• We know that m is the slope and b is the y-intercept
y
y = mx + b
x
b
• Depending upon how m 1, m 2, b 1 and b 2 are chosen, the lines
will
– Intersect at a point if m 1 ≠ m 2
– Be parallel to one another if m 1 = m 2 , but b 1 ≠ b 2
– Be the same line if m 1 = m 2 and b 1 = b 2
Parallel
y
y
x
Same Line
y
x
x
Point of
Intersection
Chapter 5: Graphical Interpretation
5–2
ECE 1010 ECE Problem Solving I
• To obtain a matrix formulation of this problem we would first
rewrite (5.1) as
m1 x – y = –b1
(5.2)
m2 x – y = –b2
or
m1 –1 x
–b1
=
m2 –1 y
–b2
(5.3)
• The two lines intersect in a point if the matrix inverse
m1 –1
–1
(5.4)
m2 –1
exists; why?
• Consider
m1 –1
m1 –1
m2 –1
m1 –1
x =
m2 –1
y
–1
–b1
–b2









m2 –1
–1
10 = I
01
Chapter 5: Graphical Interpretation
5–3
ECE 1010 ECE Problem Solving I
• Thus the intersection point has x-y coordinates
x = m1 –1
m2 –1
y
–1
–b1
(5.5)
–b2
Linear Equations with Three Unknowns: The Intersection of
Planes
• The equation for a plane in the space x-y-z is given by
z = ax + by + c
• Two planes (two equations and three unknowns) may
– Intersect in a line (multiple solutions)
– Lie parallel to one another (no solutions)
– Be the same plane (multiple solutions)
• Three planes (three equations and three unknowns) may
– Intersect in a single point (a single solutions)
– Intersect in a line (multiple solutions)
– Form three parallel planes (no solutions)
– Be the same plane (multiple solutions)
– Other possibilities (see book)
Chapter 5: Graphical Interpretation
5–4
ECE 1010 ECE Problem Solving I
Two Planes
Intersecting
in a Line
z
y
x
Three Parallel Planes
e#
n
a
l
P
#3
e
n
Pla
2
Plane #1
Unique Point
of Intersection
M Hyperplanes of N Variables Each
• The generalization of the above ideas is consider a hyperplane defined in N-dimensional space
a1 x1 + a2 x2 + a3 x3 + … + aN xN = 0
Chapter 5: Graphical Interpretation
5–5
ECE 1010 ECE Problem Solving I
• We can not actually draw hyperplanes beyond N = 3 , but
the concept of solving M simultaneous equations of N
unknowns, extends from the notions developed for three
dimensions
• In the following assume the M hyperplanes are unique
• If M < N we say that the system is underspecified and a
unique solution does not exist
– As an example consider how two planes may intersect in a
line (here M = 2 and N = 3 )
• If M = N a unique solution is possible if none of the hyperplanes are parallel to each other
– As an examples consider how three faces of a cube intersect in a point
• If M > N we say that the system is overspecified and a unique
solution does not exist
– As an example consider how three lines in the plane may
pair-wise intersect, but not have a common solution
• When a unique solution exists we say that the system of
equations is nonsingular
• When no unique solution exists we say the system of equations is singular
Chapter 5: Graphical Interpretation
5–6
ECE 1010 ECE Problem Solving I
Solutions Using Matrix Operations
• The two equations and two unknowns given in (5.2) can be
cast into a more general notation as follows
a 11 x 1 + a 12 x 2 = b 1
a 21 x 1 + a 22 x 2 = b 2
• Extending to N equations and N unknowns we have
a 11x 1 + a 12x 2 + … + a 1N x N = b 1
a 21x 1 + a 22x 2 + … + a 2N x N = b 2
(5.6)
…
a N1 x 1 + a N2 x 2 + … + a NN x N = b N
• If we let
a 11 a 12 … a 1N
A =
a 21 a 22 … …
… … … …
a N1 … … a NN
x1
,X =
x2
…
xN
b1
,B =
b2
…
bN
(5.7)
we can write (5.6) in matrix form
(5.8)
AX = B
• Not that we could also write (5.6) as
T T
X A = B
Chapter 5: Solutions Using Matrix Operations
T
(5.9)
5–7
ECE 1010 ECE Problem Solving I
• This follows from the matrix theory result that
T
T
( GH ) = H G
T
– Note: (5.9) is simply another way expressing a system of N
equations and N unknowns as a matrix equation
Matrix Division
• In MATLAB solving matrix equations of the form (5.8) and
(5.9) is very easy
• Two basic approaches are available
• In this subsection we consider the use of matrix division
• Given
AX = B
(the form of (5.8)) is the matrix equation, with X the quantity
of interest, we use matrix left division as follows
X = A\B; % Note the backslash
– The numerical technique used here is Gauss elimination
• Given
XA = B
(the form of (5.8)) is the matrix equation, with X the quantity
of interest, we use matrix right division as follows
X = A/B; % Note the backslash
Example: N = 2
» A = [1 2; 3 4];
» B = [2; 5];
» X = A\B
Chapter 5: Solutions Using Matrix Operations
5–8
ECE 1010 ECE Problem Solving I
X =
1.0000
0.5000
» Xt = B'/A'
Xt =
1.0000
0.5000 %The same solutions as expected
• If the solution is singular MATLAB gives Nan’s or Inf’s
• If the solution is nearly singular, a warning message is given
Matrix Inverse
• As shown in (5.5) an alternate solution approach involves the
use of the matrix inverse, i.e., if
AX = B
then
–1
–1
A AX = A B
–1
but A A = I and IX = X , so
–1
X = A B
(5.10)
• In MATLAB this would be written as
X = inv(A)*B;
Chapter 5: Solutions Using Matrix Operations
5–9
ECE 1010 ECE Problem Solving I
• Using (5.9) the solution is
T T
T –1
T
T
X A (A )
T
T –1
= B (A )
which reduces to
T –1
X = B (A )
(5.11)
Example: Practice! p. 157 (2,6)
Solve the following systems of equations using both matrix division and inverse matrices. For systems with just two variables
(unknowns), plot the equations on the same graph to see the
intersection (unique solution) or show that the system is singular
(without a unique solution).
2. A system of two equations and two unknowns:
– 2x 1 + x 2 = – 3
–2 x1 + x2 = 1
• Load the system into MATLAB with
A = –2 1 , B = –3
1
–2 1
» A = [-2 1; -2 1]; B = [-3; 1];
» % Solve using matrix division:
» X = A\B
Warning: Matrix is singular to working precision.
Chapter 5: Solutions Using Matrix Operations
5–10
ECE 1010 ECE Problem Solving I
X =
Inf
Inf
» % Solve using the matrix inverse, first check
» % to see if rank is 2
» rank(A)
ans =
1
» % Unique solution does not exist
• Now we plot the two equations to see what is going on with
regard to the solution
»
»
»
»
»
x1 = -10:.1:10;
x2_1 = 2*x1 - 3;
x2_2 = 2*x1 + 1;
s = length(x1);
plot(x1(1:10:s),x2_1(1:10:s),'s',x1(1:10:s),...
x2_2(1:10:s),'d')% Plot symbols at a few points
» legend('First Eqn','Second Eqn')
» hold
Current plot held
» plot(x1,x2_1,x1,x2_2) % Plot lines with all points
» grid
» title('Plot of Two Equations for #2','fontsize',16)
» ylabel('x2','fontsize',14)
» xlabel('x1','fontsize',14)
Chapter 5: Solutions Using Matrix Operations
5–11
ECE 1010 ECE Problem Solving I
Plot of Two Equations for #2
25
First Eqn
Second Eqn
20
15
10
x2
5
0
-5
-10
-15
-20
-25
-10
-8
-6
-4
-2
0
2
4
6
8
10
x1
6. A system of three equations and three unknowns:
3x 1 + 2x 2 – x 3 = 1
– x 1 + 3x 2 + 2x 3 = 1
x1 – x2 – x3 = 1
Chapter 5: Solutions Using Matrix Operations
5–12
ECE 1010 ECE Problem Solving I
• Load the system into MATLAB with
3 2 –1
1
A = –1 3 2 , B = 1
1 –1 –1
1
» A = [3 2 -1; -1 3 2; 1 -1 -1]; B = [1; 1; 1];
» % Solve using matrix division:
» X = A\B
X =
9.0000
-6.0000
14.0000
» %Solve using the matrix inverse, first check rank:
» rank(A)
ans =
3
» X = inv(A)*B
X =
9.0000
-6.0000
14.0000
» % Solutions agree!
• The three planes must intersect at the point (9,-6,14)
Chapter 5: Solutions Using Matrix Operations
5–13
ECE 1010 ECE Problem Solving I
Problem Solving Applied: Electrical Circuit
Analysis
In the solution of electrical circuit problems we must deal with
systems of linear equations. The electrical engineering curriculum does not take this subject lightly.
– The electrical engineering BSEE program devotes two
semesters to circuit analysis
– Two semesters to electronic circuits analysis
– One semester to the study of signals and systems
• The foundation of circuit analysis are Kirchoff’s voltage and
current laws
• We will briefly introduce these two laws here, but to keep
things simple we will only consider resistor networks with
direct current (dc) or ideal battery sources
Kirchoff’s Voltage Law
The sum of voltage drops (or rises) around a closed loop in a circuit (without any independent current sources in series) is zero.
• The voltage drop across a resistive element is the current
through the element times the element resistance, e.g. ohms
law
i
+
v
-
R
Chapter 5: Problem Solving Applied: Electrical Circuit Analysis
Ohms Law
v = iR
5–14
ECE 1010 ECE Problem Solving I
A simple application:
+
v1
+
-
R1
+
i1
R2
-
• Kirchoff’s voltage law applied to the single loop current i 1
gives
– v1 + R1 i1 + R2 i1 = 0
or
( R 1 + R 2 )i 1 = v 1
Kirchoff’s Current Law
The sum of currents leaving (or entering) a node in a circuit
(without any independent voltage sources attached) is zero.
• Again ohm’s law comes in handy
A Simple Example:
v1
+
-
R1
+
v2
R2
-
Chapter 5: Problem Solving Applied: Electrical Circuit Analysis
5–15
ECE 1010 ECE Problem Solving I
• Kirchoff’s current law applied to node voltage v 2 gives
( v2 – v1 ) ( v2 – 0 )
-------------------- + ------------------- = 0
R1
R2
or
v1
1
1
 ----+
----v
=
----- (assume v 1 is known)
R
 2
R
R
1
2
1
Example: A three loop current network with five resistors and
two voltage sources.
R1
R3
R5
v1
+
-
i1
R2
i2
R4
i3
+
- v2
• Here we have three loops, hence we can write three equations
to solve for the three unknowns i 1, i 2, and i 3
• The first loop equation has a voltage source and two resistors;
the resistor R 2 has current i 1 flowing from top to bottom and
current i 2 flowing from bottom to top
– v 1 + R 1 i 1 + ( i 1 – i 2 )R 2 = 0
or
( R 1 + R 2 )i 1 – R 2 i 2 = v 1
Chapter 5: Problem Solving Applied: Electrical Circuit Analysis
(5.12)
5–16
ECE 1010 ECE Problem Solving I
• The second loop equation involves three resistors, but all
three loop currents appear in the equation
( i 2 – i 1 )R 2 + i 2 R 3 + ( i 2 – i 3 )R 4 = 0
or
– R 2 i 1 + ( R 2 + R 3 + R 4 )i 2 – R 4 i 3 = 0
(5.13)
• The third loop equation as with the first involves a voltage
source and two resistors
( i 3 – i 2 )R 4 + i 3 R 5 + v 2 = 0
or
– R 4 i 2 + ( R 4 + R 5 )i 3 = – v 2
(5.14)
• Putting (5.12–14) together in matrix form we have
( R1 + R2 )
–R2
0
–R2
( R2 + R3 + R4 )
–R 4
0
–R4
i1
v1
i2 =
0
–v2
( R4 + R5 ) i3
(5.15)
1. Problem Statement: Solve (5.15) for the mesh currents i 1, i 2 ,
and i 3 given as inputs the resistor values R 1 through R 5 and
the voltages v 1 and v 2
Chapter 5: Problem Solving Applied: Electrical Circuit Analysis
5–17
ECE 1010 ECE Problem Solving I
2. Input/Output Description: The I/O diagram is shown below
MATLAB
Solution
Resistor
Values
Voltage
Source
Values
Mesh
Currents
3. Hand Calculation: For a hand calculation assume that
R 1 = R 2 = R 3 = R 4 = R 5 = 1 ohm
v 1 = 5 volts and v 2 = – 6 volts
• We must solve
2 –1 0 i1
5
–1 3 –1 i2 = 0
0 –1 2 i3
6
• We solve this using MATLAB’s left division command and
then check the solution by computing the error
» A = [2 -1 0; -1 3 -1; 0 -1 2];
» B = [5; 0; 6];
» X = A\B
X =
3.8750 % Units of amps
2.7500 % Units of amps
4.3750 % Units of amps
Chapter 5: Problem Solving Applied: Electrical Circuit Analysis
5–18
ECE 1010 ECE Problem Solving I
» Error = sum(A*X-B)
Error = -2.6645e-015 % Very small
4. MATLAB Solution: A script will be written which prompts
the user to supply the five resistor values followed by the two
voltage values.
% Three-loop Circuit, three_loop.m
% Five resistors and two voltage sources
%
%
R
%
V
Prompt user to
= input('Enter
Prompt user to
= input('Enter
enter resistor values:
[R1 R2 ... R5] in ohms--> ');
enter voltage source values:
voltage values [v1 v2] in volts--> ');
% Fill the A matrix and the B vector:
A = [R(1)+R(2) -R(2) 0;
-R(2) R(2)+R(3)+R(4) -R(4);
0 -R(4) R(4)+R(5)];
B = [V(1); 0; -V(2)];
% Make sure solution is not singular
if rank(A) == 3
fprintf('The mesh currents in amps are: \n');
i = A\B
else
fprintf('The solution is not unique');
end
% Were Done!
Chapter 5: Problem Solving Applied: Electrical Circuit Analysis
5–19
ECE 1010 ECE Problem Solving I
5. Test Results:
• First check out the hand calculated value
» three_loop
Enter [R1 R2 ... R5] in ohms--> [1 1 1 1 1]
Enter voltage values [v1 v2] in volts--> [5 -6]
The mesh currents in amps are:
i =
3.8750
2.7500 <<--Values all agree with hand calculation
4.3750
• Try different resistor values and turn voltage source v 2 off.
» three_loop
Enter [R1 R2 ... R5] in ohms--> [2 3 2 3 2]
Enter voltage values [v1 v2] in volts--> [5 0]
The mesh currents in amps are:
i =
1.4091
0.6818 % All currents in amps
0.4091
» % Check the solution error
» Error = sum(A*i-B) % better check sum(abs(A*i-B))
Error =
1.1102e-015 % Small so solution seems reasonable
Chapter 5: Problem Solving Applied: Electrical Circuit Analysis
5–20
ECE 1010 ECE Problem Solving I
Example: The circuit of text problem 4 (text Fig. 5.5) worked
with node voltages.
R1
R2
va
R3
v1
+
-
R4
v2
R5
Reference Node
• The circuit of text Figure 5.5 as shown above contains three
loops, yet only two node voltages (excluding the ground or
reference node)
• Using node voltages we can solve for all the quantities of
interest by only writing two equations for node voltages as
opposed to three current equations
• At node 1 ( v 1 ) we have
( v1 – va ) v1 ( v1 – v2 )
-------------------- + ------ + --------------------- = 0
R2
R3
R4
Chapter 5: Problem Solving Applied: Electrical Circuit Analysis
5–21
ECE 1010 ECE Problem Solving I
or
va
11
1- + ----1- v – ---- ----v
+
----=
----1
2
R

R3
R2
2 R3 R4
(5.16)
• At node 2 ( v 2 ) we have
( v2 – va ) ( v2 – v1 ) v2
-------------------- + --------------------- + ------ = 0
R1
R3
R5
or
va
1
1- + ----1- + ----1- v = ----– ------ v 1 +  ----2


R3
R1 R3 R5
R1
(5.17)
• In matrix form (5.16) and (5.17) become
1
1- + ----1-
 ----- + ----R
R
R 
2
3
1
– -----R3
1– ----R3
4
v1
1- + ----1- + ----1- v 2
 ----R
R
R 
1
3
=
5
Chapter 5: Problem Solving Applied: Electrical Circuit Analysis
v
-----aR2
(5.18)
v
-----aR1
5–22