Ticket #13519: 13519gslspline.patch
File 13519gslspline.patch, 4.3 KB (added by , 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 8 8 """ 9 9 Create a spline interpolation object. 10 10 11 Given a list v of pairs, s = spline(v) is an object ssuch that12 s(x)is the value of the spline interpolation through the points13 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`. 14 14 15 The values in vdo not have to be sorted. Moreover, one can append16 values to v, delete values from v, or change values in v, and the15 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 17 17 spline is recomputed. 18 18 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)] 20 53 21 54 This example is in the GSL documentation:: 22 55 … … 48 81 sage: S(1.5) 49 82 2.0625 50 83 51 Replace 0th point, which changes the spline::84 Replace `0`th point, which changes the spline:: 52 85 53 86 sage: S[0]=(0,1); S 54 87 [(0, 1), (2, 3), (4, 5)] 55 88 sage: S(1.5) 56 89 2.5 57 90 58 If you set the nth point and n > len(S), then (0,0) points59 are inserted and the nth entry is set (which may be a weird60 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):: 61 94 62 95 sage: S[4] = (6,10) 63 96 sage: S … … 93 126 [(1, 1), (2, 3), (4, 5)] 94 127 sage: del S[1] 95 128 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 97 142 """ 98 143 del self.v[i] 144 self.stop_interp() 99 145 100 146 def append(self, xy): 101 147 """ … … 103 149 104 150 sage: S = spline([(1,1), (2,3), (4,5)]); S.append((5,7)); S 105 151 [(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 106 164 """ 107 165 self.v.append(xy) 166 self.stop_interp() 108 167 109 168 def list(self): 110 169 """ … … 177 236 178 237 def __call__(self, double x): 179 238 """ 180 Value of the spline function at x.239 Value of the spline function at `x`. 181 240 182 241 EXAMPLES:: 183 242