Lagrange Interpolation: Difference between revisions
Content added Content deleted
m (→{{header|Wren}}: Fixed a typo and added a program comment.) |
|||
Line 20: | Line 20: | ||
-21 + 215/6*x - 16*x^2 + 13/6*x^3 |
-21 + 215/6*x - 16*x^2 + 13/6*x^3 |
||
</pre> |
</pre> |
||
=={{header|Julia}}== |
|||
Note the Polynomials module prints polynomials in order from degree 0 to n rather than n to zero degree. |
|||
<syntaxhighlight lang="julia">using Polynomials, SpecialPolynomials |
|||
const pts = [[1, 1], [2, 4], [3, 1], [4, 5]] |
|||
const xs = first.(pts) |
|||
const ys = last.(pts) |
|||
const p = Lagrange(xs, ys) |
|||
@show p Polynomial(p) |
|||
</syntaxhighlight>{{out}} |
|||
<pre> |
|||
p = Lagrange(1⋅ℓ_0(x) + 4⋅ℓ_1(x) + 1⋅ℓ_2(x) + 5⋅ℓ_3(x)) |
|||
Polynomial(p) = Polynomial(-21.0 + 35.83333333333333*x - 16.0*x^2 + 2.1666666666666665*x^3) |
|||
</pre> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |