Jump to content

Sum of a series: Difference between revisions

→‎{{header|Excel }}: Added an Excel LAMBDA version
m (→‎{{header|Phix}}: added syntax colouring the hard way)
(→‎{{header|Excel }}: Added an Excel LAMBDA version)
Line 809:
 
printf( 1, "%.15f\n", sum( 1, 1000 ) )</lang>
 
=={{header|Excel}}==
===LAMBDA===
 
Binding the names '''sumOfSeries''', and '''inverseSquare''' to the following lambda expressions in the Name Manager of the Excel WorkBook:
 
(See [https://www.microsoft.com/en-us/research/blog/lambda-the-ultimatae-excel-worksheet-function/ LAMBDA: The ultimate Excel worksheet function])
 
Excel automatically lifts a function over a scalar to a function over an array:
 
{{Works with|Office 365 betas 2021}}
<lang lisp>sumOfSeries
=LAMBDA(f,
LAMBDA(n,
SUM(
f(SEQUENCE(n, 1, 1, 1))
)
)
)
 
 
inverseSquare
=LAMBDA(n,
1 / (n ^ 2)
)</lang>
 
{{Out}}
{| class="wikitable"
|-
|||style="text-align:right; font-family:serif; font-style:italic; font-size:120%;"|fx
! colspan="2" style="text-align:left; vertical-align: bottom; font-family:Arial, Helvetica, sans-serif !important;"|=sumOfSeries(inverseSquare)(A2)
|- style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff;"
|
| A
| B
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 1
| style="font-weight:bold" | N terms
| style="font-weight:bold" | Sum of inverse square series
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 2
| style="text-align:right; font-weight:bold" | 1
| style="text-align:right; background-color:#cbcefb" | 1
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 3
| style="text-align:right; font-weight:bold" | 10
| style="text-align:right" | 1.5497677311665408
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 4
| style="text-align:right; font-weight:bold" | 100
| style="text-align:right" | 1.63498390018489
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 5
| style="text-align:right; font-weight:bold" | 1000
| style="text-align:right" | 1.64393456668156
|}
 
=={{header|Ezhil}}==
9,655

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.