%% General Solution of Underdetermined System of Equations
% Find one particular solution to an underdetermined system, and then obtain the general form for all solutions.
% Underdetermined linear systems \textrm{Ax}=b involve more unknowns than equations. An underdetermined system can have infinitely many solutions or no solution. When the system has infinitely many solutions, they all lie on a line. The points on the line are all obtained with linear combinations of the null space vectors.
%
% Create a 2-by-4 coefficient matrix and use backslash to solve the equation Ax_0 =b, where b is a vector of ones. Backslash calculates a least-squares solution to the problem.

A = [1 8 15 67; 7 14 16 3]

%

b = ones(2,1);
x0 = A\b

%
% The complete general solution to the underdetermined system has the form x=x_0 +\textrm{Ny}, where:
% N is the null space of A.
% y is any vector of proper length.
% x_0 is the solution computed by backslash.
% Calculate the null space of A, and then use the result to construct another solution to the system of equations. Check that the new solution satisfies \textrm{Ax}=b, up to roundoff error.

N = null(A)

%

x = x0 + N*[1; -2]

%

norm(A*x-b)

%
% Copyright 2018 The MathWorks, Inc.
%
%