Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please solve using MATLAB. Will rate. Prablem S: Apply the Numerical Recipe concept; Understand application of arror analysis to the Babylonian Mcthod/Algorithm One numcrical method
Please solve using MATLAB. Will rate.
Prablem S: Apply the "Numerical Recipe" concept; Understand application of arror analysis to the Babylonian Mcthod/Algorithm One numcrical method for calculating the square root of a number is the Babylonian method. In this method Vp is calculated in iterations. The solution process starts by choosing a value x as a first estimate of the solution. Using this valuc, a sccond, more accurate solution x2 can be calculated with x2 ( p/x)/2, which is then uscd for calculating a third, still more accurate solution x3, and so on. The general cquation for the algorithm to estimate the solution for the square root of a number is thus xm = (xi + P/x)/2. 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) here maxitr is the maximum number of iterations to be performed, er is a vector of relative errors, and sqr is the estimated value of the square root of p. In the program, use x, p for the first estimate of the solution. Then, by using the general cquation in a loop, calculate new, more accurate solutions. Terminate the loop when the number of iterations is greater than the maximum number of iterations maxitr. Also, your function should define for the k-th a yestor of the relative approximate errors er defined by erfor the k-th iteration and plot the relative error versus the number of iterations. imate errors er defined by er b) Use Babylonian to find the square root of 21.43. Use the value of 20 for maxitr Interpret the output plot. Compare your result with the MATLAB result using sqrt c) Write a MATLAB user-defined function that calculates the square root of a number using the Babvlonian method. 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 s the maximum tolerance, and maxi tr is the maximum number of iterations allowedThe output arguments sqr is the estimated value of the square root of p, and er is the relative approximate error when the iteration is terminated. In the program, use xi 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 ertor is less than or equal to the maximum error tolerance, maxtol The number of iterations exceeds the maxmum number of iterations allowed, maxitr -- d) Use BabylonianErr to find the squ are root of 21.43. UUse the value maxtol-ie-5 and maxitr-10
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