matlab ppval understanding of centering/displacement in breaks

2 visualizaciones (últimos 30 días)
Thales
Thales el 24 de Nov. de 2019
Comentada: Thales el 25 de Nov. de 2019
The documentation on the ppval function gives the following example:
breaks = [0 4 10 15];
coefs = [0 1 -1 1 1; 0 0 1 -2 53; -1 6 1 4 77];
pp = mkpp(breaks,coefs)
xq = 0:0.01:15;
plot(xq,ppval(pp,xq))
line([4 4],ylim,'LineStyle','--','Color','k')
line([10 10],ylim,'LineStyle','--','Color','k')
I was trying to understando the function, but couldn't figure out why the function behaves as it does.
My understanding of the function was that, from the interval [0,4] the polynomial was p1=[0 1 -1 1 1], from [4 10], p2=[0 0 1 -2 53], and from [10 15], p3=[-1 6 1 4 77]. To my surprise, this is not exactly the case.
If you evaluate the polynomials at, say, x=4, you have:
p1=[0 1 -1 1 1];
p2=[0 0 1 -2 53];
y1 = polyval(p1,4)
y2 = polyval(p2,4)
And you can see y1~=y2. The behaviour of the ppval function calculates the polynomial on the range [4 10] with a displacement. You will get both values to be the same evaluaten the second polynomial at
y2 = polyval(p2,4-4)
So, ppval function evaluates the polynomial on the range [4 10], but the x values are from [0 6]. Why MATLAB does it this way?
And how do I define a polynomial for each range, so that MATLAB uses the polynomial exactly at the point specified (as I first thought the function would behave)?

Respuestas (1)

Steven Lord
Steven Lord el 25 de Nov. de 2019
The documentation page for ppval says that the pp input is a struct array created by a function like mkpp. If we look at the mkpp documentation page we can see what the coefficients represent. Note that the coefficients represent a polynomial but it's not a polynomial in x. It's a polynomial in x - breaks(i). Try calling polyval to evaluate the polynomial at (x - breaks(i)).
  1 comentario
Thales
Thales el 25 de Nov. de 2019
I see. But I am curious. Why is it so? Why are the polinomial defined in x-breaks(i)?
And what is a good/fast way to define the polinomials in x?

Iniciar sesión para comentar.

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