Ticket #13519: 13519-gsl-spline.patch

File 13519-gsl-spline.patch, 4.3 KB (added by Joris Vankerschaver, 10 years ago)
  • sage/gsl/interpolation.pyx

    # HG changeset patch
    # User Joris Vankerschaver <joris.vankerschaver@gmail.com>
    # Date 1348323525 -3600
    # Node ID 5ffd10a2c434b8ed645a2f492daa961178832393
    # Parent  4bf4480e8fd30e0cede481f174fa8630cf558133
    trac 13519: recompute spline when points are changed
    
    diff --git a/sage/gsl/interpolation.pyx b/sage/gsl/interpolation.pyx
    a b  
    88    """
    99    Create a spline interpolation object.
    1010
    11     Given a list v of pairs, s = spline(v) is an object s such that
    12     s(x) is the value of the spline interpolation through the points
    13     in v at the point x.
     11    Given a list `v` of pairs, ``s = spline(v)`` is an object ``s`` such that
     12    `s(x)` is the value of the spline interpolation through the points
     13    in `v` at the point `x`.
    1414
    15     The values in v do not have to be sorted.  Moreover, one can append
    16     values to v, delete values from v, or change values in v, and the
     15    The values in `v` do not have to be sorted.  Moreover, one can append
     16    values to `v`, delete values from `v`, or change values in `v`, and the
    1717    spline is recomputed.
    1818
    19     EXAMPLES:
     19    EXAMPLES::
     20
     21        sage: S = spline([(0, 1), (1, 2), (4, 5), (5, 3)]); S
     22        [(0, 1), (1, 2), (4, 5), (5, 3)]
     23        sage: S(1.5)
     24        2.76136363636...
     25
     26    Changing the points of the spline causes the spline to be recomputed::
     27
     28        sage: S[0] = (0, 2); S
     29        [(0, 2), (1, 2), (4, 5), (5, 3)]
     30        sage: S(1.5)
     31        2.507575757575...
     32
     33    We may delete interpolation points of the spline::
     34
     35        sage: del S[2]; S
     36        [(0, 2), (1, 2), (5, 3)]
     37        sage: S(1.5)
     38        2.04296875
     39
     40    We may append to the list of interpolation points::
     41
     42        sage: S.append((4, 5)); S
     43        [(0, 2), (1, 2), (5, 3), (4, 5)]
     44        sage: S(1.5)
     45        2.507575757575...
     46
     47    If we set the `n`-th interpolation point, where `n` is larger than
     48    ``len(S)``, then points `(0, 0)` will be inserted between the
     49    interpolation points and the point to be added::
     50
     51        sage: S[6] = (6, 3); S
     52        [(0, 2), (1, 2), (5, 3), (4, 5), (0, 0), (0, 0), (6, 3)]
    2053
    2154    This example is in the GSL documentation::
    2255   
     
    4881            sage: S(1.5)
    4982            2.0625
    5083
    51         Replace 0th point, which changes the spline::
     84        Replace `0`-th point, which changes the spline::
    5285       
    5386            sage: S[0]=(0,1); S
    5487            [(0, 1), (2, 3), (4, 5)]
    5588            sage: S(1.5)
    5689            2.5
    5790
    58         If you set the n-th point and n > len(S), then (0,0) points
    59         are inserted and the n-th entry is set (which may be a weird
    60         thing to do, but that is what happens)::
     91        If you set the `n`-th point and `n` is larger than ``len(S)``,
     92        then `(0,0)` points are inserted and the `n`-th entry is set
     93        (which may be a weird thing to do, but that is what happens)::
    6194       
    6295            sage: S[4] = (6,10)
    6396            sage: S
     
    93126            [(1, 1), (2, 3), (4, 5)]
    94127            sage: del S[1]
    95128            sage: S
    96             [(1, 1), (4, 5)]       
     129            [(1, 1), (4, 5)]
     130
     131        The spline is recomputed when points are deleted (:trac:`13519`)::
     132
     133            sage: S = spline([(1,1), (2,3), (4,5), (5, 5)]); S
     134            [(1, 1), (2, 3), (4, 5), (5, 5)]
     135            sage: S(3)
     136            4.375
     137            sage: del S[0]; S
     138            [(2, 3), (4, 5), (5, 5)]
     139            sage: S(3)
     140            4.25
     141
    97142        """
    98143        del self.v[i]
     144        self.stop_interp()
    99145
    100146    def append(self, xy):
    101147        """
     
    103149
    104150            sage: S = spline([(1,1), (2,3), (4,5)]); S.append((5,7)); S
    105151            [(1, 1), (2, 3), (4, 5), (5, 7)]
     152
     153        The spline is recomputed when points are appended (:trac:`13519`)::
     154
     155            sage: S = spline([(1,1), (2,3), (4,5)]); S
     156            [(1, 1), (2, 3), (4, 5)]
     157            sage: S(3)
     158            4.25
     159            sage: S.append((5, 5)); S
     160            [(1, 1), (2, 3), (4, 5), (5, 5)]
     161            sage: S(3)
     162            4.375
     163
    106164        """
    107165        self.v.append(xy)
     166        self.stop_interp()
    108167
    109168    def list(self):
    110169        """
     
    177236
    178237    def __call__(self, double x):
    179238        """
    180         Value of the spline function at x.
     239        Value of the spline function at `x`.
    181240
    182241        EXAMPLES::
    183242