Answered step by step
Verified Expert Solution
Link Copied!

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 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.
image text in transcribed

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

Recommended Textbook for

DB2 9 For Linux UNIX And Windows Advanced Database Administration Certification Certification Study Guide

Authors: Roger E. Sanders, Dwaine R Snow

1st Edition

1583470808, 978-1583470800

More Books

Students also viewed these Databases questions

Question

What is meant by planning or define planning?

Answered: 1 week ago

Question

Define span of management or define span of control ?

Answered: 1 week ago

Question

What is meant by formal organisation ?

Answered: 1 week ago

Question

What is meant by staff authority ?

Answered: 1 week ago