How to fit function with 3 variables

kx=-0.5:0.00666:0.5;
ky=kx;
w=5:0.1:20;
KXYW=[kx(:) ky(:) w(:)];
f = @(KxyW,b) b(1)-((b(2)*(KxyW(:,1)-X0)-b(3)*(KxyW(:,2)-Y0))/b(4)).^2+((b(3)*(KxyW(:,1)-X0)+b(2)*(KxyW(:,2)-Y0))/b(5)).^2+((KxyW(:,3)-W0)/b(6)).^2;
B0=[0.008 0.5 0.5 0.1 0.1 0.5];
B = lsqcurvefit(f,B0,KXYW,M);
What is important M is size 151x151x151 so when i run this code i got this statment:
Error using lsqcurvefit (line 262)
Function value and YDATA sizes are not equal.
I know f should be the same size as M but i dont know how to do this.
Generaly my task is to find parameters (b(1),b(2)...) of fitted function to area near maximum value. I did find max of M.
This is result of calling : surface(M(:,:,6)) (so you know how it's look, there is 151 of this)

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Nonlinear Least Squares (Curve Fitting) 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by