Polynominal Fitting Constrained in 1 Coefficient
2 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!