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

1 vue (au cours des 30 derniers jours)
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

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by