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

조회 수: 1 (최근 30일)
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 CenterFile Exchange에서 Get 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