Compute Pi by Euler Formula
Leonard Euler (1707-1783) derived the following infinite sum expansion:
?2 / 6 = ? 1/j 2 (for j from 1 to ?)
>> pi = sqrt( 6 .* cumsum(1 ./ (1:10) .^ 2));
To define a function, select New/m-file and type definition:
% Return a vector of approximations to pi.
e = sqrt( 6 .* cumsum(1 ./ (1:n) .^ 2));
Select SaveAs and save to a file with the same name as the function.