wiki:cypress/Programming/ApproximatePi/MatlabExample

Version 1 (modified by cmaggio, 7 years ago) (diff)

migrated content from ccs wiki

Ex12sq.m

%
% PI/4=sum(-1)^i/(2i+1)
% ex12eq.m
%
%
clear all;
%
tic;
% number of iterations
n=100000000;
%
x=0.0;
for i = 0:n
    x = x + (-1)^i / (2 * i + 1);
end
str = sprintf('n=%d Pi=%1.16f\n',n,4.0 * x);
disp(str);
toc;