nonlinear least squares fit
2 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
sorry, but I am trying to fit some data and don't get where I am going wrong. I have defined my function
function F = nonlinfun(x,t)
F = x(1)*t.^2 + x(2)*t + x(3) + x(4)*sin(2*pi*(t+x(5)));
and then I am trying to do the fit
clear;
read = importdata('c:/data.txt',',');
data = read(:,7);
n = length(data);
t = 1:n;
x0 = rand(5,1);
x0 = 300;
[x,resnorm] = lsqcurvefit(@nonlinfun,x0,t,data);
The data I am trying to fit can be found here:
(coumn 7) if anyone is interested. I saved it in a file 'data.txt' and reading that out works. When I try to run above sequence Matlab returns the following error:
Function value and YDATA sizes are incommensurate.
I got the simple Matlab examples to work but have tried unsuccessfully all day with the atmospheric data. I guess there is something simple I am overlooking?
Thanks for the help.
0 个评论
回答(2 个)
Ivan van der Kroon
2011-6-10
t is a row-vector while data is a column-vector. Change it to
t=(1:n)';
Btw, I got
x= 0.0012
0.1046
-7.6955
-2.0487
-3.2998
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!