# least square fitting of multiple variable equation (error: too many input arguments)

3 views (last 30 days)
JongGu Han on 6 Mar 2022
Edited: Torsten on 6 Mar 2022
I have a data file constituting 2 lines (EXP_x, EXP_y) and want to fit it with the equation mentioned in the second paragraph which has two variables (w, a).
here is the code
global EXP_x
global EXP_y
EXP_x=EXP(:,1);
EXP_y=EXP(:,2);
w0=[0 0.5];
lb=[0 0.5];
ub=[20 2];
x=lsqcurvefit(@distribution,w0,EXP_x,EXP_y,lb,ub);
function calculation=distribution(w,a)
global EXP_x
global EXP_y
gamma=@(t) integral(t.^(w-1).*exp(-t),0,inf);
calculation=(a/((w^(3/2))*gamma)*exp(-(EXP_x/w).^a))
end
it doesn't work. Error: "lsqcurvefit too many input arguments in that case"
If it is not the proper case to use the lsqcurvefit, please tell me the replacement method.
Thank you.

Torsten on 6 Mar 2022
Edited: Torsten on 6 Mar 2022
x=lsqcurvefit(@(w)distribution(w(1),w(2)),w0,EXP_x,EXP_y,lb,ub);
x=lsqcurvefit(@distribution,w0,EXP_x,EXP_y,lb,ub);
and
function calculation=distribution(w,a)
global EXP_x
global EXP_y
gammah = gamma(w);
calculation=(a/((w^(3/2))*gammah)*exp(-(EXP_x/w).^a))
end
function calculation=distribution(w,a)
global EXP_x
global EXP_y
gamma=@(t) integral(t.^(w-1).*exp(-t),0,inf);
calculation=(a/((w^(3/2))*gamma)*exp(-(EXP_x/w).^a))
end

### Categories

Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange

R2020b

### Community Treasure Hunt

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

Start Hunting!