Questions about ppval in piecewise polynomial
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
John D'Errico
2016-4-2
编辑:John D'Errico
2016-4-2
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polynomials 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!