Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

bThe Babylonian method for approximating is based on the idea that if we guess a value, say , and 2 > , then will be

bThe Babylonian method for approximating is based on the idea that if we guess a value, say , and 2>, 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=1
while(|2|>)
=1(+)2
end return x
(1) Write a MATLAB user-defined 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 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.The Babylonian method for approximating is based on the idea that if we guess a value, say , and 2>, 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=1
while(|2|>)
=1(+)2
end return x
(1) Write a MATLAB user-defined 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 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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions