RosettaCodeData/Task/Arithmetic-geometric-mean/MATLAB/arithmetic-geometric-mean.m
Ingy döt Net 776bba907c Sync
2013-10-27 22:24:23 +00:00

9 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