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!