You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+68-65Lines changed: 68 additions & 65 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -104,71 +104,7 @@ Finally, courtesy of Julia's indexing rules, you can also use
104
104
fine =itp(range(1,stop=10,length=1001), range(1,stop=15,length=201))
105
105
```
106
106
107
-
### Quickstart guide
108
-
109
-
For linear and cubic spline interpolations, `LinearInterpolation` and `CubicSplineInterpolation` can be used to create interpolation objects handily:
110
-
```julia
111
-
f(x) =log(x)
112
-
xs =1:0.2:5
113
-
A = [f(x) for x in xs]
114
-
115
-
# linear interpolation
116
-
interp_linear =LinearInterpolation(xs, A)
117
-
interp_linear(3) # exactly log(3)
118
-
interp_linear(3.1) # approximately log(3.1)
119
-
120
-
# cubic spline interpolation
121
-
interp_cubic =CubicSplineInterpolation(xs, A)
122
-
interp_cubic(3) # exactly log(3)
123
-
interp_cubic(3.1) # approximately log(3.1)
124
-
```
125
-
which support multidimensional data as well:
126
-
```julia
127
-
f(x,y) =log(x+y)
128
-
xs =1:0.2:5
129
-
ys =2:0.1:5
130
-
A = [f(x,y) for x in xs, y in ys]
131
-
132
-
# linear interpolation
133
-
interp_linear =LinearInterpolation((xs, ys), A)
134
-
interp_linear(3, 2) # exactly log(3 + 2)
135
-
interp_linear(3.1, 2.1) # approximately log(3.1 + 2.1)
136
-
137
-
# cubic spline interpolation
138
-
interp_cubic =CubicSplineInterpolation((xs, ys), A)
139
-
interp_cubic(3, 2) # exactly log(3 + 2)
140
-
interp_cubic(3.1, 2.1) # approximately log(3.1 + 2.1)
141
-
```
142
-
For extrapolation, i.e., when interpolation objects are evaluated in coordinates outside of range provided in constructors, the default option for a boundary condition is `Throw` so that they will return an error.
143
-
Interested users can specify boundary conditions by providing an extra parameter for `extrapolation_bc`:
144
-
```julia
145
-
f(x) =log(x)
146
-
xs =1:0.2:5
147
-
A = [f(x) for x in xs]
148
-
149
-
# extrapolation with linear boundary conditions
150
-
extrap =LinearInterpolation(xs, A, extrapolation_bc =Line())
151
-
152
-
@testextrap(1-0.2) # ≈ f(1) - (f(1.2) - f(1))
153
-
@testextrap(5+0.2) # ≈ f(5) + (f(5) - f(4.8))
154
-
```
155
-
You can also use a "fill" value, which gets returned whenever you ask for out-of-range values:
156
-
157
-
```julia
158
-
extrap =LinearInterpolation(xs, A, extrapolation_bc =NaN)
159
-
@testisnan(extrap(5.2))
160
-
```
161
-
162
-
Irregular grids are supported as well; note that presently only `LinearInterpolation` supports irregular grids.
163
-
```julia
164
-
xs = [x^2for x =1:0.2:5]
165
-
A = [f(x) for x in xs]
166
-
167
-
# linear interpolation
168
-
interp_linear =LinearInterpolation(xs, A)
169
-
interp_linear(1) # exactly log(1)
170
-
interp_linear(1.05) # approximately log(1.05)
171
-
```
107
+
There is also an abbreviated notion [described below](#convenience-notation).
172
108
173
109
## Control of interpolation algorithm
174
110
@@ -323,6 +259,73 @@ etpf = extrapolate(itp, Flat()) # gives 1 on the left edge and 7 on the right
For linear and cubic spline interpolations, `LinearInterpolation` and `CubicSplineInterpolation`
265
+
can be used to create interpolating and extrapolating objects handily:
266
+
```julia
267
+
f(x) =log(x)
268
+
xs =1:0.2:5
269
+
A = [f(x) for x in xs]
270
+
271
+
# linear interpolation
272
+
interp_linear =LinearInterpolation(xs, A)
273
+
interp_linear(3) # exactly log(3)
274
+
interp_linear(3.1) # approximately log(3.1)
275
+
276
+
# cubic spline interpolation
277
+
interp_cubic =CubicSplineInterpolation(xs, A)
278
+
interp_cubic(3) # exactly log(3)
279
+
interp_cubic(3.1) # approximately log(3.1)
280
+
```
281
+
which support multidimensional data as well:
282
+
```julia
283
+
f(x,y) =log(x+y)
284
+
xs =1:0.2:5
285
+
ys =2:0.1:5
286
+
A = [f(x,y) for x in xs, y in ys]
287
+
288
+
# linear interpolation
289
+
interp_linear =LinearInterpolation((xs, ys), A)
290
+
interp_linear(3, 2) # exactly log(3 + 2)
291
+
interp_linear(3.1, 2.1) # approximately log(3.1 + 2.1)
292
+
293
+
# cubic spline interpolation
294
+
interp_cubic =CubicSplineInterpolation((xs, ys), A)
295
+
interp_cubic(3, 2) # exactly log(3 + 2)
296
+
interp_cubic(3.1, 2.1) # approximately log(3.1 + 2.1)
297
+
```
298
+
For extrapolation, i.e., when interpolation objects are evaluated in coordinates outside the range provided in constructors, the default option for a boundary condition is `Throw` so that they will return an error.
299
+
Interested users can specify boundary conditions by providing an extra parameter for `extrapolation_bc`:
300
+
```julia
301
+
f(x) =log(x)
302
+
xs =1:0.2:5
303
+
A = [f(x) for x in xs]
304
+
305
+
# extrapolation with linear boundary conditions
306
+
extrap =LinearInterpolation(xs, A, extrapolation_bc =Line())
307
+
308
+
@testextrap(1-0.2) # ≈ f(1) - (f(1.2) - f(1))
309
+
@testextrap(5+0.2) # ≈ f(5) + (f(5) - f(4.8))
310
+
```
311
+
You can also use a "fill" value, which gets returned whenever you ask for out-of-range values:
312
+
313
+
```julia
314
+
extrap =LinearInterpolation(xs, A, extrapolation_bc =NaN)
315
+
@testisnan(extrap(5.2))
316
+
```
317
+
318
+
Irregular grids are supported as well; note that presently only `LinearInterpolation` supports irregular grids.
319
+
```julia
320
+
xs = [x^2for x =1:0.2:5]
321
+
A = [f(x) for x in xs]
322
+
323
+
# linear interpolation
324
+
interp_linear =LinearInterpolation(xs, A)
325
+
interp_linear(1) # exactly log(1)
326
+
interp_linear(1.05) # approximately log(1.05)
327
+
```
328
+
326
329
## Performance shootout
327
330
328
331
In the `perf` directory, you can find a script that tests
0 commit comments