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

2 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

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

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Curve Fitting Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by