Trying to find best fit of the shape y = a/(x-b)+c. Getting warning of badly conditioned polynomial sometimes but not always.
조회 수: 5 (최근 30일)
이전 댓글 표시
Arrays x and y fit the equation y = a/(x-b)+c almost perfectly, but this was the only technique I could come up with to incorporate the x-shift caused by the constant 'b'.
f = @(b)(polyfitNormR((x - b).^-1, y));
xAdjustment = fminsearch(f,0);
function [normr] = polyfitNormR(x,y)
[~,errorData] = polyfit(x,y,1);
normr = errorData.normr;
end
It works perfectly every time, but I have one particular instance where I get a bunch of warnings and it runs extremely slowly. The fits still look good but I would like to avoid a code that causes warnings in some circumstances. The reason it shows a warning is because fminsearch somehow reduces the array 'x' to essentially the same number on the order of 1E-4 or smaller (even though I am originally passing an array on the order of 1E-1).
Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce the degree of the polynomial, or try centering and
scaling as described in HELP POLYFIT.
I am looking for either a different technique to find this best fit, or an explanation of how to amend my code to avoid this warning using the current technique.
댓글 수: 0
답변 (1개)
Ajay Pattassery
2019년 8월 9일
Try scaling and shifting the input x such that the mean of x is zero and the standard deviation as one. This scaling and shifting improves the numerical properties of both the polynomial and the fitting algorithm.
The input data (x) will be automatically centered and scaled if polyfit is used with three output values.
[p,S,mu] = polyfit(x,y,n);
mu(mu(1) is mean(x), and mu(2) is std(x)) can then be given as the fourth argument in polyval (which evaluates the polynomial p at each point in x) to convert back easily.
[y,delta] = polyval(p,x,S,mu);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!