Filter löschen
Filter löschen

Questions about ppval in piecewise polynomial

2 Ansichten (letzte 30 Tage)
Bo Wang
Bo Wang am 1 Apr. 2016
Bearbeitet: John D'Errico am 2 Apr. 2016
I have a question about piecewise polynomial.
If I use t=pp.coefs to get the coefficients about the polynomial.
Then I use
[m n]=size(t);
for i=1:n-1
t(:,i)=i.*t(:,i);
end
to get the new coefficients after differentiate it. How can I use ppval again to evaluate the polynomial with this new coefficients?

Antworten (1)

John D'Errico
John D'Errico am 2 Apr. 2016
Bearbeitet: John D'Errico am 2 Apr. 2016
You only think that this differentiates the polynomial. But it does not. In fact, look at the result. For example, consider the polynomial represented by coefficients:
t = [1 2 3 4]
so the polynomial is
x^3 + 2^x^2 + 3*x + 4
Remember in MATLAB, the polynomial is represented by the coefficients starting from the highest order first.
Now, try the code you wrote. What vector t results?
[m n]=size(t);
for i=1:n-1
t(:,i)=i.*t(:,i);
end
t
t =
1 4 9 4
so:
x^3 + 4*x + 9*x^2 + 4
Clearly that is the wrong derivative. Instead, try this:
M = diag([3 2 1],1);
t = [1 2 3 4];
t*M
ans =
0 3 4 3
That is the polynomial
0*x^3 + 3*x^2 + 4*x + 3
Which is the proper derivative polynomial. Just stuff it back into the proper field in pp.
pp.coefs = pp.coefs*M;

Kategorien

Mehr zu Polynomials finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by