Page 29 - Applied Numerical Methods Using MATLAB
P. 29
18 MATLAB USAGE AND COMPUTATIONAL ERRORS
The results of various operations on these vectors/matrices are as follows (pay
attention to the error message):
>>A3 = A1 + A2, A4 = A1 - A2, 1 + A1 %matrix/scalar addition/subtraction
A3=-2 4 6 A4=0 0 0 ans=0 3 4
2 5 3 6 5 1 5 6 3
>>AB = A1*B % AB(m, n) = A 1 (m, k)B(k, n) matrix multiplication?
k
??? Error using ==> *
Inner matrix dimensions must agree.
>>BA1 = B*A1 % regular matrix multiplication
BA1 = -9 -8 -1
3 -6 -9
>>AA = A1.*A2 %termwise multiplication
AA = 1 4 9
-8 0 2
>>AB=A1.*B % AB(m, n) = A 1 (m, n)B(m, n) termwise multiplication
??? Error using ==> .*
Matrix dimensions must agree.
T −1
T
>>A1 1 = pinv(A1),A1’*(A1*A1’)^-1,eye(size(A1,2))/A1 % A [A 1 A ]
1
1
A1 1 = -0.1914 0.1399 %right inverse ofa2x3 matrix A1
0.0617 0.0947
0.2284 -0.0165
>>A1*A1 1 %A1/A1 = I implies the validity of A1 1 as the right inverse
ans = 1.0000 0.0000
0.0000 1.0000
>>A5=A1’;%a3x2 matrix
T
A
>>A5 1 = pinv(A5),(A5’*A5)^-1*A5’,A5\eye(size(A5,1)) % [A A 5 ] −1 T
5 5
A5 1 = -0.1914 0.0617 0.2284 %left inverse of a 3x2 matrix A5
0.1399 0.0947 -0.0165
>>A5 1*A5 % = I implies the validity of A5 1 as the left inverse
ans = 1.0000 -0.0000
-0.0000 1.0000
>>A1 li = (A1’*A1)^-1*A1’ %the left inverse of matrix A1 withM<N?
Warning: Matrix is close to singular or badly scaled.
Results may be inaccurate. RCOND = 9.804831e-018.
A1 li = -0.2500 0.2500
0.2500 0
0.5000 0.5000
(Q12) Does the left inverse of a matrix having rows fewer than columns exist?
(A12) No. There is no N × M matrix that is premultiplied on the left of an M × N
matrix with M< N to yield a nonsingular matrix, far from an identity matrix.
In this context, MATLAB should have rejected the above case on the ground
T
that [A A 1 ] is singular and so its inverse does not exist. But, because the round-
1
off errors make a very small number appear to be a zero or make a real zero
appear to be a very small number (as will be mentioned in Remark 2.3), it is
not easy for MATLAB to tell a near-singularity from a real singularity. That is
why MATLAB dares not to declare the singularity case and instead issues just a
warning message to remind you to check the validity of the result so that it will
not be blamed for a delusion. Therefore, you must be alert for the condition