フィルターのクリア

Derivative of piecewise polynomial using ppval

37 ビュー (過去 30 日間)
Bo Wang
Bo Wang 2016 年 3 月 31 日
コメント済み: Jon 2021 年 10 月 20 日
I have a problem about derivative of piecewise polynomial. Here is my code
function y=ppval_drv(pp,x,deriv)
%x=0:10;
%y=f(x);
%xx=linspace(0,10,200);
y=f(x);
pp=spline(x,y);
t=pp.coefs;
[m n]=size(t);
d=[n-deriv:-1:1;ones(deriv-1,n-deriv)];
d=cumsum(d,1);
d=prod(d,1);
I don't know what to do next. Can anyone give me a hint for this one? Thanks

採用された回答

John D'Errico
John D'Errico 2016 年 3 月 31 日
編集済み: John D'Errico 2016 年 4 月 5 日
Well, you could always use ppder. I've not looked at the code, but I imagine it might work.
For a cubic spline, a derivative is actually pretty easy to do, as just a matrix multiply. (For that matter any order spline in a pp form is trivial to differentiate.)
% pd is the polynomial degree of the polynomial segments,
% so for a spline created by spline, we have pd=3.
pd = 3;
D = diag(pd:-1:1,1);
% given deriv as the order of the derivative to compute
% just loop
for i = 1:deriv
pp.coefs = pp.coefs*D;
end
Untested code, but it should work.
  2 件のコメント
Dimitry Chuprakov
Dimitry Chuprakov 2021 年 7 月 29 日
Here is the path to correct ppder version for taking derivative of any piecewise polynomial including PCHIP.
Jon
Jon 2021 年 10 月 20 日
Inspired approach! I love its simplicity just using a single matrix multiply. I think you were aiming for clarifying the approach here, but, I think you actually could even further vectorize it using
pp.coefs = pp.coefs*D^deriv

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by