nonlinear least squares fit
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (2)
Ivan van der Kroon
le 10 Juin 2011
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 commentaires
Voir également
Catégories
En savoir plus sur Get Started with Curve Fitting Toolbox dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!