Download MuPAD from SciFace

MuPAD Pro Computing Essentials - Examples 

Example 9.4 - To calculate

sqrtNew := proc(n:Type::PosInt, m:Type::PosInt)

 /* This is a procedure to calculate the square root
   of any integer number n, with a given accuracy m.
   Number m must be a whole number. The procedure
   implements the bisection method */
local x, y, accuracy, middle ;
begin
   DIGITS := m+3; //number of digits in calculations
   x := 1;
   y := n; // right point > sqrt(n)
   accuracy := 0.1^m; // define length of interval
   repeat
      middle :=(x+y)/2;
      if middle^2<n then
         x := middle
      else
         y := middle
      end
   until (y-x)<accuracy end;
   return( float(x+y)/2)
end:
 
sqrtNew(2,400)
 
1.4142135623730950488016887242096980785696718753769480
731766797379907324784621070388503875343276415727350138
462309122970249248360558507372126441214970999358314132
226659275055927557999505011527820605714701095599716059
702745345968620147285174186408891986095523292304843087
143214508397626036279952514079896872533965463318088296
406206152583523950547457502877599617298355752203375318
57011354374603408498847132
 
TOP