custom equation fit - function value and YDATA sizes are not equal

1 回表示 (過去 30 日間)
Birsen Ayaz-Maierhafer
Birsen Ayaz-Maierhafer 2022 年 7 月 7 日
回答済み: Sam Chak 2022 年 7 月 7 日
Hello,
I have data to make a fit with custom equation and would like to find the 3 parameters using lsqcurvefit
F = @(x,xdata) (x(1)+(x(2)/xdata^2))*exp(-xdata/x(3));
Here is my code:
****************
load("mydata.mat")
t = mydata(:,1);
y=mydata(:,2);
plot(t,y,'ro')
F = @(x,xdata) (x(1)+(x(2)/xdata.^2))*exp(-xdata/x(3));
x0 = [1 1 7];
[x,resnorm,~,exitflag,output] = lsqcurvefit(F,x0,t,y)
hold on
plot(t,F(x,t))
hold off
set(gca, 'YScale', 'log')
**********************************
X(1), x(2) and x(3) are the coefficient I would like to find out. When I run I got the following error:
Function value and YDATA sizes are not equal
I searched and find an example at:
mentioning that I need to elementwise operations to declare your function.
I tried make mine as elementawise but so far it did not work. How I make my equation elamemntalwise?
Thank you
Birsen

採用された回答

Sam Chak
Sam Chak 2022 年 7 月 7 日
Hi Birsen
I think there should be dots here:
F = @(x,xdata) (x(1) + (x(2)./(xdata.^2))).*exp(- xdata/x(3));

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by