Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 6 : Applying Concepts of Error Analysis to the Babylonian Method / Algorithm One numerical method for calculating the square root of a number
Problem : Applying Concepts of Error Analysis to the Babylonian MethodAlgorithm
One numerical method for calculating the square root of a number is the Babylonian method. In this method is calculated in iterations. The solution process starts by choosing a value as a first estimate of the solution. Using this value, a second, more accurate solution can be calculated with which is then used for calculating a third, still more accurate solution and so on The general equation for the algorithm to estimate the solution for the square root of a number is thus
a Write a MATLAB userdefined function that calculates the square root of a number using the Babylonian method. Name the function
function Babylonian 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 In the program, use 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 for the 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 Use the value of for maxitr. Interpret the output plot. Compare your result with the MATLAB result using sqrt
c Modify your Babylonian function so that a whileloop checks both the error tolerance and the maximum number of iterations. Name the function
function BabylonianErr maxtol, maxitr
where the input arguments 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 and er is the percent error. In the program, use 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 to find the square root of Use the value maxtol and
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started