I have a homework assignment that tasks me with writing a MATLAB function and I'm worried that I've missed something in my current answer. The function returns the complete solution to a linear equation of the form Ax=b, where A is a square matrix, and b is a vector of the appropriate dimension. The first line of the function is
function [Bs, Ns] = a(A, b)
where Bs
is the basic solution (a vector), and Ns
is the null solution - a matrix whose columns are a basis of the null space of A. There are also a few considerations in terms of the code used:
The code I've written is below.
function [Bs, Ns] = a(A, b)
ncols = size(A, 2);
x = pinv(A)*b;
Bs = x;
if ncols == rank(A)
Ns = zeros(ncols,1);
else
Ns = null(A);
end
end
The simplicity of my function has me worried that I've missed something (assignment is worth 4% of final grade) - either in my interpretation of the listed considerations, or that there are test cases which will cause errors/warnings. Any input would be appreciated.