Questions about ppval in piecewise polynomial
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponses (1)
John D'Errico
le 2 Avr 2016
Modifié(e) : John D'Errico
le 2 Avr 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;
0 commentaires
Voir également
Catégories
En savoir plus sur Polynomials dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!