Skip to content

Commit 94240ba

Browse files
aaowenstimholy
authored andcommitted
Update README.md (#157)
Add examples for scale.
1 parent 70e4128 commit 94240ba

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,31 @@ itp = interpolate!(A, BSpline(Quadratic(InPlace())), OnCell())
135135
```
136136
which destroys the input `A` but also does not need to allocate as much memory.
137137

138+
### Scaled BSplines
139+
140+
BSplines assume your data is uniformly spaced on the grid `1:N`, or its multidimensional equivalent. If you have data of the form `[f(x) for x in A]`, you need to tell Interpolations about the grid `A`. If `A` is not uniformly spaced, you must use gridded interpolation described below. However, if `A` is a collection of ranges or linspaces, you can use scaled BSplines. This is more efficient because the gridded algorithm does not exploit the uniform spacing. Scaled BSplines can also be used with any spline degree available for BSplines, while gridded interpolation does not currently support quadratic or cubic splines.
141+
142+
Some examples,
143+
```jl
144+
A_x = 1.:2.:40.
145+
A = [log(x) for x in A_x]
146+
itp = interpolate(A, BSpline(Cubic(Line())), OnGrid())
147+
sitp = scale(itp, A_x)
148+
sitp[3.] # exactly log(3.)
149+
sitp[3.5] # approximately log(3.5)
150+
```
151+
152+
For multidimensional uniformly spaced grids
153+
```jl
154+
A_x1 = 1:.1:10
155+
A_x2 = 1:.5:20
156+
f(x1, x2) = log(x1+x2)
157+
A = [f(x1,x2) for x1 in A_x1, x2 in A_x2]
158+
itp = interpolate(A, BSpline(Cubic(Line())), OnGrid())
159+
sitp = scale(itp, A_x1, A_x2)
160+
sitp[5., 10.] # exactly log(5 + 10)
161+
sitp[5.6, 7.1] # approximately log(5.6 + 7.1)
162+
```
138163
### Gridded interpolation
139164

140165
These use a very similar syntax to BSplines, with the major exception

0 commit comments

Comments
 (0)