Approximating Roots (50 points) In this problem, we will implement a square root approximator and then...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Approximating Roots (50 points) In this problem, we will implement a square root approximator and then an nth root approximator. Recall that the nth root of a non-negative x, written √, is the non-negative number y when raised to the power n gives x. We learned in class that we can use the concept of binary search to approximate the square root of a number, and we can continue this logic to approximate the nth square root. We're going to use the concept 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 tasks, except DecimalFormat. (a) Implement the method squareRootFinder (int number, int iterations). The method should return a string representing an approximation of the square root of the number with 5 decimal places. For example: squareRoot Finder(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 the range that we look at be [0,9]. Its midpoint is 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 range to [0, 4.5]. The middle is now 2.25. (2.25)2 is equal to 5.0625, which is now too low since 1 CSC 3320: Syst x Your answer is X D2L Feedback for X > HW2 (1).pdf × > Lab04.pdf × Homework He X C In this assignm X C Please use Sim × D2L Assignments × + 0 X > File ❘ C:/Users/14049/Downloads/HW2%20(1).pdf ✩ * ☐ H Update M Gmail YouTube = HW2 (1).pdf 1 Maps News 2 Translate Diagnostic Quiz: Ge... Degree evaluation r... Degree evaluation r... D2L y 2 / 2 100% + | Implement.java HW2 (1).pdf PDF HW2.pdf 78°F Sunny Q 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) Implement the method nth RootFinder (int number, int iterations, int n). Now we're approximating the nth root of our number. Recall that the nth root of x, written "√√x, is the number y 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 use the same binary search method as described in part (a) for squareRootFinder, but now you're checking to see if it's the nth root. For example: nth RootFinder (64, 1, 3) is trying to approximate the cubed. root of 64 with only one iteration of binary search. Hint: the code for nth Root Finder looks just like the code for squareRootFinder, but contains a few more lines of code. Remember, you may not use any library functions for these tasks, except DecimalFormat. (c) Call these methods in this order with the following inputs: squareRootFinder (41, 5), nthRootFinder (41, 3, 3). Each individ- ual result must be output and appear in a single line. Example output for the input above: 6.40625 5.12500 Note: Your methods must return correct results even for different inputs. Good luck! lab 2 (1).docx implementation (1).java PDF Lab04 dt.pdf ^ >>> Show all 8:32 PM 9/18/2022 D Approximating Roots (50 points) In this problem, we will implement a square root approximator and then an nth root approximator. Recall that the nth root of a non-negative x, written √, is the non-negative number y when raised to the power n gives x. We learned in class that we can use the concept of binary search to approximate the square root of a number, and we can continue this logic to approximate the nth square root. We're going to use the concept 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 tasks, except DecimalFormat. (a) Implement the method squareRootFinder (int number, int iterations). The method should return a string representing an approximation of the square root of the number with 5 decimal places. For example: squareRoot Finder(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 the range that we look at be [0,9]. Its midpoint is 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 range to [0, 4.5]. The middle is now 2.25. (2.25)2 is equal to 5.0625, which is now too low since 1 CSC 3320: Syst x Your answer is X D2L Feedback for X > HW2 (1).pdf × > Lab04.pdf × Homework He X C In this assignm X C Please use Sim × D2L Assignments × + 0 X > File ❘ C:/Users/14049/Downloads/HW2%20(1).pdf ✩ * ☐ H Update M Gmail YouTube = HW2 (1).pdf 1 Maps News 2 Translate Diagnostic Quiz: Ge... Degree evaluation r... Degree evaluation r... D2L y 2 / 2 100% + | Implement.java HW2 (1).pdf PDF HW2.pdf 78°F Sunny Q 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) Implement the method nth RootFinder (int number, int iterations, int n). Now we're approximating the nth root of our number. Recall that the nth root of x, written "√√x, is the number y 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 use the same binary search method as described in part (a) for squareRootFinder, but now you're checking to see if it's the nth root. For example: nth RootFinder (64, 1, 3) is trying to approximate the cubed. root of 64 with only one iteration of binary search. Hint: the code for nth Root Finder looks just like the code for squareRootFinder, but contains a few more lines of code. Remember, you may not use any library functions for these tasks, except DecimalFormat. (c) Call these methods in this order with the following inputs: squareRootFinder (41, 5), nthRootFinder (41, 3, 3). Each individ- ual result must be output and appear in a single line. Example output for the input above: 6.40625 5.12500 Note: Your methods must return correct results even for different inputs. Good luck! lab 2 (1).docx implementation (1).java PDF Lab04 dt.pdf ^ >>> Show all 8:32 PM 9/18/2022 D
Expert Answer:
Answer rating: 100% (QA)
CODE import javatextDecimalFormat class Main public static double multiplydouble midint n TO mu... View the full answer
Related Book For
Numerical Methods With Chemical Engineering Applications
ISBN: 9781107135116
1st Edition
Authors: Kevin D. Dorfman, Prodromos Daoutidis
Posted Date:
Students also viewed these programming questions
-
re Regular Languages and Finite Automata (a) Let L be the set of all strings over the alphabet {a, b} that end in a and do not contain the substring bb. Describe a deterministic finite automaton...
-
Give examples of three exceptions to the Cardozo rule of foreseeability.
-
Use the Techno Toys Ltd. data in Starter 17-9 to compute the following: a. New borrowing or payment of long-term note payable, with Techno having only one long-term note payable transaction during...
-
Refer to the data in Exercise 3.69. In exercise a. Construct a quantile plot of the number of tuberculosis cases. b. From the quantile plot, determine the 90th percentile for the number of...
-
During the \(0.75 \mathrm{~s}\) that the tube is running, what is the electric power? A. \(7.0 \mathrm{~kW}\) B. \(700 \mathrm{~W}\) C. \(70 \mathrm{~W}\) D. \(7.0 \mathrm{~W}\) \(\mathrm{X}\) rays...
-
Refer to problem 3-37. Prepare a balance sheet as of November 30, 20X0, and an income statement for the month of November. Prepare the retained earnings column of a statement of stockholders' equity....
-
Bean Company has the following selected transactions in January: Jan. 1 Signed a $100,000, six-month, 5% note payable. Interest is payable at maturity. Jan. 15 Sales made totaling $300,000. The...
-
Use the data in COUNTYMURDERS to answer this question. Use only the year 1996. The variable murders is the number of murders reported in the county. The variable execs is the number of executions...
-
Why is the councilor important and how does it differ from the role of an MP?
-
A company has 380,000 shares outstanding that sell for $89.01 per share. The company plans a 4-for-1 stock split. Assuming no market imperfections or tax effects, what will the stock price be after...
-
Quantitative Problem: You are given the following information for Wine and Cork Enterprises (WCE): rRF = 4%; rM = 7%; RPM = 3%, and beta = 1.3 - What is WCE's required rate of return? Do not round...
-
Fresh Air Inc., has a beginning accounts payable balance of $540 in February. Credit purchase for February through May are $300, $330, $410 and $430, respectively. The accounts payable period is 60...
-
For all the hand-waving about a flat world (e.g., Thomas Friedman) how does geography still matter? Consider various aspects of geography, such as distance, culture, law, economic differences: how do...
-
In business, is a party to contract negotiations obligated to provide translation services to other parties?
-
Construct the confidence interval for the population mean u. c= 0.98, x = 16.6, = 3.0, and n= 65 A 98% confidence interval for u is OD (Round to one decimal place as needed.)
-
Accounting policies and practices that are most important to the portrayal of the companys financial condition and results, and require managements most difficult, subjective, or complex judgments...
-
In this problem, we want to figure out how the rate of convergence to the successive over-relaxation (SOR) solution of a linear system of equations depends on the relaxation parameter for w = 0.1,...
-
Classify the two steady states of the dynamic system and make a sketch of the phase plane near the steady states for the system Your phase plane only needs to show the basic idea and you do not need...
-
Consider nonlinear ordinary differential equation subject to initial conditions Convert this problem into a system of autonomous equations and initial conditions. y" + (xy)" + cos(x)y = y
-
What are the three main types of assistance available to the general public for completing their tax forms?
-
Ask older friends or relatives about the cost of specific items (e.g., a gallon of gas, a cup of coffee, etc.) during their youth. Also inquire bout their average wages in the past. Compare the...
-
Develop and solve a future-value, a present-value, a future value of an annuity, and a present value of an annuity problem. Establish the three known variables in each problem and solve for the...
Study smarter with the SolutionInn App