Example 2. Find the
"clamped cubic spline" that satisfies
Solution 2.
Set up the formulas for the two cubic polynomials and form the equations to solve. Subscripted variables are used if you prefer you can use ordinary variables .
Set up eight equations using the prescribed endpoint conditions. Then find the solution set to this linear system and store it in the variable solset.
Use the solution given above for the coefficients and form the cubic functions. Remember that we must dig out one set of braces using before we can use the ReplaceAll command.
Now graph the portion of each cubic in the interval over which it is to be used. Then combine the two piecewise cubic graphs to form the spline.
Remark. Note that the individual cubics were graphed over different intervals and then the graphs were combined. If they were plotted together over a common interval it would look different.
Remark. It would be
nice to have one piecewise cubic function S[z] that is used.
The following formulas for S[x] uses
the condition syntax for
making a piecewise function. Under the help menu we can
find the following information about Condition.
patt test
is a pattern which matches only if the evaluation of test yields
True
Caution. We cannot print the formula for a piecewise function with the Print command. It is only possible to interrogate the system and determine what rule it is storing for S. Hence, it was a good idea to always use two formulas f1 and f2 to define S, since they can be printed.
Global`S

When a plot is made, it only uses real numbers specified in the conditions.
The clamped cubic spline forces the slope at the endpoints to be prescribed values.
(c) John H. Mathews 2004