Using lsqcurvefit or nlinfit correctly with some data (possibly power law)
조회 수: 3 (최근 30일)
이전 댓글 표시
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)
댓글 수: 0
답변 (2개)
the cyclist
2015년 9월 9일
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.
댓글 수: 0
Star Strider
2015년 9월 9일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Least Squares에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!