Page 87 - Applied Numerical Methods Using MATLAB
P. 87
76 SYSTEM OF LINEAR EQUATIONS
whose solution can be obtained by setting the derivative of this function (2.1.9)
with respect to x to zero.
∂ T o T −1 T
J = A [Ax − b] = 0; x = [A A] A b (2.1.10)
∂x
Note that the matrix A having the number of rows greater than the number of
columns (M> N) does not have its inverse, but has its left pseudo (generalized)
−1
T
T
inverse [A A] A as long as A is not rank-deficient—that is, all of its columns
are independent of each other (see item 2 in Remark 1.1). The left pseudo-inverse
matrix can be computed by using the MATLAB command pinv().
The LSE solution (2.1.10) can be obtained by using the pinv() command or
the backslash (\) operator.
>>A = [1; 2]; b = [2.1; 3.9];
>>x = pinv(A)*b %A\b or x = (A’*A)^-1*A’*b, equivalently
x = 1.9800
function x = lin_eq(A,B)
%This function finds the solution to Ax = B
[M,N] = size(A);
if size(B,1) ~= M
error(’Incompatible dimension of A and B in lin_eq()!’)
end
if M == N, x = A^-1*B; %x = inv(A)*B or gaussj(A,B); %Eq.(2.1.1)
elseifM<N %Minimum-norm solution (2.1.7)
x = pinv(A)*B; %A’*(A*A’)^-1*B; or eye(size(A,2))/A*B
else %LSE solution (2.1.10) forM>N
x = pinv(A)*B; %(A’*A)^-1*A’*B orx=A\B
end
The above MATLAB routine lin_eq() is designed to solve a given set of
equations, covering all of the three cases in Sections 2.1.1, 2.1.2, and 2.1.3.
(cf) The power of the pinv() command is beyond our imagination as you might have
felt in Problem 1.14. Even in the case of M< N, it finds us a LS solution if the
equations are inconsistent. Even in the case of M> N, it finds us a minimum-norm
solution if the equations are redundant. Actually, the three cases can be dealt with
by a single pinv() command in the above routine.
2.1.4 RLSE (Recursive Least-Squares Estimation)
In this section we will see the so-called RLSE (Recursive Least-Squares Esti-
mation) algorithm, which is a recursive method to compute the LSE solution.
◦
Suppose we know the theoretical relationship between the temperature t[ ]and