/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/ /* [ Created with wxMaxima version 0.8.1 ] */ /* [wxMaxima: title start ] The Babylonian method also known as Herons method for finding square roots [wxMaxima: title end ] */ /* [wxMaxima: comment start ] Reference: J. Ziegenbalg: Algorithmen von Hammurapi bis Gödel, Verlag Harri Deutsch, Frankfurt a.M. 2007, section 3.2.1 [wxMaxima: comment end ] */ /* [wxMaxima: input start ] */ epsilon : 0.000000001 $ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ heron(a) := block([x : a], while abs(a-x*x) > epsilon do x : (x+a/x)/2, x); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ heron(5); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ heron_2(a) := block([x : a], while abs(a-x*x) > epsilon do x : (x+a/x)/2, [x, float(x)] ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ heron_2(5); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ fpprec : 100 $ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ heron_3(a) := block([x : a], while abs(a-x*x) > epsilon do x : (x+a/x)/2 , [x, float(x), bfloat(x)] ); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ heron_3(5); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ set_display(ascii) $ /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ heron_3(5); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ heron_floating_point(a) := block([x : a], while abs(a-x*x) > epsilon do x : 0.5*(x+a/x) , x); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ heron_floating_point(17); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ heron_floating_point_2(a) := block([x : a], while abs(a-x*x) > epsilon do x : 0.5*(x+a/x) , bfloat(x)); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ heron_floating_point_2(17); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ heron_floating_point_3(a) := block([x : a], while abs(a-x*x) > epsilon do x : 0.5*(x+a/x) , [x, float(x), bfloat(x)]); /* [wxMaxima: input end ] */ /* [wxMaxima: input start ] */ heron_floating_point_3(17); /* [wxMaxima: input end ] */ /* Maxima can't load/batch files which end with a comment! */ "Created with wxMaxima"$