Question: Problem 6 : Applying Concepts of Error Analysis to the Babylonian Method / Algorithm One numerical method for calculating the square root of a number

Problem 6: Applying Concepts of Error Analysis to the Babylonian Method/Algorithm
One numerical method for calculating the square root of a number is the Babylonian method. In this method p2 is calculated in iterations. The solution process starts by choosing a value x1 as a first estimate of the solution. Using this value, a second, more accurate solution x2 can be calculated with x2=x1+px12, which is then used for calculating a third, still more accurate solution x3, and so on. The general equation for the algorithm to estimate the solution for the square root of a number is thus xi+1=xi+pxi2.
a) Write a MATLAB user-defined function that calculates the square root of a number using the Babylonian method. Name the function
function [sqr,er]= Babylonian(p, maxitr)
where maxitr is the maximum number of iterations to be performed, er is a vector of percent errors, and sqr is the estimated value of the square root of p. In the program, use x1=p for the first estimate of the solution. Then, by using the general equation in a loop, calculate new, more accurate solutions. Your function should define a vector of the approximate percent errors, er, defined by er rk=100%*|xnow-xoldxnew| for the k-th iteration and plot the error versus the number of iterations. A partially completed code has been provided (remove the "part" from the function handle before running).
b) Use Babylonian to find the square root of 12.34. Use the value of 20 for maxitr. Interpret the output plot. Compare your result with the MATLAB result using sqrt.
c) Modify your Babylonian function so that a while-loop checks both the error tolerance and the maximum number of iterations. Name the function
function [sqr,er]= BabylonianErr(p, maxtol, maxitr )
where the input arguments p is the number whose square root is to be determined, maxtol is the maximum tolerance, and maxitr is the maximum number of iterations allowed. The output arguments sqr is the estimated value of the square root of p, and er is the percent error. In the program, use x1=p for the first estimate of the solution. Then, by using the general equation in a loop, calculate new, more accurate solutions. Terminate the looping if either of the following conditions is met
The relative approximate error is less than or equal to the maximum error tolerance, maxtol
The number of iterations exceeds the maximum number of iterations allowed, maxitr.
d) Use BabylonianEr r to find the square root of 12.34. Use the value maxtol =1e-5 and matr=10.
 Problem 6: Applying Concepts of Error Analysis to the Babylonian Method/Algorithm

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!