Question: ( 8 points ) The Babylonian method for approximating S 2 is based on the idea that if we guess a value, say x ,

(8 points) The Babylonian method for approximating S2 is based on the idea that if we guess
a value, say x, and x2>S, then Sx will be an underestimate of S2, and vice versa. Hence the
average of these two numbers provide a better estimate. One can repeat this averaging to get a
close approximation to S2 within some required accuracy. The algorithm is presented below:
x=1
while (|x2-S|>eps)
q,x=12(x+Sx)
end
return x
(1) Write a MATLAB user-defined function (named mysqrt) that takes a single positive
real valued argument, say S, and computes S2 using the Babylonian method described
above. For eps you can use eps(single(1)). Use "help eps" to learn more about this
function.
(2) Write a MATLAB script file that uses a while loop to repeatedly prompt the user to
enter a positive real value number, say S, and
a) if S is negative it outputs "Invalid input!" and asks the user to re-enter the number,
b) if S is positive it outputs:
The square root of S is x.
where x is mysqrit(S)
c) if S is 0 it stops and outputs "Goodbye!".
 (8 points) The Babylonian method for approximating S2 is based on

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!