From: Joshua on
I am currently working on a program in matlab where the use of piecewise polynomials would be quite convenient.

Unfortunately, as I recently discovered, the piecewise polynomial object type (pp) included with matlab takes the constants for the polynomail you pass it, assumes those coefficients are for a polynomial centered at the origin, and then shifts the polynomial into the piecewise section you are defining the polynomial over. This is at lest true for construction of the object using the mkpp function.

I would greatly prefer to simply define a segment of a polynomial using the actual coeficients. For example, if the polynomial is x^2 - 1 over the range 1 < x < 2, I would simply pass the coeficients 1, 0, 1.

Is anyone aware of an alternate form of the piecewise polynomial object where it does -not- perform the shifts, or a work around that is low in computational requirements?
From: Bruno Luong on
"Joshua " <nosend.fakeemail(a)gmail.com> wrote in message <i3d4ls$nka$1(a)fred.mathworks.com>...
> I am currently working on a program in matlab where the use of piecewise polynomials would be quite convenient.
>
> Unfortunately, as I recently discovered, the piecewise polynomial object type (pp) included with matlab takes the constants for the polynomail you pass it, assumes those coefficients are for a polynomial centered at the origin, and then shifts the polynomial into the piecewise section you are defining the polynomial over. This is at lest true for construction of the object using the mkpp function.
>
> I would greatly prefer to simply define a segment of a polynomial using the actual coeficients. For example, if the polynomial is x^2 - 1 over the range 1 < x < 2, I would simply pass the coeficients 1, 0, 1.

There is a numerical reason to leads to why the polynomial to be recentered about the left break point in the pp form. They are made to privilege the accuracy, not for user convenience.

>
> Is anyone aware of an alternate form of the piecewise polynomial object where it does -not- perform the shifts, or a work around that is low in computational requirements?

Depending on your subjective evaluation of what is "low". IMO, just shift it. To compute the coefficient of shifted polynomial, you can use convolution to perform the products of shifted terms then add to shifted monomials together. This can't be too long. Here is the tool of mine to shift a polynomial

function Q = polyshift(P, a)
% function Q = polyshift(P, a)
%
% Compute the coefficients of shifted polynomial P(x+a).
%
% P and Q are polynomial coefficients, i.e.,
% vector of length N+1 whose elements are the coefficients of the
% polynomial in descending powers.

L = length(P);
N = L-1;

powers= cell(1, N+1);

if N>0
powers{1} = 1;
powers{2} = [1 a]; % (x+a)
p2 = 1;
r = 1;
Q = zeros(size(P));
Q(L) = P(L);
Q(N:L) = Q(N:L) + P(N)*powers{2};
for k=2:N
Ck = conv(powers{p2+1}, powers{r+1}, 'full');
ind = L-length(Ck)+1:L;
Q(ind) = Q(ind) + P(L-k)*Ck;
powers{k+1} = Ck;
if (p2==r)
p2 = 2*p2;
r = 1;
else
r = r+1;
end
end % for-loop
else
Q = P;
end

end %% polyshift

%% Check on command line:

>> P=rand(1,5)

P =

0.2238 0.7513 0.2551 0.5060 0.6991

>> a=rand

a =

0.8909

>> x=rand

x =

0.9593

>> Q = polyshift(P, a)

Q =

0.2238 1.5488 3.3289 3.3824 2.0245

>> polyval(P,x+a)

ans =

9.8894

>> polyval(Q,x)

ans =

9.8894


% Bruno
From: Joshua on
Bruno, I apologize for the delay in my response.

Thank you for offering the your procedure for my use, but rather than shifting the information one way, and then the other, I think I'll just keep it in matrix form and do the evaluations myself, it seems like it would have lower overhead, and also improve the accuracy of the end results.

-Josh

"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <i3dold$ck9$1(a)fred.mathworks.com>...
> Depending on your subjective evaluation of what is "low". IMO, just shift it. To compute the coefficient of shifted polynomial, you can use convolution to perform the products of shifted terms then add to shifted monomials together. This can't be too long. Here is the tool of mine to shift a polynomial