Lagrange Interpolation: Difference between revisions

J draft
m (added wp link)
(J draft)
Line 21:
-21 + 215/6*x - 16*x^2 + 13/6*x^3
</pre>
 
=={{header|J}}==
 
From the J wiki [[j:Phrases/Polynomials|polynomial phrases]] page, we have a couple implementations:
 
<syntaxhighlight lang=J>lagrange=: ] +/ .* [ (] % p.~) 1 p.@;~&1\. [
lagrange1=: %.@(^/ i.@#)@[ +/ .* ]</syntaxhighlight>
 
Task example:
<syntaxhighlight lang=J> 1 2 3 4 lagrange 1 4 1 5
_21 215r6 _16 13r6
1 2 3 4 lagrange1 1 4 1 5
_21 35.8333 _16 2.16667</syntaxhighlight>
 
(The J representation of a polynomial is the list of coefficients of the polynomial such that the index of the coefficient is the power applied to the polynomial's variable.)
 
=={{header|Julia}}==
6,962

edits