7 linear algebraic equations.pdf
TRANSCRIPT
-
8/11/2019 7 Linear Algebraic Equations.pdf
1/69
Linear Algebraic Equations
Cheng-Liang ChenPSELABORATORY
Department of Chemical EngineeringNational TAIWAN University
-
8/11/2019 7 Linear Algebraic Equations.pdf
2/69
Chen CL 1
Linear Algebraic Equations and Gauss Elimination
x+y+ 2z = 2 (1)3x y+z = 6 (2)
x+ 3y+ 4z = 4 (3)
(3)(1) 2y+ 2z = 2 (4)(2)+3(1) 2y+ 7z = 12 (5)
(5)
(4) 5z = 10 (6) ( z= 2)z=2 in (4) y = 1 (7)
z=2,y=1 in (1)
x = 1 (8)
-
8/11/2019 7 Linear Algebraic Equations.pdf
3/69
Chen CL 2
Linear Algebraic Equations and Gauss Elimination
1. Equation (1) is thepivotequation
2. Multiply it by
1 and add the result to (3)
to obtain2y+ 2z = 2 (equivalent toy+ z = 1)
x+y+ 2z = 2 (1)3x
y+z = 6 (2)
x+ 3y+ 4z = 4 (3)
3. Next multiply (1) by3 and add the result to (2)to obtain 2y+ 7z= 12
Thus we have a new set of two equations in twounknowns (y, z):
y+z = 1 (4)
2y+ 7z = 12 (5)
4. Equation (4) is the newpivotequation.
5. Multiply (4) by2 and add the result to (5)to obtain 5z = 10 (orz = 2)
6. Substitutez = 2 into (4) to obtain y+ 2 = 1 (ory = 1)
7. Then substitutey= 1 andz = 2 into (1)to obtainx 1 + 4 = 2 (orx= 1)
-
8/11/2019 7 Linear Algebraic Equations.pdf
4/69
Chen CL 3
Test Your Understanding
T6.1-1
Solve the following equations using Gauss elimination:
6x 3y+ 4z = 4112x+ 5y
7z =
26
5x+ 2y+ 6z = 14
(Answer:x= 2, y= 3, z = 5.)
-
8/11/2019 7 Linear Algebraic Equations.pdf
5/69
Chen CL 4
Singular and Ill-Conditioned Problems
3x 4y = 56x 10y = 2
unique solution, x= 7, y= 4
3x 4y = 56x 8y = 10
singular, infinite # solution
3x
4y = 5
6x 8y = 3 singular, no solution
C C
-
8/11/2019 7 Linear Algebraic Equations.pdf
6/69
Chen CL 5
Ch CL 6
-
8/11/2019 7 Linear Algebraic Equations.pdf
7/69
Chen CL 6
function P363b
x = [6 : 0.25 : 8];
y_1 = (3*x-5)/4;
y_2 = (6*x-2)/10;
subplot(3,1,1)plot(x,y_1,x,y_2),...
xlabel(x),ylabel(y),...
title(Unique solution),...
legend(Line 1,Line 2)
y_3 = (6*x-10)/8;
subplot(3,1,2)plot(x,y_1,x,y_3,o),...
xlabel(x),ylabel(y),...
title(Singular, No unique soln),...
legend(Line 1,Line 2)
y_4 = (6*x-3)/8;
subplot(3,1,3)
plot(x,y_1,x,y_4),...
xlabel(x),ylabel(y),...
title(Singular, No solution),...
legend(Line 1,Line 2)
Ch CL 7
-
8/11/2019 7 Linear Algebraic Equations.pdf
8/69
Chen CL 7
Homogeneous Equations (zero RHSs)
6x+ay = 0 (1)
2x+ 4y = 0 (2)
(1)3(2)
(a 12)y = 0
Case 1: y = 0 only ifa = 12y=0 in (1)
x = 0
Case 2: 0y = 0 ifa= 12
x = 2y infinite # of solutions
Ch CL 8
-
8/11/2019 7 Linear Algebraic Equations.pdf
9/69
Chen CL 8
Ill-Conditioned EquationsAnIll-Conditionedset of equations is a set that is close to being
singular
3x 4y = 56x 8.002y = 3
y = 3x 54
x= 4668y =
3x 1.54.001
y= 3500
But if we had carried only two significant figures We would have rounded the denominator of the latter
expression to 4.0
Two expressions for y have the same slope (parallel)
No solution ill-conditioned status (soln dep.s on accuracy)
Ch CL 9
-
8/11/2019 7 Linear Algebraic Equations.pdf
10/69
Chen CL 9
Test Your Understanding
T6.1-2Show that the following set has no solution.
4x+ 5y = 10
12x 15y = 8
T6.1-3
For what value ofb will the following set have a solution in which
both x and y are nonzero? Find the relation between x and y.
4x by = 03x+ 6y = 0
(Answer: Ifb= 8, x= 2. Ifb = 8, x=y= 0.)
Chen CL 10
-
8/11/2019 7 Linear Algebraic Equations.pdf
11/69
Chen CL 10
Matrix Methods for Linear Equations
2x1+ 9x2 = 5
3x1
4x2 = 7
2 9
3 4
A
x1
x2
x
=
5
7
b
Ax = b
a11x1+a12x2+ +a1nxn = b1a21x1+a22x2+ +a2nxn = b2
am1x1+am2x2+ +amnxn = bm
a11 a12 a1na21 a22 a2n
am1 am2 amn
A
x1
x2...
xn
x
=
b1
b2...
bm
b
Ax = b
Chen CL 11
-
8/11/2019 7 Linear Algebraic Equations.pdf
12/69
Chen CL 11
Determinant and Singular Problems
A=
3 4 16 10 2
9 7 8
A = [3,-4,1; 6,10,2; 9,-7,8];
det(A)
ans =
8
-
8/11/2019 7 Linear Algebraic Equations.pdf
13/69
Chen CL 13
-
8/11/2019 7 Linear Algebraic Equations.pdf
14/69
Chen CL 13
Left-division Method With Three Unknowns
Example: Use the left-division method to solve the following set:
3x+ 2y 9z = 659x 5y+ 2z = 16
6x+ 7y+ 3z = 5
Solution:
A =
3 2
9
9 5 26 7 3
We can use MATLAB to check the determinant ofA to see
whether the problem is singular.
Chen CL 14
-
8/11/2019 7 Linear Algebraic Equations.pdf
15/69
Chen CL 14
A = [3, 2, -9; -9, -5, 2; 6, 7, 3];
b = [-65; 16; 5];det_A = det(A),...
soln = A\b ,... % Ax=b
A*soln
det_A =
288
soln =
2.0000-4.0000
7.0000
ans =
-65.0000
16.0000
5.0000
Chen CL 15
-
8/11/2019 7 Linear Algebraic Equations.pdf
16/69
Chen CL 15
Example: An Electrical-resistance Network
The circuit shown in the following Figure has five resistances and applied voltages.Assuming that the positive directions of current flow are in the directions shown inthe figure, Kirchhoffs voltage law applied to each loop in the circuit gives
v1+R1i1+R4i4 = 0R4+R2i2+R5i5 = 0R5i5+R3i3+v2 = 0
Conservation of charge applied at each node in the circuit gives
i1 = i2+i4
i2 = i3+i5
You can use these two equations to eliminate i4 andi5 from the first three
Chen CL 16
-
8/11/2019 7 Linear Algebraic Equations.pdf
17/69
Chen CL 16
equations. The results is:
(R1+R4)i1 R4i2 = v1
R4i1+ (R2+R4+R5)i2
R5i3 = 0
R5i2 (R3+R5)i3 = v2
Thus we have three equations in three unknowns: i1, i2, and i3.
Write a MATLAB script file that uses given values of the applied voltages v1andv2 and given values of the five resistances to solve for the currents i1, i2, and
i3. Use the program to find the currents for the case R1= 5, R2= 100,
R3= 200, R4= 1504, R5= 250 k, v1= 100, andv2= 50 volts. (Note that 1
k = 1000)
Chen CL 17
-
8/11/2019 7 Linear Algebraic Equations.pdf
18/69
Chen CL 17
Solution:
% File resist.m % Solvers for the currents i_1, i_2, i_3
R = [5, 100, 200, 150, 250]*1000;v1 = 100; v2 = 50;
A1 = [R(1) + R(4), -R(4), 0];
A2 = [-R(4), R(2) + R(4) + R(5), -R(5)];
A3 = [0, R(5), -(R(3) + R(5))];
A = [A1; A2; A3];
b = [v1; 0; v2];current = A\b;
disp(The currents are:)
disp(current)
>> resist % run resist.m
The currents are:
1.0e-003*
0.9544
0.3195
0.0664 % i_1,i_2,i_3 = 0.9544, 0.3195, 0.0664 mA
Chen CL 18
-
8/11/2019 7 Linear Algebraic Equations.pdf
19/69
Chen CL 18
Example: Ethanol Production
Engineers in the food and chemical industries use fermentation in many processes.
The following equation describes Bakers yeast fermentation.
a(C6H12O6) +b(O2) +c(N H3)
C6H10N O3+d(H2O) +e(CO2) +f(C2H6O)
The variables a, b, . . . , f represent the masses of the products involved in theequation. In this formula C6H12O6 representsglucose, C6H10N O3 representsyeast, andC2H6O representsethanol. This reaction produces ethanol, in additionto water and carbon dioxide. We want to determine the amount of ethanol fproduced. The number ofC, O, N, and Hatoms on the left must balance thoseon the right side of the equation. This gives four equations:
Cbalance 6a = 6 +e+ 2f
O balance 6a+ 2b = 3 +d+ 2e+f
N balance c = 1
Hbalance 12a+ 3c = 10 + 2d+ 6f
Chen CL 19
-
8/11/2019 7 Linear Algebraic Equations.pdf
20/69
Chen CL 19
The fermentor is equipped with anoxygensensor and acarbon dioxidesensor.These enable us to compute the respiratory quotient R:
R=CO2
O2=
e
b
Thus the fifth equation is Rb e= 0. The yeast yield Y (grams of yeastproduced per gram of glucose consumed) is related to a as follows .
Y =
144
180a
Where 144 is the molecular weight of yeast and 180 is the molecular weight of
glucose. By measuring the yeast yield Ywe can compute a as follows:
a= 144/180Y. This is the sixth equation.
Write a user-defined function that computes f, the amount of ethanol produced,
withR andYas the functions arguments. Test your function for two cases where
Y is measure to be 0.5: (a) R= 1.1 and (b) R= 1.05.
Chen CL 20
-
8/11/2019 7 Linear Algebraic Equations.pdf
21/69
Chen CL 20
Solution: let x1 b, x2 d, x3 e, x4 f
x3
2x4 = 6
6(144/180Y)
2x1 x2 2x3 x4 = 3 6(144/180Y)2x2 6x4 = 7 12(144/180Y)
Rx1 x3 = 0
In matrix form:
0 0 1 2
2 1 2 10 2 0 6
R 0 1 0
x1
x2x3
x4
= 6 6(144/180Y)
3 6(144/180Y)7 12(144/180Y)
0
The function file and the the session:
Chen CL 21
-
8/11/2019 7 Linear Algebraic Equations.pdf
22/69
funtion E = ethanol(R,Y)
% Computes ethanol produced
% from yeast reaction.
A = [0, 0,-1,-2; 2,-1,-2,-1; ...0,-2, 0,-6; R, 0,-1, 0];
b = [6 - 6*(144./(180*Y)); ...
3 - 6*(144./(180*Y)); ...
7 - 12*(144./(180*Y)); 0];x = A\b;
E = x(4);
E_1 = ethanol(1.1, 0.5)
E_2 = ethanol(1.05,0.5)
E_1 =
0.0654E_2 =
-0.0717
Chen CL 22
-
8/11/2019 7 Linear Algebraic Equations.pdf
23/69
Matrix Inverse
Ax = b
A1A = AA1 = I
A1Ax = A1b
x = A1b
Chen CL 23
-
8/11/2019 7 Linear Algebraic Equations.pdf
24/69
Example: Calculation Of Cable Tension
A mass m is suspended by three cables attached at the three points B, C, and D,
as shown in the following figure. Let T1, T2, and T3 be the tensions in the threecables AB, AC, and AD, respectively. If the mass m is stationary, the sum of thetension components in the x, in the y, and in the z directions must each be zero.This requirement gives the following three equations:
T135
3T234
+ T3
42= 0
3T135
4T342
= 0
5T135
+ 5T2
34+ 5T
342
mg = 0
Use MATLAB to findT1, T2, andT3 in terms of an unspecified value of theweight mg.
Solution: set mg= 1
Chen CL 24
-
8/11/2019 7 Linear Algebraic Equations.pdf
25/69
A =
135
334
142
335
0 442
535
534
542
x =
T1
T2
T3
b =
0
0
1
% File cable.m
% Computes the tensions in three cables.
A1 = [1/sqrt(35), -3/sqrt(34), 1/sqrt(42)];
A2 = [3/sqrt(35), 0, -4/sqrt(42)];
A3 = [5/sqrt(35), 5/sqrt(34), 5/sqrt(42)];
A = [A1; A2; A3];
b = [ 0; 0; 1];
x = A\b;
disp(The tension T_1 is:)
disp(x(1))disp(The tension T_2 is:)
disp(x(2))
disp(The tension T_3 is:)
disp(x(3))
The tension T_1 is:
0.5071 % 0.5071 mg
The tension T_2 is:
0.2915 % 0.2915 mg
The tension T_3 is:0.4166 % 0.4166 mg
Chen CL 25
-
8/11/2019 7 Linear Algebraic Equations.pdf
26/69
Example: The Matrix Inverse Method
Solve the following equations using the matrix inverse:
2x+ 9y = 5
3x 4y = 7
Solution:
A = 2 9
3 4
Its determinant is|A| = 2(4) 9(3) = 35, and its inverse is
A
1
=
1
35 4 93 2 = 135 4 93 2 The solution is
x = A1b = 1
35 4 9
3 2 5
7 = 1
35 83
1
Chen CL 26
-
8/11/2019 7 Linear Algebraic Equations.pdf
27/69
The Matrix Inverse inMATLAB
A = [2, 9; 3, -4];
b = [5; 7]x = inv(A)*b
x =
2.37140.0286
Chen CL 27
-
8/11/2019 7 Linear Algebraic Equations.pdf
28/69
Test Your Understanding
T6.2-1
Use the matrix inverse method to solve the following set by handby using MATLAB: (Answer:x= 7, y= 4.)
3x 4y = 5
6x 10y = 2
T6.2-2
Use the matrix inverse method to solve the following set by hand
and by using MATLAB:
3x 4y = 56x 8y = 2
(Answer: no solution.)
Chen CL 28
-
8/11/2019 7 Linear Algebraic Equations.pdf
29/69
Cramers Method
a11x+a12y = b1
a21x+a22y = b2 a22(a11x+a12y) = a22b1a12(a21x+a22y) = a12b2
x = b1a22
b2a12
a22a11 a12a21 =
b1 a12
b2 a22
a11 a12
a21 a22
D1
D
y = b2a11 b1a21a22a11 a12a21
=
a11 b1
a21 b2
a11 a12a21 a22
D2
D
Note: IfD= 0 but D1 = 0 then x is undefinedIfD= 0 andD1= 0 then x has infinitely many soln.s
Chen CL 29
-
8/11/2019 7 Linear Algebraic Equations.pdf
30/69
Test Your Understanding
T6.3-1Use Cramers method to solve for x and y in terms of the
parameter b. For what value ofb is the set singular ?
4x
by = 5
3x+ 6y = 3
(Answer: x= (10 +b)/(8 b), y = 9/(8 b) unless b= 8.)
Chen CL 30
-
8/11/2019 7 Linear Algebraic Equations.pdf
31/69
T6.2-2
UseCramers method to solve for y.
UseMATLAB to evaluate the determinants.
2x+y+ 2z = 17
3y+z = 6
2x 3y+ 4z = 19
(Answer: y= 1.)
-
8/11/2019 7 Linear Algebraic Equations.pdf
32/69
Chen CL 32
-
8/11/2019 7 Linear Algebraic Equations.pdf
33/69
2x 4y+ 5z = 44x 2y+ 3z = 4
2x+ 6y 8z = 0A = [2,-4,5; -4,-2,3; 2,6,-8];
b = [-4, 4, 0];
soln_left_div = A\b
soln_pseudoin = pinv(A)*b
Warning: Matrix is singular
to working precision.
soln_left_div =
Inf
Inf
Inf
soln_pseudoin =
-1.2148
0.2074
-0.1481
Chen CL 33
-
8/11/2019 7 Linear Algebraic Equations.pdf
34/69
Matrix Rank
Anm
n matrix A has a rank r
1 if and only if
|A
|contains a
nonzeror r determinant and every square sub-determinant withr+ 1 or more rows is zero
Example: The rank ofA=
3 4 16 10 2
9 7 3
is 2 because|A| = 0
whereas A contains at least one nonzero 2 2 subdeterminant.
eg,|A| =
10 2
7 3
= 44
A = [3,-4,1; 6,10,2; 9,-7,3];
rank(A)
ans =
2
Chen CL 34
-
8/11/2019 7 Linear Algebraic Equations.pdf
35/69
Existence and Uniqueness of Solutions
Existence and Uniqueness of SolutionsThe set Ax= b with m equations and n unknowns has solutions
if and only ifrank(A) = rank([A b])
Letr= rank(A).
1. If previous condition is satisfied and ifr=n,
then the solution is unique
2. If previous condition is satisfied and but r < n,
an infinite number of solution exists andrunknown variables can
be expressed as linear combination of the other n r unknownvariables, whose values are arbitrary.
Chen CL 35
-
8/11/2019 7 Linear Algebraic Equations.pdf
36/69
Homogeneous Case
1. For the homogeneous set Ax = 0, rank(A) = rank([A b])
always, and thus the set always has the trivial solution x= 0.
2. A nonzero solution (at least one unknown is nonzero) exists ifand only ifrank(A) < n
3. Ifm < n, the homogeneous set always has a nonzero solution
Chen CL 36
-
8/11/2019 7 Linear Algebraic Equations.pdf
37/69
Example: A Set Having A Unique Solution
Determine whether the following set has a unique solution, and ifso,find it:
3x 2y+ 8z = 486x+ 5y+z = 129x+ 4y+ 2z = 24
Solution:
A =
3 2 8
6 5 1
9 4 2
b =
48
12
24
x =
x
y
z
Chen CL 37
-
8/11/2019 7 Linear Algebraic Equations.pdf
38/69
A = [3, -2, 8; -6, 5, 1; 9, 4, 2];
b = [48; -12; 24];
rank(A)
ans =3
rank([A b])
ans =
3
x=A\b
x =
2
-1
5
Chen CL 38
Y U d di
-
8/11/2019 7 Linear Algebraic Equations.pdf
39/69
Test Your Understanding
T6.4-1
UseMATLAB to show that the following set has a unique solutionand then find the solution:
3x+ 12y 7z = 55x 6y 5z = 8
2x+ 7y+ 9z = 5
(Answer: The unique solution is
x= 1.0204, y= 0.5940, z= 0.1332.)
Chen CL 39
Th Mi i E lid N S l i
-
8/11/2019 7 Linear Algebraic Equations.pdf
40/69
The Minimum Euclidean Norm Solution
Thepinvcommand can obtain a solution of an
underdetermined set
v = [x y z]
N =
vTv =
[x y z]T
xy
z
=
x2 +y2 +z2
Chen CL 40
E l A U d d i d S
-
8/11/2019 7 Linear Algebraic Equations.pdf
41/69
Example: An Under-determined Set
Show that the following set does not have a unique solution. How many of the
unknowns will be undetermined ? Interpret the results given by the left-divisionmethod.
2x 4y+ 5z = 44x 2y+ 3z = 4
2x+ 6y 8z = 0
Solution:A = [2, -4, 5; -4, -2, 3;...
2, 6, -8];
b = [-4; 4; 0];r1 = rank(A)
r2 = rank([A b])
r1 =
2
r2 =
2
infinite no. of solutions
soln = pinv(A)*b
soln =
-1.2148
0.2074
-0.1481
Chen CL 41
E A S i ll I d i P bl
-
8/11/2019 7 Linear Algebraic Equations.pdf
42/69
Ex: A Statically-Indeterminate Problem
Determine the forces in the three equally spaced
supports that hold up a light fixture. The supports
are5 feet apart. The fixture weights 400 pounds,
and its mass center is 4 feet from the right end.
(a) Solve the problem by hands. (b) obtain the
solution using the MATLABleft-division method
and the pseudoinverse method.
Solution:
vertical force must cancel; total moments about right endpoint are zero
Chen CL 42
-
8/11/2019 7 Linear Algebraic Equations.pdf
43/69
T1+T2+T3 400 = 0400(4)
10T1
5T2 = 0
or T1+T2+T3 = 400
10T1+ 5T2+ 0T3 = 1600
1 1 110 5 0
A
T1
T2
T3
x
= 400
1600
b
[A b] = 1 1 1 40010 5 0 1600 T2 =
1600 10T15
= 320 2T1T1 = T3 80T2 = 320
2T1= 320
2(T3
80) = 480
2T3
Chen CL 43
l l ft A\b
-
8/11/2019 7 Linear Algebraic Equations.pdf
44/69
A = [1, 1, 1; 10, 5, 0];
b = [400; 1600];
rank(A)
ans =
2
rank([A b])
ans =
2
soln_left = A\b
soln_pseu = pinv(A)*b
soln_left =
160.0000
0240.0000
soln_pseu =
93.3333 % min norm soln
133.3333
173.3333
norm_left = sqrt(sum(soln_left.^2))norm_pseu = sqrt(sum(soln_pseu.^2))
norm_left =
288.4441
norm_pseu =
237.7674
-
8/11/2019 7 Linear Algebraic Equations.pdf
45/69
Chen CL 45
Th R d d R E h l F
-
8/11/2019 7 Linear Algebraic Equations.pdf
46/69
The Reduced Row Echelon Form
T1
= T3
80
T2 = 480 2T3 T1 T3 = 80
T2+ 2T3 = 480
1 0 10 1 2
T1
T2
T3
= 80480
1 0 1 800 1 2 480
rref([A b])command provides a procedure to reduce an underdetermined set tosuch a reduced row echelon form
Its output is the augmented matrix [C d] that corresponds to the equation set
Cx= d
Chen CL 46
E l A Si l S t
-
8/11/2019 7 Linear Algebraic Equations.pdf
47/69
Example: A Singular Set
The following under-determined equation set was analyzed in
previous Example. There it was shown that an infinite number of
solutions exists. Use the pinv and the rrefcommands to obtain
solutions.
2x 4y+ 5z = 4
4x 2y+ 3z = 42x+ 6y 8z = 0
Solution:
Chen CL 47
A = [2 4 5; 4 2 3;
-
8/11/2019 7 Linear Algebraic Equations.pdf
48/69
A = [2, -4, 5; -4, -2, 3;...
2, 6, -8];
b = [-4; 4; 0];
x = pinv(A)*b
x =-1.2148
0.2074
-0.1481
rref([A b])
ans =
1 0 -0.1 -1.2000
0 1 -1.3 0.40000 0 0 0
The answer corresponds to the augmented matrix [C d],
[C d] =
1 0 0.1 1.20 1 1.3 0.40 0 0 0
The matrix corresponds to the matrix equation Cx= d, or
x+ 0y 0.1z = 1.20x+y 1.3z = 0.40x+ 0y+ 0z = 0.0
x = 0.1z 1.2y = 1.3z+ 0.4
z = arbitrary value
Chen CL 48
E a le P od ctio Pla i
-
8/11/2019 7 Linear Algebraic Equations.pdf
49/69
Example: Production Planning
The following table shows how many hours reactors A and B need to produce 1ton each of the chemical products 1, 2, and3. The two reactors are available for
40 hours and 30 hours per week, respectively. Determine how many tons of eachproduct can be produced each week.
Hours Product 1 Product 2 Product 3
Reactor A 5 3 3
Reactor B 3 3 4
Solution:
5x+ 3y+ 3z = 40
3x+ 3y+ 4z = 30
A =
5 3 3
3 3 4
b =
40
30
x =
x
y
z
Chen CL 49
Note: rank(A) = rank([A b]) = 2 which is less than the number of unknowns
-
8/11/2019 7 Linear Algebraic Equations.pdf
50/69
Note: rank(A) = rank([A b]) = 2, which is less than the number of unknowns(3). Thus an infinite number of solution exists, and we can determine two of thevariables in terms of the third.Usingrref([A b]), whereA=[5,3,3; 3,3,4]andb=[40;30], we obtain the following
reduced echelon augmented matrix,
1 0 0.5 50 1 1.8333 5
x 0.5z = 5y+ 1.8333z = 5
x = 5 + 0.5zy = 5 1.8333z
Suppose we make a profit of$400, $600, $100 per ton for products 1, 2 and3,
Chen CL 50
respectively
-
8/11/2019 7 Linear Algebraic Equations.pdf
51/69
respectively.
P = 400x+ 600y+ 100z
= 400(5 + 0.5z) + 600(5
1.8333z) + 100z
= 5000 800z
To maximize profit P, choose z = 0 x= y = 5 tons.
Chen CL 51
Example: Traffic Engineering
-
8/11/2019 7 Linear Algebraic Equations.pdf
52/69
Example: Traffic Engineering
A traffic engineer wants to know whether measurements of traffic flow entering
and leaving a road network are sufficient to predict the traffic flow on each street
in the network. For example, consider the network of one-way streets shown in the
following Figure. The numbers in the figure give the measured traffic flows in
vehicles per hour. Assume that no vehicles park anywhere within the network. If
possible, calculate the traffic f1, f2, f3, andf4. If this is not possible, suggest
how to obtain the necessary information.
Chen CL 52
Solution:
-
8/11/2019 7 Linear Algebraic Equations.pdf
53/69
Solution:
100 + 200 = f1+f4
f1+f2 = 300 + 200
600 + 400 = f2+f3
f3+f4 = 300 + 500
A =
1 0 0 1
1 1 0 00 1 1 0
0 0 1 1
b = 300
5001000
800
x = f1
f2f3
f4
rref([A b])
1 0 0 1 3000 1 0 1 2000 0 1 1 800
0 0 0 0 0
f1 = 300 f4
f2 = 200 +f4
f3 = 800 f4
Chen CL 53
Test Your Understanding
-
8/11/2019 7 Linear Algebraic Equations.pdf
54/69
Test Your Understanding
T6.4-3
Use the rref and pinv commands and the left-division method to solve thefollowing set:
3x+ 5y+ 6z = 6
8x
y+ 2z = 1
5x 6y 4z = 5
(Answer: The set has an infinite number of solutions. The result obtainedwith the rref commands is x = 0.2558 0.3721z, y = 1.0465 0.9767z, z isarbitrary. The pinv commands gives x= 0.0571, y = 0.5249, z = 0.5340. The
left-division method generates an error message.)
Chen CL 54
T6.4-4
-
8/11/2019 7 Linear Algebraic Equations.pdf
55/69
T6.4 4Use the rref and pinv commands and the left-division method to solve thefollowing set:
3x+ 5y+ 6z = 4x 2y 3z = 10
(Answer: The set has an infinite number of solutions. The result obtained withtherrefcommands isx = 0.2727z + 5.2727 0.3721z,y = 1.3636z 2.3636,z is arbitrary. The pinv commands gives x= 4.8000, y = 0, z = 1.7333. Thepseudoinverse method gives x= 4.8396, y= 0.1972, z= 1.5887.)
Chen CL 55
Overdetermined Systems: The Least
-
8/11/2019 7 Linear Algebraic Equations.pdf
56/69
Overdetermined Systems: The LeastSquares Method
Suppose we have the following three data points, and we want to find the straightline y=mx+b that best fits the data in some sense.
x y0 2
5 6
10 11
(a) Find the coefficients m andb by using the least squares criterion. (b) Find the
coefficients by using MATLAB to solve the three equations (one for each data
point) for the two unknowns m andb. Compare the answers from (a) and (b).
Solution:
Chen CL 56
-
8/11/2019 7 Linear Algebraic Equations.pdf
57/69
J=
i=3i=1
(mxi+b yi)2
J= (0m+b 2)2
+ (5m+b 6)2
+ (10m+b 11)2
Chen CL 57
J2(5 b 6)(5) 2(10 b 11)(10)
-
8/11/2019 7 Linear Algebraic Equations.pdf
58/69
m = 2(5m+b 6)(5) + 2(10m+b 11)(10)
= 250m+ 30b 280 = 0J
b
= 2(b
2) + 2(5m+b
6) + 2(10m+b
11)
= 30m+ 6b 38 = 0
250m+ 30b = 280
30m+ 6b = 38 m= 0.9, b= 11
6 (y = 0.9x+ 11/6)
Evaluate y=mx+b at each data point:
0m+b = 2
5m+b = 6
10m+b = 11
-
8/11/2019 7 Linear Algebraic Equations.pdf
59/69
Chen CL 59
Example: An Over-determined Set
-
8/11/2019 7 Linear Algebraic Equations.pdf
60/69
Example: An Over-determined Set
(a) Solve the following equations by hand and (b) solve them using MATLAB.
Discuss the solution for two cases: c= 9 andc= 10.
x+y = 1
x+ 2y = 3
x+ 5y = c
Solution:
A =
1 1
1 2
1 5
[A b] = 1 1 1
1 2 3
1 5 c
c= 9 rank(A) = rank([A b]) = 2 A\bgives unique solution x= 1, y= 2
-
8/11/2019 7 Linear Algebraic Equations.pdf
61/69
Chen CL 61
Fitting Models by Least Squares
-
8/11/2019 7 Linear Algebraic Equations.pdf
62/69
Fitting Models by Least Squares
inputs = xi1, xi2,
, xip output=yi, i= 1, . . . , n
(y1 ; x11, x12, , x1p) (1st observation data)(y2 ; x21, x22, , x2p) (2nd observation data)
... ...
(yn ; xn1, xn2, , xnp) (nth observation data)y = 1x1+2x2+ +pxp (linear model)
y1 = 1x11+2x12+ +px1p+1y2 = 1x21+2x22+ +px2p+2
... ...
yn
obs= 1xn1+2xn2+ +pxnp model output
+ n
error
-
8/11/2019 7 Linear Algebraic Equations.pdf
63/69
-
8/11/2019 7 Linear Algebraic Equations.pdf
64/69
Chen CL 64
Test Your Understanding
-
8/11/2019 7 Linear Algebraic Equations.pdf
65/69
Test Your Understanding
T6.5-1
Use MATLAB to solve the following set:
x 3y = 23x+ 5y = 7
70x
28y = 153
(Answer: The unique solution, x = 2.2143, y = 0.0714, is given by theleft-division method.)
T6.5-2
Use MATLAB to solve the following set:
x 3y = 23x+ 5y = 7
5x
2y =
4
(Answer: no exact solution.)
Chen CL 65
AMATLABProgram to Solve Linear Equations
-
8/11/2019 7 Linear Algebraic Equations.pdf
66/69
g t S q t
Chen CL 66
% Script file lineq.m
-
8/11/2019 7 Linear Algebraic Equations.pdf
67/69
p q
% Solve the set Ax=b, given A and b
% Check the ranks of A and [A b]
if rank(A) == rank([A b]) % A, [A b]: equal ranks
size_A = size(A);
if rank(A) == size_A(2) % rank of A = no unknowns
disp(There is a unique solution: )
x = A\b % solve using left division
else % rank of A # no unknownsdisp(There is an infinite no of solutions.)
disp(The augmented matrix of reduced system: )
rref([A b]) % compute augmented matrix
endelse % A, [A b]: not equal ranks
disp(There are no solutions )
end
Chen CL 67
A = [1, -1; 1, 1]; b = [3; 5];
-
8/11/2019 7 Linear Algebraic Equations.pdf
68/69
lineq
There is a unique solution:
x =
41
A = [1, -1; 2, -2]; b = [3; 6];
lineq
There is an infinite no of solutions.
The augmented matrix of reduced system:
ans =
1 -1 3
0 0 0
A = [1, -1; 2, -2]; b = [3; 5];
lineq
There are no solutions
Chen CL 68
-
8/11/2019 7 Linear Algebraic Equations.pdf
69/69
Thank You for Your AttentionQuestions Are Welcome