lsqcurvefit does not fit correctly to my data

2 次查看(过去 30 天)
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

回答(1 个)

Matt J
Matt J 2013-6-11
编辑:Matt J 2013-6-11
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 个评论
Mona Mahboob Kanafi
Dear Matt,
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. As I said before, I believe it's the problem of initial points which I'm not able to guess correctly.
Matt J
Matt J 2013-6-12
编辑:Matt J 2013-6-12
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.

请先登录,再进行评论。

类别

Help CenterFile 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!

Translated by