Reputation: 477
For 2D space I have used lsqcurvefit. But for 3D space I haven't found any easy function.
the function I'm trying to fit has the form something like this:
z = f(x,y) = a+b*x+c*e^(-y/d)
I would like to know if there is any tool box or function for fitting this kind of data the in least square sense. Or can lsqcurvefit can be used in some way?
Otherwise I think I have to write something myself. Back to theory reading I guess.
SO, Any help will be appreciated.
Thanks.
Upvotes: 0
Views: 1988
Reputation: 1454
lsqcurvefit should be able to handle the function given in the question. I don't have a way to verify this code right now, but I believe that it should work:
clear variables
f = @(p, x)(p(1)+p(2)*x(:, 1)+p(3)*e.^(-x(:, 2)/p(4)));
xydata = [ 0 0 ; 1 1 ; 2 2 ; 3 3 ];
zdata = [ 0 ; 1 ; 2 ; 3 ];
x = lsqcurvefit(f, [ 0 0 0 0 ], xydata, zdata);
Upvotes: 1