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, 04.07.2019 18:10
Steel is coated with a thin layer of ceramic to protect against corrosion. what do you expect to happen to the coating when the temperature of the steel is increased significantly? explain.
Answers: 1
question
Engineering, 04.07.2019 18:10
Water at 70°f and streams enter the mixing chamber at the same mass flow rate, determine the temperature and the quality of the exiting stream. 0 psia is heated in a chamber by mixing it with saturated water vapor at 20 psia. if both streams enters the mixing chamber at the same mass flow rate, determine the temperature and the quality of the existing system.
Answers: 2
question
Engineering, 04.07.2019 18:10
Afluid flows with a velocity field given by v=(x/t)i.. determine the local and convective accelerations when x=3 and t=1.
Answers: 2
question
Engineering, 04.07.2019 18:20
Ahe-xe mixture containing a 0.75 mole fraction of helium is used for cooling electronics in an avionics application. at a temperature of 300 k and atmospheric pressure, calculate the mass fraction of helium and the mass density, molar concentration and molecular weight of the mixture. if the cooling capacity is 10 l, what is the mass of the coolant?
Answers: 3
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
History, 22.01.2021 21:00
question
Mathematics, 22.01.2021 21:00
question
Mathematics, 22.01.2021 21:00
question
Mathematics, 22.01.2021 21:00
question
Mathematics, 22.01.2021 21:00
Questions on the website: 13722362