subject
Engineering, 22.02.2020 05:18 abalth8463

In this problem, we will implement a square root approxi- mater and then an nth root approximater. Recall that the nth root of x, written n√x, is the number when raised to the power n gives x. We learned in class that we can use the concepts of binary search to approx- imate the square root of a number, and we can continue this logic to approximate the nth square root. Please look at Lecture Notes 03, section 4 for a little more detail. We’re going to use the concepts of binary search to try and approximate finding the square root and finding the nth root. You may not use any library functions for these question, except DecimalFormat.

(a) Please fill in the squareRootFinder(int number, int iterations) method. The method should return a string representing an approx- imation of the square root of the number to 5 decimal places.

For example:
squareRootFinder(9, 2) means that we want to approximate the square root of 9 with two iterations of binary search. We know that the square root of 9 must be between 0 and 9. Thus, let’s let the ranges that we look at be (0,9). We see the middle of that to be 4.5. (4.5)2 is equal to 20.25. 20.25 is too high because it’s greater than 9. Thus, we now set our ranges we’re looking at to be (0, 4.5). The middle is now 2.25. (2.25)2 is equal to 5.0625, which is now too low since it’s less than 9. We did 2 iterations. Thus, our best guess for the square root is 2.25000 (remember, 5 decimal point accuracy). If we were doing 3 iterations, we’d now set our new range to (2.25, 4.5).

(b) Please fill in the nthRootFinder(int number, int iterations, int n). Now we’re approximating the nth root of our number. Recall that the nth root of x, written n√x, is the number when raised to the power n gives x. For example, the cubed root of 64 is 3√64 which is equal to 4, since 43 = 64. You’ll do the same binary search method as described in part (a) for squareRootFinder, but now you’re check- ing to see if it’s the nth root.

For example: nthRootFinder(64, 1, 3) is trying to approximate the cubed root of 64 with only one iteration of binary search. Hint: the code for nthRootFinder looks just like the code for squareRootFinder except maybe 3 more lines of code. Remember, you may not use any library functions for these questions, except DecimalFormat.

ansver
Answers: 1

Another question on Engineering

question
Engineering, 03.07.2019 23:20
Two technicians are discussing the intake air temperature (iat) sensor. technician a says that the computer uses the iat sensor as a backup to the engine coolant temperature (ect) sensor. technician b says that the powertrain control module (pcm) will subtract the calculated amount of fuel if the air measures hot. who is correct
Answers: 3
question
Engineering, 04.07.2019 18:10
The higher the astm grain-size number, the coarser the grain is. a)-true b)-false
Answers: 3
question
Engineering, 04.07.2019 18:10
You are making beer. the first step is filling the glass carboy with the liquid wort. the internal diameter of the carboy is 15 in., and you wish to fill it up to a depth of 2 ft. if your wort is drawn from the kettle using a siphon process that flows at 3 gpm, how long will it take to fill?
Answers: 1
question
Engineering, 04.07.2019 18:10
A-mn has a cubic structure with a0 0.8931 nm and a density of 7.47 g/cm3. b-mn has a different cubic structure, with a0 0.6326 nm and a density of 7.26 g/cm3. the atomic weight of manganese is 54.938 g/mol and the atomic radius is 0.112 nm. determine the percent volume change that would occur if a-mn transforms to b-mn.
Answers: 2
You know the right answer?
In this problem, we will implement a square root approxi- mater and then an nth root approximater. R...
Questions
question
Mathematics, 15.09.2020 01:01
question
Social Studies, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
English, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Social Studies, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
English, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
Mathematics, 15.09.2020 01:01
question
History, 15.09.2020 01:01