Here is my riddle of the day for you. Explain why the following piece of Matlab code returns the following
>>blog1(10,3)
x=5.477226, y=5.477226
sqrt(x0y0)=5.477226
Here is the piece of code:
%lasting gemsfunction
function blog1(x0,y0)
x=x0;
y=y0;
for i = 1 : 100000
tmp=x;
x = (x+y)/2;
y = 2*tmp*y/(tmp+y);
endfprintf(‘x=%f, y=%f\n’,x,y);
fprintf(‘sqrt(x0y0)=%f\n’,sqrt(x0*y0));
Also, generalize the above example and realize that the above gives you a numerical procedure to find the geometric mean of two numbers.