0

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.

ponir
  • 447
  • 7
  • 20
  • What is the problem with using lsqcurvefit for this function? It supports functions with multiple input arguments. – nojka_kruva Jun 29 '14 at 12:50
  • I that case can you tell me how to use it? I tried to write _xdata_ as a 2D vector. [1 2 3; 2 3 4] hoping it would take inputs as [x;y]. Is there any other way? – ponir Jun 29 '14 at 13:32

1 Answers1

1

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);
nojka_kruva
  • 1,454
  • 1
  • 10
  • 23
  • It works. But f should be defined as `f=@(ab,x) (ab(1)+ab(2).*x(:,1)+ab(3).*exp(-x(:,2)/ab(4)))`. Edit it when you have time. Now I see what I did wrong when I tried it. Thanks for the help. – ponir Jun 29 '14 at 17:07