All published worksheets from http://sagenb.org
Image: ubuntu2004
Sage lets us easily use the industry-standard Fortran routines at netlib.org because Sage includes a copy of f2py. I've copied the following code directly from the highly-regarded PPPACK library, written by Carl de Boor for his book A Practical Guide to Splines. This code is in the cubspl.f file.
I've added two things to the code to make it work with Sage. First, I've added a blank line starting with "C" (i.e., a comment line) just under the %fortran. Second, I've added a comment "Cf2py intent(in,out) c" that tells f2py what should be returned when the function ends. Of course, I also put a "%fortran" at the top of the cell to tell Sage that the cell contains fortran code.
After evaluating the above cell, I have access to the cubspl routine. I can ask Sage for help in what the parameters are.
Type: <type 'fortran'>
Definition: cubspl( [noargspec] )
Docstring:
cubspl - Function signature: c = cubspl(tau,c,ibcbeg,ibcend,[n]) Required arguments: tau : input rank-1 array('f') with bounds (n) c : input rank-2 array('f') with bounds (4,n) ibcbeg : input int ibcend : input int Optional arguments: n := len(tau) input int Return objects: c : rank-2 array('f') with bounds (4,n)
In the description of the algorithm, it tells me that tau is the -coordinates and that the first row of is the -coordinates. Additionally, the first and last entries of the second row of are the boundary conditions for the first and last points of the spline, respectively. If ibcbeg is 0, 1, or 2, then the boundary condition on the start of the spline is not-a-knot, the given first derivative, or the given second derivative, respectively. Similar things apply to ibcend for the boundary condition on the ending point of the spline. In the call to cubspl below, the 1 means the first derivative is specified at the beginning, and the 2 means the second derivative is specified at the end.
We construct the polynomials as given in the cubspl description in the fortran code above.
Here is the first spline, which is for the interval .
Here we plot the splines, and plot points for the knots.
Here is a fun little interact that does the same thing above. The points array has the -coordinates on the top and the corresponding -coordinates on the bottom.
|