Polynominal Fitting Constrained in 1 Coefficient

2 visualizaciones (últimos 30 días)
Mark Whirdy
Mark Whirdy el 19 de Dic. de 2012
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)

Respuesta aceptada

Walter Roberson
Walter Roberson el 19 de Dic. de 2012
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

Más respuestas (0)

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by