lsqcurvefit does not fit correctly to my data
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dear all,
I want to fit a nonlinear function to my data, and here is the code I have so far:
FitFunc = @(x,xdata) x(1)./(2.*((1+((x(2)*xdata).^2)).^(x(3)/2)));
x0 = [max(ydata) 0.00001 0.9];
[mfit,resnorm,] = lsqcurvefit(FitFunc, x0, xdata, ydata)
1- I don't know whether it's the problem of my initial values or somewhere else, because when I plot my data and the fitted curve, they are so far away! I don't know what are good initial values for parameters : x(2) and x(3)
2- After fitting, for plotting the fitted curve, which of the following commands must be used?
loglog(xdata,FitFunc(x,xdata))
or
loglog(xdata, FitFunc(mfit,xdata))
P.S. I uploaded my data in two formats: '.mat' and '.xls' at link below:
https://dl.dropboxusercontent.com/u/82779497/testdata.xls
https://dl.dropboxusercontent.com/u/82779497/testdata.mat
0 comentarios
Respuestas (1)
Matt J
el 11 de Jun. de 2013
Editada: Matt J
el 11 de Jun. de 2013
We can only assume that your model is a bad fit to your ydata. Try to use simulated ydata, based on known x(i). Then, test to see if LSQCURVEFIT will recover the x(i).
2 comentarios
Matt J
el 12 de Jun. de 2013
Editada: Matt J
el 12 de Jun. de 2013
This model is exactly what has been used over and over in articles to fit data types like mine. So, it should definitely fit my data
That still assumes that whatever code is generating your ydata is working properly.
I don't know what are good initial values for parameters : x(2) and x(3)
If only these 2 variables are hard to guess initially, then you can make a SURF or CONTOUR plot of the objective function with x(1) frozen.
x1=max(ydata);
objfunc=@(x2,x3) norm(ydata - FitFunc([x1,x2,x3],xdata) ).^2
You can then look for an approximate minimizer w.r.t. x2 and x3 on the plot, which you would then feed to LSQCURVEFIT as initial guesses. If nothing else, this would let you confirm whether the initial guess is truly the problem.
Ver también
Categorías
Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!