RosettaCodeData/Task/Arithmetic-geometric-mean/MATLAB/arithmetic-geometric-mean.m

10 lines
152 B
Matlab

function [a,g]=agm(a,g)
%%arithmetic_geometric_mean(a,g)
while (1)
a0=a;
a=(a0+g)/2;
g=sqrt(a0*g);
if (abs(a0-a) < a*eps) break; end;
end;
end