% Solving linear systems clc disp(' Solving Linear Systems') disp(' ') disp('Define a matrix') disp('>> A = [1 2 5; 4 5 6; 7 8 9]') A = [1 2 5; 4 5 6; 7 8 9] disp('Paused...Please hit a key to continue') pause disp('and a right-hand side (column) vector') disp('>> b = [2 5 7]'' ') b = [2 5 7]' disp('Paused...Please hit a key to continue') pause disp('To solve Ax=b for x we type') disp('>> x = A\b') x = A\b disp('Paused...Please hit a key to continue') pause disp('Check the answer') disp('>> A*x - b') A*x-b disp('Paused...Please hit a key to continue') pause disp('Define another (singular) matrix') disp('>> A = [1 2 3; 4 5 6; 7 8 9; 10 11 12]') A = [1 2 3; 4 5 6; 7 8 9; 10 11 12] disp('Paused...Please hit a key to continue') pause disp('>> rank(A)') rank(A) disp('Paused...Please hit a key to continue') pause disp('and a right-hand side (column) vector') disp('>> b = [2 5 7 8]'' ') b = [2 5 7 8]' disp('Paused...Please hit a key to continue') pause disp('Now the (least-squares) solution is given by') disp('>> x = A\b') x = A\b disp('Paused...Please hit a key to continue') pause disp('Note that x does NOT satisfy the linear system') disp('>> A*x - b') A*x-b