필터 지우기
필터 지우기

How to get the value of slopes of pchip at the enpoints?

조회 수: 3 (최근 30일)
David Gillcrist
David Gillcrist 2024년 1월 7일
댓글: David Gillcrist 2024년 1월 8일
I'm using pchip to interpolate a set of data X. After getting the interpolation, I'm trying to have functions g and f, connect to the endpoints of the interpolation. I want g and f to have the same slopes where they connect to the endpoints. Is there a convenient way to get the values of the slopes of the pchip interpolation?

채택된 답변

Paul
Paul 2024년 1월 7일
The doc page pchip (under the Output Arguments, pp section) shows how the interpolationg polynominal is formed for each interval based on the breakpoints and the pp coefficients, from which it should be straighforward to compute the derivative at the leading and trailing edges of the first and last intervals respectively.
x = 0:.1:1;y=sin(x);
pp = pchip(x,y);
pp
pp = struct with fields:
form: 'pp' breaks: [0 0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1] coefs: [10×4 double] pieces: 10 order: 4 dim: 1
Not sure why pp.oder = 4. That seems odd for a cubic polynomial.
  댓글 수: 1
David Gillcrist
David Gillcrist 2024년 1월 8일
It looks like it counts the constant coefficient as a dimension. I should be able to use this to get the slope values there.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2024년 1월 7일
편집: Matt J 2024년 1월 7일
You don't need to determine the end slopes to extrapolate X. Just use the 'extrap' option to obtain values where desired outside the boundaries of X.
You could also do a finite-difference approximation, e.g.,
x=sort(rand(1,10)); y=rand(size(x)); f=@(z) interp1(x,y,z,'pchip','extrap');
ye=y(end); delta=eps(ye);
endslope = ( f(ye+delta) - f(ye) )/delta
endslope = 24

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by