4.9 Find particular and homogenous solution to undetermined system of equations

Problem: Find the general solution to $$Ax=b$$

$\begin {bmatrix} 2 & 4 & 6 & 4\\ 2 & 5 & 7 & 6\\ 2 & 3 & 5 & 2 \end {bmatrix}\begin {bmatrix} x_{1}\\ x_{2}\\ x_{3}\\ x_{3}\end {bmatrix} =\begin {bmatrix} b_{1}\\ b_{2}\\ b_{3}\end {bmatrix} \ where\begin {bmatrix} b_{1}\\ b_{2}\\ b_{3}\end {bmatrix} =\begin {bmatrix} 4\\ 3\\ 5 \end {bmatrix}$

In Maple 11, the LinearAlgebra package was used. In Mathematica one can also get the general solution, but one must ﬁnd the Null space speciﬁcally and add it to the result from LinearSolve[] since LinearSolve[] ﬁnds particular solutions only.

In Matlab the same thing needs to be done. I am not sure now how to make Matlab give me the same particular solution as Maple and Mathematica since Matlab A$$\backslash$$b uses least square approach to determine a solution.  I am sure there is a way, will update this once I ﬁnd out.

 Mathematica vars = {x1,x2,x3,x4}; eqs ={2 x1+4 x2+6 x3+4 x4==4, 2 x1+5 x2+7 x3+6 x4==3, 2 x1+3 x2+5 x3+2 x4==5}; {b,mat} = CoefficientArrays[eqs,vars]; Normal[mat]  $\left ( {\begin {array}{cccc} 2 & 4 & 6 & 4 \\ 2 & 5 & 7 & 6 \\ 2 & 3 & 5 & 2 \\ \end {array}} \right )$ Normal[b]  Out[163]= {-4,-3,-5}  Mathematica LinearSolve gives one solution (particular solution) particularSolution = LinearSolve[mat,b]  Out[164]= {-4,1,0,0}  ﬁnd the homogenous solution (nullspace) and add it to the above particular solution homogenousSolution =Transpose[NullSpace[mat]]  $\left ( {\begin {array}{cc} 2 & -1 \\ -2 & -1 \\ 0 & 1 \\ 1 & 0 \\ \end {array}} \right )$ Add the particular solution to the homogenous solution to get the general solution fullSolution = particularSolution+homogenousSolution  $\left ( {\begin {array}{cc} -2 & -5 \\ -1 & 0 \\ 0 & 1 \\ 1 & 0 \\ \end {array}} \right )$ To obtain the general solution right away Solve can be used instead sol = Flatten[Solve[eqs,vars]] During evaluation of In[167]:= Solve::svars: Equations may not give solutions for all "solve" variables. >>  $$\left \{\text {x3}\to -\frac {\text {x1}}{2}-\frac {\text {x2}}{2}+\frac {3}{2},\text {x4}\to \frac {\text {x1}}{4}-\frac {\text {x2}}{4}-\frac {5}{4}\right \}$$ generalSolution = vars/.sol  $$\left \{\text {x1},\text {x2},-\frac {\text {x1}}{2}-\frac {\text {x2}}{2}+\frac {3} {2},\frac {\text {x1}}{4}-\frac {\text {x2}}{4}-\frac {5}{4}\right \}$$

 Matlab clear all; A=[2 4 6 4; 2 5 7 6; 2 3 5 2] b=[4 3 5]' particularSolution=A\b  Warning: Rank deficient, rank = 2, tol = 4.033641e-15. particularSolution = 0 0 1.5000 -1.2500  nullSolution=null(A,'r')  nullSolution = -1 2 -1 -2 1 0 0 1 

 Maple restart; with(LinearAlgebra); vars := x[1], x[2], x[3], x[4]; sys := 2*x[1]+4*x[2]+6*x[3]+4*x[4] = 4, 2*x[1]+5*x[2]+7*x[3]+6*x[4] = 3, 2*x[1]+3*x[2]+5*x[3]+2*x[4] = 5; eqs=, convert([sys], Vector); A, b := GenerateMatrix([sys], [vars])  A=\left [ {\begin {array}{cccc} 2&4&6&4\\ \noalign {\medskip }2&5&7&6\\ \noalign {\medskip }2&3&5&2\end {array}} \right ] b=\left [ {\begin {array}{c} 4\\ \noalign {\medskip }3\\ \noalign {\medskip }5\end {array}} \right ] general solution=, LinearSolve(A, b, free = 'x')  \left [ {\begin {array}{c} 4-x_{{3}}+2\,x_{{4}}\\ \noalign {\medskip }-1-x_{{3}}-2\,x_{{4}}\\ \noalign {\medskip }x_{{3}}\\ \noalign {\medskip }x_{{4}}\end {array}} \right ] Can solve this system to get the general solution using the solve command as follows s := solve([sys], [vars]); r := subs(op(s), [vars]); general solution=, convert(%, Vector)  \left [ {\begin {array}{c} 4-x_{{3}}+2\,x_{{4}}\\ \noalign {\medskip }-1-x_{{3}}-2\,x_{{4}}\\ \noalign {\medskip }x_{{3}}\\ \noalign {\medskip }x_{{4}}\end {array}} \right ]

WARNING: Maple sometimes reorders the result from solve() so we can get a diﬀerent ordering of the free variables as shown above.