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

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
EXP=textread('filename')
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
Torsten 2022년 3월 6일
편집: Torsten 2022년 3월 6일
x=lsqcurvefit(@(w)distribution(w(1),w(2)),w0,EXP_x,EXP_y,lb,ub);
instead of
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
instead of
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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2022년 3월 6일

편집:

2022년 3월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by