lsqcurvefit does not fit correctly to my data

3 views (last 30 days)
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

Answers (1)

Matt J
Matt J on 11 Jun 2013
Edited: Matt J on 11 Jun 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 Comments
Mona Mahboob Kanafi
Mona Mahboob Kanafi on 12 Jun 2013
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 on 12 Jun 2013
Edited: Matt J on 12 Jun 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.

Sign in to comment.

Categories

Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!