Question 3: Descent Write a function descent (f: callable, x0: float, stepsize: float) -> float. Starting...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Question 3: Descent Write a function descent (f: callable, x0: float, stepsize: float) -> float. Starting at xe, it examines the value of f at all values spaced apart by stepsize, as long as the values continue to get smaller. It returns the x last value checked before the function started getting larger. Exercise We will see examples using the function bumpy, provided in the start code. It looks like this: 1.0- 0.5 0.0 -0.5 0 1 ter 2 3 h 4 If we start at x = 5, with a stepsize of 1, we see that the function is smaller at 6, and still smaller at 7, but then larger at 8. The smallest value we see occurs at 7, so we can write the test: check. within ("b0", descent (bumpy, 5.0, 1.0), 7.0, 0.0001) check.within ("b1", descent (bumpy, 5.0, 0.42), 7.1, 0.0001) If we start at x = 5, with a stepsize of 0.42, we see that the function is smaller at 5.42, smaller still at 5.84, 6.26, 6.68, and 7.1, but then larger at 7.52. The smallest value we see occurs at 7.1, so we can write the test: Fin 1.0 0.5 0.0 -0.5 1.0 0.5 0.0 -0.5 ·10 6 0 0 7 1 1 8 2 2 3 w₁ 3 5.0 4 5 5.0 6.0 4 5 6 5.84 5.42 6.26 6 7.0 Ⓒ 8.0 7 8 6.68 7.52 7.19 7 8 If we start at x = 2.5, with a stepsize of 0.42, we see that the function is smaller at 2.92, smaller still at 3.34, but then larger at 3.76. The smallest value we see occurs at 3.34, so we can write the test: check.within ("b2", descent (bumpy, 2.5, 0.42), 3.34, 0.0001) If we start at x = 2.5, with a stepsize of 1.0, we see that the function is smaller at 3.5, smaller still at 4.5, but then larger at 5.5. The smallest value we see occurs at 4.5, so we can write the test: check.within ("b2", descent (bumpy, 2.5, 1.00), 4.5, 0.0001) 1.0 0.5- 0.0 -0.5 1.0 0.5 0.0 -0.5 0 1 2 2.5 43.34 2.92 2.5 3.76 3 3,5 4 5 Ⓡ 5.5 7 8 0 1 2 3 4 5 6 7 8 The provided function parabola corresponds to p(x) = (x - 2)², which has a minimum as x = 2. For additional examples: • Starting at x = -1, with a stepsize of 1.0, we see that p(-1) = 9, p(0) = 4, p(1) = 1, p(2) = 0, and finally p(3) = 1. The smallest value we see occurs at 2, so we can write the test: check. within ("P0", descent (parabola, -1.0, 1.0), 2.0, 0.0001) • Starting at x = 0, with a stepsize of 0.7, we see that p(0) = 4, p(0.7) = 1.69, p(1.4) = 0.36, p(2.1) = 0.01, and finally p(2.8) = 0.64. The smallest value we see occurs at 2.1, so we can write the test: check.within("p1", descent (parabola, 0.0, 0.7), 2.1, 0.0001) Do not test your function only with bumpy and parabola. It should work for any appropriate function. Create additional simple mathematical functions to use for tests of descent. (A function such as d(x) = -x will not work, since it keeps getting smaller, forever. Your program could never find a point where this function gets bigger.) Question 3: Descent Write a function descent (f: callable, x0: float, stepsize: float) -> float. Starting at xe, it examines the value of f at all values spaced apart by stepsize, as long as the values continue to get smaller. It returns the x last value checked before the function started getting larger. Exercise We will see examples using the function bumpy, provided in the start code. It looks like this: 1.0- 0.5 0.0 -0.5 0 1 ter 2 3 h 4 If we start at x = 5, with a stepsize of 1, we see that the function is smaller at 6, and still smaller at 7, but then larger at 8. The smallest value we see occurs at 7, so we can write the test: check. within ("b0", descent (bumpy, 5.0, 1.0), 7.0, 0.0001) check.within ("b1", descent (bumpy, 5.0, 0.42), 7.1, 0.0001) If we start at x = 5, with a stepsize of 0.42, we see that the function is smaller at 5.42, smaller still at 5.84, 6.26, 6.68, and 7.1, but then larger at 7.52. The smallest value we see occurs at 7.1, so we can write the test: Fin 1.0 0.5 0.0 -0.5 1.0 0.5 0.0 -0.5 ·10 6 0 0 7 1 1 8 2 2 3 w₁ 3 5.0 4 5 5.0 6.0 4 5 6 5.84 5.42 6.26 6 7.0 Ⓒ 8.0 7 8 6.68 7.52 7.19 7 8 If we start at x = 2.5, with a stepsize of 0.42, we see that the function is smaller at 2.92, smaller still at 3.34, but then larger at 3.76. The smallest value we see occurs at 3.34, so we can write the test: check.within ("b2", descent (bumpy, 2.5, 0.42), 3.34, 0.0001) If we start at x = 2.5, with a stepsize of 1.0, we see that the function is smaller at 3.5, smaller still at 4.5, but then larger at 5.5. The smallest value we see occurs at 4.5, so we can write the test: check.within ("b2", descent (bumpy, 2.5, 1.00), 4.5, 0.0001) 1.0 0.5- 0.0 -0.5 1.0 0.5 0.0 -0.5 0 1 2 2.5 43.34 2.92 2.5 3.76 3 3,5 4 5 Ⓡ 5.5 7 8 0 1 2 3 4 5 6 7 8 The provided function parabola corresponds to p(x) = (x - 2)², which has a minimum as x = 2. For additional examples: • Starting at x = -1, with a stepsize of 1.0, we see that p(-1) = 9, p(0) = 4, p(1) = 1, p(2) = 0, and finally p(3) = 1. The smallest value we see occurs at 2, so we can write the test: check. within ("P0", descent (parabola, -1.0, 1.0), 2.0, 0.0001) • Starting at x = 0, with a stepsize of 0.7, we see that p(0) = 4, p(0.7) = 1.69, p(1.4) = 0.36, p(2.1) = 0.01, and finally p(2.8) = 0.64. The smallest value we see occurs at 2.1, so we can write the test: check.within("p1", descent (parabola, 0.0, 0.7), 2.1, 0.0001) Do not test your function only with bumpy and parabola. It should work for any appropriate function. Create additional simple mathematical functions to use for tests of descent. (A function such as d(x) = -x will not work, since it keeps getting smaller, forever. Your program could never find a point where this function gets bigger.)
Expert Answer:
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
What theory proposes that the relationships of younger adults are knowledge-based, whereas those of late adulthood are more emotions-based. Explain the theory and the reason why?
-
How does marital satisfaction in mid-life compare to marital satisfaction in earlier parts of adulthood in Western countries?
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Quality Air Conditioning manufactures three home air conditioners: an economy model, a standard model, and a deluxe model. The profits per unit are $63, $95, and $135, respectively. The production...
-
Reconsider Prob. 159. Using EES (or other) software, investigate the effect of the manometer fluid density in the range of 800 to 13,000 kg/m3 on the differential fluid height of the manometer. Plot...
-
Rewrite the partial polyurethane structure shown in eq. 14.30, but with one more monomer unit attached to each wavy bond.
-
The wall shear stress in a fully developed flow portion of a 12 -in.-diameter pipe carrying water is \(1.85 \mathrm{lb} / \mathrm{ft}^{2}\). Determine the pressure gradient, \(\partial p / \partial...
-
Dustin Clemens is the accounting and finance manager for a manufacturer. At year-end, he must determine how to account for the companys contingencies. His manager, Madeline Pretti, objects to...
-
1. You have an object and have been told what material it is. You look it up in the density chart and it states that it is 18.6 g/cm 3 . You mass the object and see that it is 37.95 grams. How many...
-
In receiving terminals of petrochemical plants, some of the liquid natural gas (LNG) storage Tanks are designed to be in ground, to avoid receiving radiation from the sun and also being protected...
-
The size of a scope tube has more to do with adjustability than light-allowance. Explain.
-
Describe the impact that diversity awareness has on giving and receiving feedback when communicating and collaborating with others. Describe how you can use strategies for interacting with diverse...
-
Answer each question in at least one paragraph, where each paragraph would have at least more than 10 lines and provide justification to your answers with some references and some articles. Can a...
-
1. Compensation income earners may deduct the following from their gross income to arrive at taxable income: a. Itemized Deductions b. Optional Standard Deductions c. First P250,000 d. None of the...
-
After reading entitled "Listening" (https://2012books.lardbucket.org/books/a-primer-on-communication-studies/s05-listening.html) respond to this discussion topic. Be descriptive in answering two of...
-
Which of the following compounds will test positive with the ammonium ceric nitrate reagent? 5-methylhex-1-ene 2-methyl hexane cyclohexane para methyl phenol pre T 1 Eion 2 N F2 W S 3 Debit: El...
-
Which of the following functions are NOT differentiable: (A) f(x) = |x| (B) f(x) = (x+3) (C) f(x) = 1066 (D) f(x) = mx + b (E) None of the above
-
(a) With not more than 300 words, examine why Malaysia missed its 2020 targets to divert 40% of waste from landfills and increase recycling rates to 22%. (10 marks) b) Why arent Malaysian recycling?...
-
Write a static method remove(int v,int[] in) that will return a new array of the integers in the given array, but with the value v removed. For example, if v is 3 and in contains 0, 1, 3, 2, 3, 0, 3,...
-
Write a new class TruncatedDollarFormat that is the same as the class DollarFormat from Listing 6.14, except that it truncates rather than rounds to obtain two digits after the decimal point. When...
-
Many private water wells produce only 1 or 2 gallons of water per minute. One way to avoid running out of water with these low-yield wells is to use a holding tank. A family of 4 will use about 250...
-
The kinematic viscosity and specific gravity of a liquid are \(3.5 \times 10^{-4} \mathrm{~m}^{2} / \mathrm{s}\) and 0.79, respectively. What is the dynamic viscosity of the liquid in SI units?
-
A liquid has a specific weight of \(59 \mathrm{lb} / \mathrm{ft}^{3}\) and a dynamic viscosity of \(2.75 \mathrm{lb} \cdot \mathrm{s} / \mathrm{ft}^{2}\). Determine its kinematic viscosity.
-
Fluids for which the shearing stress, \(\tau\), is not linearly related to the rate of shearing strain, \(\dot{\gamma}\), are designated as nonNewtonian fluids. Such fluids are commonplace and can...
Study smarter with the SolutionInn App