Summation Example
Description
This script shows how a mathematical operation, in this case a summation, can be applied in terms of code. In this instance we've got
, where
is the input parameter.You can see the mathematics at WolframAlpha.
See it in Action
Specify the "N" value:
Code
squareToN.js
function SquareToN(){
// Assuming nValue is a form field containing the "n" value
// Example: <input type="text" id="nValue" value="5" />
var n = document.getElementById( 'nValue' ).value;
var x = 0;
for( i = 0; i <= n; i++ )
x = x + ( i * i );
alert( "Summation of (i^2) from i = 0 to n = " + n + " is " + x );
}

