catalan constant in matlab

Here's a simple implementation of Catalan's constant in MATLAB:

main.m
%% Define the function
function [catalan] = catalan_const()
% Calculate catalan constant
catalan = 0;
for i=0:5000
    catalan = catalan + ((-1)^i)/(2*i+1)^2;
end
catalan = catalan*8/(pi^2);
end
195 chars
10 lines

You can run this function in MATLAB to calculate the value of the Catalan constant.

gistlibby LogSnag