For FindFit I want to have a norm that just sums up all residuals.
For the sum of absolute values there is NormFunction -> (Norm[#, 1] &)
, but I don't know how to sum up residuals as they are. I tried to define my own norm but failed, for instance NormFunction -> (# &)
or NormFunction -> (Total[#] &)
.
MWE:
xdata = {1, 2, 3, 4, 5, 6, 7};
ydata = {1.2, 2.5, 2.3, 4.3, 5.9, 3.2, 4.9};
data = Transpose [{xdata, ydata}];
value = FindFit[data, a + b x , {a, b}, x,
NormFunction -> Total](*(Norm[#,1]&)*)
FindFit[data, a x Log[b + c x], {a, b, c}, x, NormFunction -> Total]
. Please show what failed and explain why you think it failed. $\endgroup$Total
, the minimum will be $-\infty$. This modification of your code gives a proper error:FindFit[data, b (x + a), {a, b}, x, NormFunction -> Total]
. (Technically, a norm should be positive-definite.) $\endgroup$FindFit[data, b (x + a), {a, b}, x, NormFunction -> Abs@*Total]
. The norm is positive but not definite. Consequently, there should be infinitely many solutions for which the sum of the residuals is zero.FindFit
returns one of them along with an error. But it does return one solution. And different starting points return others:FindFit[data, b (x + a), {{a, -2}, {b, 3}}, x, NormFunction -> Abs@*Total]
$\endgroup$t
withvalue = Thread[{a, b} -> (1 - t) ({a, b} /. value1) + t ({a, b} /. value2)]
. (As long as you understand that I don't know why you want solve such a problem, but it seems a well-defined problem, even if not a common fitting problem.) $\endgroup$