Question: The Babylonian method for approximating is based on the idea that if we guess a value, say , and 2 > , then will be
The Babylonian method for approximating is based on the idea that if we guess a value, say and then will be an underestimate of 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 within some required accuracy. The algorithm is presented below:
x
while
end return x
Write a MATLAB userdefined function named mysqrt that takes a single positive
real valued argument, say S and computes using the Babylonian method described above. For you can use epssingle Use help eps to learn more about this function.
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 reenter the number,
b if S is positive it outputs:
The square root of S is x
where x is mysqrtS
c if S is it stops and outputs Goodbye
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
