I know there is a LeastSquares function, but I am wondering how you’d implement it using FindMinimum? For example:
In[148]:= A={{1,1},{1,2},{1,3}};
b={7,7,8};
In[154]:= FindMinimum[Norm[A.k-b],{k,ConstantArray[0,Last@Dimensions[A]]}]
During evaluation of In[154]:= FindMinimum::nrnum: The function value {12.7279,12.7279,12.7279} is not a real number at {k} = {{0.,0.}}. >>
Out[154]= FindMinimum[Norm[A.k-b],{k,ConstantArray[0,Last[Dimensions[A]]]}]
In[1]:= A = {{1, 1}, {1, 2}, {1, 3}};
b = {7, 7, 8};
vars = Table[ToExpression["v" <> ToString[i]], {i, 1, Last[Dimensions[A]]}];
FindMinimum[Norm[A.vars - b], vars]
During evaluation of In[1]:= FindMinimum::lstol: The line search decreased the step size to within the tolerance
specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the function. You may
need more than MachinePrecision digits of working precision to meet these tolerances. >>
Out[4]= {0.408248, {v1 -> 6.33333, v2 -> 0.5}}
In[5]:= N[LeastSquares[A, b]]
Out[5]= {6.33333, 0.5}