Filter löschen
Filter löschen

Using lsqcurvefit or nlinfit correctly with some data (possibly power law)

3 Ansichten (letzte 30 Tage)
SJ B
SJ B am 9 Sep. 2015
Beantwortet: Star Strider am 9 Sep. 2015
Hi everyone,
I had a general issue with using the lsqcurvefit and nlinfit tools. I was trying to curve fit some data with power law (or some other nonlinear function possibly but I'm just experimenting) and I'm not sure why my code is having issues:
I'm getting the error "Solver stopped prematurely. lsqcurvefit stopped because it exceeded the function evaluation limit, options.MaxFunEvals = 200 (the default value)..."
I tried setting tolerances as well but I had no luck.
xdata=xlsread('yadi.xlsx','A34:A45');
ydata=xlsread('yadi.xlsx','B34:B45');
fun=@(x,xdata)x(1)+x(2)*xdata.^x(3);
x0=[1,500000,-0.15];
x=lsqcurvefit(fun,x0,xdata,ydata)

Antworten (2)

the cyclist
the cyclist am 9 Sep. 2015
My answer to this question gives a simple example of using nlinfit.
One thing to be aware of is that when people talk about a "linear fit", that is referring to the coefficients, not the independent variables. So, for example, a fit of the type
y = a + b*x + c * x^2
is a linear fit, because a, b, and c appear linearly. The fact that powers of x appear does not make that a non-linear fit (even though is non-linear in x).
So, you may be able to use a linear fitting tool after all.

Star Strider
Star Strider am 9 Sep. 2015
There are two possibilities: increase the maximum number of function evaluations, or change your initial parameter estimates. I don’t have your data, so I can’t offer specific recommendations. However I would start by experimenting with different initial parameter estimates.

Kategorien

Mehr zu Least Squares finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by