Skip to content

Commit b2bb1e0

Browse files
Added example to readme.md
1 parent 4857d28 commit b2bb1e0

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

README.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,25 @@ Pkg.add("Interpolations")
4343
from the Julia REPL.
4444

4545

46-
47-
46+
## Example Usage
47+
Create a grid `xs` and an array `A` of values to be interpolated
48+
```
49+
xs = 1:0.2:5
50+
f(x) = log(x)
51+
A = [f(x) for x in xs]
52+
```
53+
Create linear interpolation object without extrapolation
54+
```
55+
interp_linear = LinearInterpolation(xs, A)
56+
interp_linear(3) # exactly log(3)
57+
interp_linear(3.1) # approximately log(3.1)
58+
interp_linear(0.9) # outside grid: error
59+
```
60+
Create linear interpolation object with extrapolation
61+
```
62+
interp_linear_extrap = LinearInterpolation(xs, A,extrapolation_bc=Line())
63+
interp_linear_extrap(0.9) # outside grid: linear extrapolation
64+
```
4865

4966
## Performance shootout
5067

0 commit comments

Comments
 (0)