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
+74-73Lines changed: 74 additions & 73 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,24 +58,22 @@ v = itp(x, y, ...)
58
58
Some interpolation objects support computation of the gradient, which
59
59
can be obtained as
60
60
```julia
61
-
g =gradient(itp, x, y, ...)
61
+
g =Interpolations.gradient(itp, x, y, ...)
62
62
```
63
-
or, if you're evaluating the gradient repeatedly, a somewhat more
64
-
efficient option is
63
+
or as
65
64
```julia
66
-
gradient!(g, itp, x, y, ...)
65
+
Interpolations.gradient!(g, itp, x, y, ...)
67
66
```
68
67
where `g` is a pre-allocated vector.
69
68
70
69
Some interpolation objects support computation of the hessian, which
71
70
can be obtained as
72
71
```julia
73
-
h =hessian(itp, x, y, ...)
72
+
h =Interpolations.hessian(itp, x, y, ...)
74
73
```
75
-
or, if you're evaluating the hessian repeatedly, a somewhat more
76
-
efficient option is
74
+
or
77
75
```julia
78
-
hessian!(h, itp, x, y, ...)
76
+
Interpolations.hessian!(h, itp, x, y, ...)
79
77
```
80
78
where `h` is a pre-allocated matrix.
81
79
@@ -104,71 +102,7 @@ Finally, courtesy of Julia's indexing rules, you can also use
104
102
fine =itp(range(1,stop=10,length=1001), range(1,stop=15,length=201))
105
103
```
106
104
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
-
```
105
+
There is also an abbreviated notion [described below](#convenience-notation).
172
106
173
107
## Control of interpolation algorithm
174
108
@@ -323,6 +257,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`
263
+
can be used to create interpolating and extrapolating objects handily:
264
+
```julia
265
+
f(x) =log(x)
266
+
xs =1:0.2:5
267
+
A = [f(x) for x in xs]
268
+
269
+
# linear interpolation
270
+
interp_linear =LinearInterpolation(xs, A)
271
+
interp_linear(3) # exactly log(3)
272
+
interp_linear(3.1) # approximately log(3.1)
273
+
274
+
# cubic spline interpolation
275
+
interp_cubic =CubicSplineInterpolation(xs, A)
276
+
interp_cubic(3) # exactly log(3)
277
+
interp_cubic(3.1) # approximately log(3.1)
278
+
```
279
+
which support multidimensional data as well:
280
+
```julia
281
+
f(x,y) =log(x+y)
282
+
xs =1:0.2:5
283
+
ys =2:0.1:5
284
+
A = [f(x,y) for x in xs, y in ys]
285
+
286
+
# linear interpolation
287
+
interp_linear =LinearInterpolation((xs, ys), A)
288
+
interp_linear(3, 2) # exactly log(3 + 2)
289
+
interp_linear(3.1, 2.1) # approximately log(3.1 + 2.1)
290
+
291
+
# cubic spline interpolation
292
+
interp_cubic =CubicSplineInterpolation((xs, ys), A)
293
+
interp_cubic(3, 2) # exactly log(3 + 2)
294
+
interp_cubic(3.1, 2.1) # approximately log(3.1 + 2.1)
295
+
```
296
+
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.
297
+
Interested users can specify boundary conditions by providing an extra parameter for `extrapolation_bc`:
298
+
```julia
299
+
f(x) =log(x)
300
+
xs =1:0.2:5
301
+
A = [f(x) for x in xs]
302
+
303
+
# extrapolation with linear boundary conditions
304
+
extrap =LinearInterpolation(xs, A, extrapolation_bc =Line())
305
+
306
+
@testextrap(1-0.2) # ≈ f(1) - (f(1.2) - f(1))
307
+
@testextrap(5+0.2) # ≈ f(5) + (f(5) - f(4.8))
308
+
```
309
+
You can also use a "fill" value, which gets returned whenever you ask for out-of-range values:
310
+
311
+
```julia
312
+
extrap =LinearInterpolation(xs, A, extrapolation_bc =NaN)
313
+
@testisnan(extrap(5.2))
314
+
```
315
+
316
+
Irregular grids are supported as well; note that presently only `LinearInterpolation` supports irregular grids.
317
+
```julia
318
+
xs = [x^2for x =1:0.2:5]
319
+
A = [f(x) for x in xs]
320
+
321
+
# linear interpolation
322
+
interp_linear =LinearInterpolation(xs, A)
323
+
interp_linear(1) # exactly log(1)
324
+
interp_linear(1.05) # approximately log(1.05)
325
+
```
326
+
326
327
## Performance shootout
327
328
328
329
In the `perf` directory, you can find a script that tests
0 commit comments