The divide and average method an oldtime method for approxim

The \"divide and average\" method, an old-time method for approximating the squareroot of any positive number a, can be formulated as x = (x + a/x)/2 Deconstruct the algorithm outlined in Fig. 4.2. Use Fig. 4.2 to determine the differences in the 2 scripts. Describe the differences in the 2 scripts and what each of the highlighted segments of code do for the function. function [fx, ea, iter] = SquareRoot(a, es, maxit) % Divide and average method for evaluating squareroot s % [fx, ea, iter] = lterMeth(x, es, maxit) % input: % a = value for which squareroot is computed % es = stopping criterion (default = 0.0001) % maxit = maximum iterations (default = 50) % output: % fx = estimated value % ea = approximate relative error (%) % iter = number of iterations % defaults: if nargin

Solution

if a<= 0 , error (\'value must be positive\')

means that square root can be computed only for positive numbers through this code .i.e this code is valid for square root of real positive numbers only.

iter=1; sol=a/2; ea =100 1st iteration relative error 100%

sol =(sol+a/sol)/2 is iterated square root iwith relative eror

if ea<=es! iter>= maxit, break, end is the stopping criteria for the function code. i.e maximum no of iterations is specified if it exceeds it will stop and sol will be final solution and the error should be less than stopping criterion

 The \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site