MATLAB Lecture 2 School of Mathematical Sciences Xiamen University http∥gdjpkc.xmu.edu.cr 5.0000 2.0000 12.0000 Least Squares Solutions. If b=[3: 6: 0, then AX-b does not have an exact solution. In this case, pinv(a)*b returns a least squares solution. If you type >>A pinv(A)b 10000 4.0000 2.0000 lo not get back the original vector b You can determine whether AX= b has an exact solution by finding the row reduced echelon form of the augmented matrix [A b]. To do so for this example, enter > rref(A b) ans 1.0000 022857 01.00001.5714 0 0 010000 Since the bottom row contains all zeros except for the last entry, the equation does not have a solution. In this case, pinv(A)returns a least-squares solution Overdetermined systems Similar to Least Squares Solutions. Omitted Underdetermined Systems >>R=fix(10*rand(2, 4)) %Obtain an integer matrix by rand and fix function >>b=fx(10*rand(2,1) b > format rat display the solution in rational format >>X0=RIb finds a basic solution, which has at most m nonzero components Lec2-4MATLAB Lecture 2 School of Mathematical Sciences Xiamen University http://gdjpkc.xmu.edu.cn Lec24 5.0000 2.0000 12.0000 Least Squares Solutions. If b = [3;6;0], then AX = b does not have an exact solution. In this case, pinv(A)*b returns a least squares solution. If you type >> A*pinv(A)*b ans = 1.0000 4.0000 2.0000 you do not get back the original vector b. You can determine whether AX = b has an exact solution by finding the row reduced echelon form of the augmented matrix [A b]. To do so for this example, enter >> rref([A b]) ans = 1.0000 0 2.2857 0 0 1.0000 1.5714 0 0 0 0 1.0000 Since the bottom row contains all zeros except for the last entry, the equation does not have a solution. In this case, pinv(A) returns a leastsquares solution. Overdetermined systems Similar to Least Squares Solutions. Omitted. Underdetermined Systems >> R = fix(10*rand(2,4)) % Obtain an integer matrix by rand and fix function R = 6 8 7 3 3 5 4 1 >> b = fix(10*rand(2,1)) b = 1 2 >> format rat % display the solution in rational format >> x0 = R\b % finds a basic solution, which has at most m nonzero components x0 = 0 5/7 0 11/7