Horner's rule for polynomial evaluation: Difference between revisions
Content added Content deleted
Line 442: | Line 442: | ||
=={{header|Elena}}== |
=={{header|Elena}}== |
||
{{trans|C#}} |
{{trans|C#}} |
||
ELENA |
ELENA 4.x : |
||
<lang elena>import extensions |
<lang elena>import extensions; |
||
import system'routines |
import system'routines; |
||
horner(coefficients,variable) |
horner(coefficients,variable) |
||
{ |
|||
[ |
|||
^ coefficients |
^ coefficients.clone().sequenceReverse().accumulate(new Real(),(accumulator,coefficient => accumulator * variable + coefficient)) |
||
} |
|||
] |
|||
public program |
public program() |
||
{ |
|||
[ |
|||
console |
console.printLine(horner(new real[]{-19.0r, 7.0r, -4.0r, 6.0r}, 3.0r)) |
||
}</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |