Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement this in C++ Part 1 You must first modify the Babylonian square-root estimation algorithm discussed in class. At the moment, the algorithm runs for

Implement this in C++

Part 1 You must first modify the Babylonian square-root estimation algorithm discussed in class. At the moment, the algorithm runs for a finite number of iterations and stops. This means that for a number like, say, 3, where the initial guess starts out close to the actual answer (1.5 vs 1.732. . . ) the accuracy will be extremely good. However, for much larger numbers where this is not the case,the accuracy will become disproportionately poorer. You will need to create a version of the algorithm which takes in two numerical inputs-Sis the number to take the square root of, and the other is an value which determines how accurately you want to approximate S. Instead of running for a finite number of iterations, the algorithmshould run for as long as it takes for the change to the estimate to fall below, and only thenoutput the result. Part 2 This part involves implementing anewsquare-root computation algorithm, sometimes called New-tons Method (based on the Babylonian method). This method finds the reciprocal square root ofS(that is,1S), which can then be used to find the desired S with the multiplication S=S1S(1) procedure Newton(S) guess2/S while condition 3aguess/2 b3Sguess guessab return Sguess This method can also theoretically run forever, continuing to refine its estimate, so you should also modify it to ask the user for avalue and run conditionally on the update step changing guess by more than (that is, stopping when the update step changes guess by less than ).

Part 3 Finally, you may notice that for numbers where the initial guess is sufficiently far away from theactual square root (particularly very small numbers, like 0.01), the algorithm in Part 2 never converges but in fact diverges- the changes in guess get bigger and bigger, and move it farther andfarther away from 1S. Implement logic to detect this (we will say that the algorithm has started to diverge if the difference between guesses increases for two consecutive iterations- in fact thereare cases where the difference will increase and then settle down again, but we dont need to worryabout those right now), stop iterating, and print out an error message.

image text in transcribed

^^ This is the babylonian method

Step 1: Make a guess at Vx (pick Step 2: Compute r= as your initial guess). guess Step 3: Set guess = guess + 2 Step 4: Go back to step 2 for as many iterations as necessary. The more that steps 2 and 3 are repeated, the closer guess will become to the square root of n

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_2

Step: 3

blur-text-image_3

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

A Complete Guide To Data Science Essentials

Authors: Miguel

1st Edition

9358684992, 978-9358684995

More Books

Students also viewed these Databases questions

Question

Explain the causes of indiscipline.

Answered: 1 week ago