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 中查找有关 Interpolation 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by