Force polynomial fit through multiple points

조회 수: 6 (최근 30일)
Bernoulli Lizard
Bernoulli Lizard 2013년 4월 29일
I have a set of x, y data that I want to fit to a quadratic polynomial. Is it possible to force the fit through BOTH zero points?
  댓글 수: 3
Bernoulli Lizard
Bernoulli Lizard 2013년 4월 29일
The model is a third order polynomial: -a*x^2 + b*x + c. The fit must pass through the points (x1,0) and (x2,0). In theory the y value must be exactly zero at x1 and x2, however it is impossible to actually take data at those points.
I'm not sure where the idea of y(x) = c*(x-x1)*(x-x2) came from, but I do not think that that is what I want.
Kye Taylor
Kye Taylor 2013년 4월 29일
편집: Kye Taylor 2013년 4월 29일
Remember that a third order polynomial has the form
g(x) = a*x^3 + b*x^2 + c*x + d
A second order polynomial has the form
f(x) = a*x^2 + b*x + c
This same second order polynomial can be written
f(x) = a*(x-x1)*(x-x2)
where x1 and x2 are the roots of the polynomial and a is the coefficient on x^2. So the model y(x) = constant*(x-x1)*(x-x2) is exactly what you want.

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

답변 (1개)

Kye Taylor
Kye Taylor 2013년 4월 29일
편집: Kye Taylor 2013년 4월 30일
I assume your data is given by two row vectors xData and yData, given for example by
xData = linspace(-2,2);
yData = 2.3*(xData-1).*(xData+1) + 0.2*rand(size(xData));
Then, since you know the roots, try this
% the roots you know
x1 = 1;
x2 = -1;
% the coefficient that makes the model
% y(x) = a*(x-x1)*x-x2) fit the data with
% smallest squared-error In other words
% a minimizes l2-error in a*designMatrix - yData'
designMatrix = ((xData-x1).*(xData-x2))';
a = designMatrix\yData'
plot(xData, yData, 'ko', xData, a*designMatrix, 'r-')
legend('Data','Model')

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by