MATLAB: How to fit implicit function to data

implicit equationMATLABnonlinear fit

I have these data points
data=[0 1
0.355257 0.726061
0.749002 0.382696
1 0
2.401699 -0.9817
3.049682 -1.49588
4.105308 -2.51708
3.419108 -2.79514
1.784289 -2.188
0.763907 -1.56124
0 -1];
I need to fit this implicit function to the data
f = @(x,y) abs(x)^a + abs(y)^b +c*x*y-1;
where a, b, c are the 3 positive parameters to be estimated.
Can anyone help me?

Best Answer

I'll just throw it into the curve fitting toolbox, although any tool would have sufficed for a first try. You should recognize that other tools, such as lsqnonlin from the optimization toolbox, nlinfit from stats TB, etc., would not require a major change to make them solve this too.
z = ones(11,1);
ft = fittype( @(a,b,c,x,y) abs(x).^a + abs(y).^b +c*x.*y, ...
'independent', {'x', 'y'},'dependent', 'z' );
mdl = fit(data,z,ft,'startpoint',[1 1 1])
General model:
mdl(x,y) = abs(x).^a+abs(y).^b+c*x.*y
Coefficients (with 95% confidence bounds):
a = 1.868 (1.805, 1.932)
b = 2.355 (2.27, 2.441)
c = 2.112 (1.944, 2.279)
mdl(data)
ans =
1
1.1598
1.2921
1
1.1184
0.97943
0.96971
1.0215
1.0299
0.94193
1
It seems to have worked reasonably. Note the CFT does not provide for bound constraints on the parameters. So if any of a,b,c were going negative, I would have needed to use another tool for the task, or been more creative in my use of fit.
One nice feature of the CFT is it tells me if the parameters are going near zero, in the case of parameters that are desired to bo NOT less than zero. Here, the confidence bounds provided by fit tell me that it would not be considering zero for any of them.
A problem with a fit like this, is it is not really what you probably want, in the sense that it would be nice if it were some sort of orthogonal fit, minimizing the an orthogonal distance of the points to the curve. As well, the fitting tool makes implicit assumptions about the "noise" structrue in the data, that are surely not valid in this case. Remember that z (the target here) was constant at 1. What noise? Don't got no steenkin' noise. Not in z at least.
So, really this is a variation of an errors in variables problem. And one thing you should know about errors in variables problems, is they can be nasty as hell to solve. As well, the result can have biases in the parameters, that there will be specific points that will have considerably more weight in your final result than others, and noise in your data (thus in x and in y) can do strange things.
Regardless, did it work?
syms X Y
fimplicit(abs(X).^mdl.a + abs(Y).^mdl.b + mdl.c*X.*Y - 1)
hold on
grid on
plot(x,y,'ro')
Could be better, could be worse. As I said though, true orthogonal fits are way more difficult to implement than the simple thing I did here.