About cubic spline function spline code!

조회 수: 6 (최근 30일)
jing liu
jing liu 2012년 3월 4일
In the spline function code I find this code
% construct piecewise cubic Hermite interpolant
% to values and computed slopes
pp = pwch(x,y,s,dx,divdif); pp.dim = sizey;
Why spline function code use pwch function? The pwch function is use to Hermite interpolant,What is the principle about the matlab cubic spline ?

답변 (1개)

John D'Errico
John D'Errico 2012년 3월 4일
How complicated something may seem when you take it out of context. In fact, it might even seem the code is wrong if this is done. Look more carefully at the code! Don't look at just one line, while forgetting about everything that was done before.
I'll include a couple of comments from earlier in the code, but within this same if-clause.
else % set up the sparse, tridiagonal, linear system b = ?*c for the slopes
...
% sparse linear equation solution for the slopes
...
s=b/c;
...
% construct piecewise cubic Hermite interpolant
% to values and computed slopes
pp = pwch(x,y,s,dx,divdif); pp.dim = sizey;
So when I look at the larger picture, this tool is computing a list of slopes at every break in the curve. The value of that function is completely known of course at those points, since this is an interpolant.
If the value and its derivative of a curve is completely known at EVERY point, is a cubic polynomial segment also completely defined? After all, in each interval between breaks, you will know four pieces of information. How many parameters are there to define a cubic polynomial segment? (Hint: 4)
The point is, at this point in the code, everything about the spline is determined. We know enough about it to compute every segment of the curve. That we use a cubic Hermite to do so does not make that curve only C1. It is still a C2 (twice continuously differentiable) cubic spline. pwch does not care, as the segments are completely defined for its purpose.
Read and understand the entire code. Do not simply look at a single line without also remembering the context under which that line arises. Out of context, it seems not to make sense. In context, it makes perfect sense.
  댓글 수: 2
jing liu
jing liu 2012년 3월 6일
Thank you remind me that very much! But I still do not know why matlab cubic spline function( spline )the boundary conditions is 'not-a-knot' but not natural boundary ? Spline function can use csape function do want he want to do why not use ?
John D'Errico
John D'Errico 2012년 3월 6일
Natural end conditions are only very rarely a good choice. Yes, they make sense if your spline is used to model the shape of a thin flexible beam under a specific set of circumstances (or if it is a homework problem in a book.) However, these are not terribly interesting cases. Otherwise, natural end conditions are simply not a good choice in general.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by