About cubic spline function spline code!
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 ?
0 Kommentare
Antworten (1)
John D'Errico
am 4 Mär. 2012
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 Kommentare
John D'Errico
am 6 Mär. 2012
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.
Siehe auch
Kategorien
Mehr zu Spline Postprocessing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!