Write a function, which finds the element of an array x, which is nearest to a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a function, which finds the element of an array x, which is nearest to a given number a. The function must have a one-dimensional array and a number as inputs. The outputs must include: the value of the element of x closest to a, the index of this element within the array, and the distance between this element and a. Hint: to find the nearest element, compute the absolute value x(i) - al and find for which x(i) it is the smallest. Please run the function for the array x = [0.1, 25, 11.2, -11.1, 8.88, 21,-0.5,-10, 7.1] and the number a 9. Write a function, which finds the element of an array x, which is nearest to a given number a. The function must have a one-dimensional array and a number as inputs. The outputs must include: the value of the element of x closest to a, the index of this element within the array, and the distance between this element and a. Hint: to find the nearest element, compute the absolute value x(i) - al and find for which x(i) it is the smallest. Please run the function for the array x = [0.1, 25, 11.2, -11.1, 8.88, 21,-0.5,-10, 7.1] and the number a 9.
Expert Answer:
Answer rating: 100% (QA)
public class NearestElementFinder public static void mainString args double x 01 25 11... View the full answer
Related Book For
Introduction to Algorithms
ISBN: 978-0262033848
3rd edition
Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest
Posted Date:
Students also viewed these programming questions
-
Find the individual electric fields produced by Q1 and Q2 at charge q. Then find the total electric field at this point. Finally, find the force experienced by charge q. All angles should be measured...
-
The following additional information is available for the Dr. Ivan and Irene Incisor family from Chapters 1-5. Ivan's grandfather died and left a portfolio of municipal bonds. In 2012, they pay Ivan...
-
Extend the model of this chapter by assuming that the firms cost function has the form C(X,E) satisfying assumption 5.1. (a) Derive the second-best optimal combination of an emission standard (no...
-
(a) A 3.00-%F capacitor is connected to a 12.0-V battery. How much energy is stored in the capacitor? (b) If the capacitor had been connected to a 6.00-V battery, how much energy would have been...
-
Two loops of wire are next to one another in the same plane. (a) If the switch S is closed, does current flow in loop 2? If so, in what direction? (b) Does the current in loop 2 flow for only a brief...
-
Complete a simulation of the entire process for the hydrodealkylation of toluene in Figure 6.14. Initially, let the purge/recycle ratio be 0.25 ; then, vary this ratio and determine its effect on the...
-
Whirlpool Corporation conducted an activity-based costing study of its Evansville, Indiana, plant in order to identify its most profitable products. Assume that we select three representative...
-
Explain some of the limitations placed on these rights by citing at least three instances where this has happened. This means finding three cases where the Bill of Rights protections have been...
-
Using a computer spreadsheet, set up a cash flow statement to capture the anticipated cash flow in the following case study scenario. Cash Flow Planning Exercise This exercise is an opportunity to...
-
In a "Short-Paragraph", please respond to the following question,and include a "Source" or "Reference" at the end of your paragraph: Question: Are respect and communication more important than...
-
Goods Market: C = 200 + 0.25(Y-T) I = 150 + 0.25Y - 1000r G = 400 T = 200 Money Market: (M/P) d = 2Y - 8000r M/P = 1600 Solve for Y, r, C and I and then summarize the effects of fiscal policy on...
-
A firm uses job - order costing with departmental overhead rates. Department A: $ 5 0 per direct labor hour Department B: $ 7 2 . 5 0 per machine hour Order #LM 5 0 : This order includes 1 5 0 units,...
-
1. During 2022, Hugh (an employee at General Motors) paid the following taxes. How much of these taxes would be deductible as an itemized deduction? Real estate property tax on Michigan...
-
Consider the block being moved along a frictionless horizontal surface, as depicted in the figure below. The block is pushed from behind by a horizontal force while simultaneously being pulled by a...
-
tommi walker corp's board of directors declared a dividend for all its shareholders there are 8,000 of dividends in arrears for its cumulative preferred shares. there are 1,000 shares of cumulative...
-
Explain why is time frozen from light's perspective? Give detailed answer with examples
-
The Home Depot is the leading retailer in the home improvement industry and one of the 10largest retailers in the United States. The company included the following on its January 29, 2012, balance...
-
Why don't we need to set or reset the prev attributes of objects in the implementation of the ALLOCATE-OBJECT and FREE-OBJECT procedures?
-
How many steps would you expect POLLARD-RHO to require to discover a factor of the form p e , where p is prime and e > 1?
-
Suppose that the vertices for an instance of the traveling-salesman problem are points in the plane and that the cost c (u, ) is the euclidean distance between points u and . Show that an optimal...
-
Would a project with 100 tasks always be more challenging to manage than a differ- ent project with only 20 tasks? Why or why not?
-
Is the critical path the shortest or longest path through a project network?
-
A car rental agency uses 96 boxes of staples a year. The boxes cost \($4\) each. It costs \($10\) to order staples, and it costs \($0.80\) to hold a box of staples in inventory for 1 year. Using the...
Study smarter with the SolutionInn App