フィルターのクリア

Questions about ppval in piecewise polynomial

2 ビュー (過去 30 日間)
Bo Wang
Bo Wang 2016 年 4 月 1 日
編集済み: John D'Errico 2016 年 4 月 2 日
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?

回答 (1 件)

John D'Errico
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;

カテゴリ

Help Center および File ExchangePolynomials についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by