Counterpart of Maple's LSSolve in Mathematica
According to the document of LSSolve
:
The
LSSolve
command solves a least-squares (LS) problem, which involves computing the minimum of a real-valued objective function having the form $$\frac{1}{2}(f_1(x)^2+f_2(x^2)+…+f_q(x)^2)$$ where $x$ is a vector of problem.
So its analog in Mathematica seems to be FindMinimum
with a specific function to be minimized. We should be able to obtain (almost) the same result with:
Clear@lSSolve
lSSolve[obj_List, constr___, x_, opt : OptionsPattern[FindMinimum]] :=
FindMinimum[{1/2 obj^2 // Total, constr}, x, opt]
lSSolve[obj_, rest__] := lSSolve[{obj}, rest]
Let's test with the examples given in the document and your question:
Case 1
Maple:
LSSolve([x-2, x-6, x-9]);
(* [12.3333333333333321, [x = 5.66666666666667]]*)
Mathematica:
lSSolve[{x - 2, x - 6, x - 9}, x]
(* {12.3333, {x -> 5.66667}} *)
Case 2
Maple:
LSSolve([x^3-2, x^2-6, x^2-9], initialpoint = {x = 1});
(* [27.5839512531713, [x = 1.75156454919679]]*)
Mathematica:
lSSolve[{x^3 - 2, x^2 - 6, x^2 - 9}, {x, 1}]
(* {27.584, {x -> 1.75156}} *)
Case 3
Maple:
LSSolve([x-1, y-1, z-1], {x <= 0, 6*x+3*y <= 1}, initialpoint = {x = -1, y = 1});
(* [0.711111111111111138, [x = -0.0666666666666667, y = 0.466666666666667, z = 1.]]*)
Mathematica:
lSSolve[{x - 1, y - 1, z - 1}, {x <= 0, 6 x + 3 y <= 1}, {{x, -1}, {y, 1}, z}]
(* {0.711111, {x -> -0.0666676, y -> 0.466668, z -> 1.}} *)
Case 4
Maple:
LSSolve([x-1], {(x+1)^2 <= 0});
(* [1.99998465585440166, [x = -0.999992327912486]]*)
Mathematica:
lSSolve[x - 1, (x + 1)^2 <= 0, x]
(* {2., {x -> -1.}} *)
Case 5: Example in your question
eq1 = -0.3007024038 c[2]^2 + (-(0.4990858944/10^2) - 0.3007024038 c[1]) c[2];
eq2 = -0.2004682692 c[2]^2 + (-(0.2495429472/10^2) - 0.1503512019 c[1]) c[2];
eq3 = -0.1503512019 c[2]^2 + (-(0.1663619648/10^2) - 0.1002341346 c[1]) c[2];
eq4 = c[0] + c[1] + c[2] - 1;
lSSolve[{eq1, eq2, eq3, eq4}, c /@ Range[0, 2]]
(* {1.58921*10^-33, {c[0] -> 1.0166, c[1] -> -0.0165973, c[2] -> 7.45058*10^-9}} *)
Slightly different, but according to objective function value, result of Mathematica is better.
Is this not what you want ?
In[6]:= NMinimize[eq1^2 + eq2^2 + eq3^2 + eq4^2, {c[0], c[1], c[2]}]
Out[6]= {1.94723*10^-27, {c[0] -> 1.01633, c[1] -> -0.0163307,
c[2] -> 4.71816*10^-10}}