# Polynominal Fitting Constrained in 1 Coefficient

조회 수: 3 (최근 30일)
Mark Whirdy 2012년 12월 19일
x = [0;7.8438;15.6493;23.4767;31.2822;39.0986;46.9123];
y = [1;0.8990;0.7102;0.5747;0.4717;0.3766;0.2956];
p = polyfit(x,y,5); % coefficient-set p in polynominal function f(x) = p(6)*x^5 + p(5)*x^4 + ... + p(1)
y_hat = polyval(p,x);
Here y_hat(1) is 1.0001, i.e. f(0) = 1.0001
I would like to fit a 5deg polynominal to y,x subject to the constraint that f(0) = 1 exactly.
I suspect its a case for fmincon, any other ideas? (I don't want to use splines)

댓글을 달려면 로그인하십시오.

### 채택된 답변

Walter Roberson 2012년 12월 19일
f(0) = 1 exactly implies that p(1) = 1 exactly. So subtract that 1 from each y value.
y1 = y - 1;
Now, hand-waving time: subtract the p(1) from the polynomial, and factor the x. You get x * (p(6) * x^4 + p(5) * x^3 + p(4) * x^2 + p(3) * x + p(2)). So (wave, wave) divide your y1 by x,
y1divx = y1(2:end) ./ x(2:end); %remove the (0,1) pair
leaving (wave, wave) p(6) * x^4 + p(5) * x^3 + p(4) * x^2 + p(3) * x + p(2) to be fit by a 4th order polynomial:
p1divx = polyfit(x(2:end), y1div, 4);
y1divx_hat = polyval(p1divx, x);
y1_hat = y1divx_hat .* x + 1; %undo division by x and subtraction of 1
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
Mark Whirdy 2012년 12월 19일
nice job, thanks Walter

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by