Skip to content

Commit 5930335

Browse files
committed
Update README for interpolate
1 parent 1c76076 commit 5930335

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,46 @@ julia> binomial(10,3)
516516
120
517517
```
518518

519+
## Interpolation
520+
521+
Given a list of (exact) numbers, the `interpolate` function returns a polynomial that generates that list.
522+
Specifically, if `vals` is the list of numbers, then `interpolate(vals)` returns a polynomial `p`
523+
such that `p(0)` is the first element of the list, `p(1)` is the second element, and so forth.
524+
525+
Here is a simple example that illustrates that `p(0)` gives the first element of the list:
526+
```
527+
julia> vals = [1,4,9,16,25];
528+
529+
julia> interpolate(vals)
530+
1 + 2*x + x^2
531+
```
532+
533+
In this next example, we find a polynomial `p` such that `p(n)` is the sum of the first `n` perfect squares.
534+
```
535+
julia> f(n) = sum(k^2 for k=0:n)
536+
f (generic function with 1 method)
537+
538+
julia> vals = [f(n) for n=0:5]
539+
6-element Vector{Int64}:
540+
0
541+
1
542+
5
543+
14
544+
30
545+
55
546+
547+
julia> p = interpolate(vals)
548+
1//6*x + 1//2*x^2 + 1//3*x^3
549+
550+
julia> p(10)
551+
385//1
552+
553+
julia> f(10)
554+
385
555+
```
556+
557+
558+
519559
## Conversion between `SimplePolynomial` and `Polynomial`
520560

521561
The `Polynomials` module also defines polynomials with many additional

0 commit comments

Comments
 (0)