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 ExchangeProblem-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