Say,
$A= \begin{pmatrix} 1 & 0 &1 \\ 0 & 1 &1 \\ 0 &0 &0 \end{pmatrix}$ and $\overrightarrow{b}= \begin{pmatrix} 8 \\ -5 \\ 0 \end{pmatrix}$
and I want to solve the system $A\overrightarrow{x}=\overrightarrow{b}$. The solution is
$\overrightarrow{x}= \begin{pmatrix} 8\\ -5 \\ 0 \end{pmatrix} + k\begin{pmatrix} -1\\ -1 \\ 1 \end{pmatrix}$
How can I solve this kind of systems using Matlab?
The backslash function (x=A\b) of course doesn't work because nullity(A) isn't 0.
I can manage to solve this kind of problems using the Symbolic Toolbox (see below), but isn't there a Matlab built-in function (similar to the backslash) that can solve this directly?
A=[1 0 0; 0 1 0; 1 1 0]'
b=[8 -5 0]'
x=sym('x',[3,1]);
eqn= A*x==b;
[XX(1,1),XX(2,1),XX(3,1),params,conds]=solve(eqn,x,'ReturnConditions',true);
vv1=diff(XX,params(1));
vv0=XX-params(1)*vv1;
X=matlabFunction(XX)
v0=eval(vv0)
v1=eval(vv1)
%the solution is x=v0+k*v1
You should use MATLAB
pinv()function which solves Least Squares problem using the SVD.This method is slower yet much more robust than using
\(It always returns the least norm solution).By itself it can handle problems with large condition number (Having eigen value which is zero -> Condition number which is infinite are included).
If you are dealing with edge cases (Really extreme condition number) you should use the
tolparameter.This parameter allows you to threshold small eigen values.