Write a function called newton_ab which takes 6 input parameters a, b, c, x0, max_iter (default...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a function called newton_ab which takes 6 input parameters a, b, c, x0, max_iter (default value 10 ) and epsilon (default value 1e-10) and implements Newton's method with initial guess x and returns an approximation of a solution of the equation f(x) = 0 where f(x) = x³ + ax² + bx + c The value_max_iter is the maximum number of iterations of Newton's method to implement. The value epsilon is the stopping criteria: f(xn) < €. Use may use the function newton defined below. ]: def newton (f, Df, x0,epsilon, max_iter): xn = x0 for n in range(0,max_iter): fxn = f(xn) if abs (fxn) < epsilon: print('Found solution after',n, 'iterations. ') return xn Dfxn = Df(xn) if abs (Dfxn) < 1e-12: print('Zero derivative. No solution found.') return None xn = xn - fxn/Dfxn print('Exceeded maximum iterations. No solution found. ') return None # YOUR CODE HERE "Check function accepts the right number of input parameters. (1 mark)" assert type (newton_ab(2,-1,-1,1)) == float, "Return value should be a float." assert type(newton_ab (2,-1,-1,1,10)) == float, "Return value should be a float." assert type (newton_ab(2,-1,-1,1,10,1e-4)) == float, "Return value should be a float." print("Problem 3 Test 2: Success!") "Check function returns the correct datatype when there is a zero derivative. (1 mark)" assert newton_ab(-2,-1,1,1,25,0.001) == None, "Return value should be None when f'(x) print("Problem 3 Test 3: Success!") = 5x^4 - 4x "Check function returns the correct values. This cell contains hidden tests. (2 marks)" assert abs (newton_ab(2, -1,-1,1) - 0.8421756416969274) < 1e-12 assert abs (newton_ab(5,4,-3,1,10,1e-12) - 0.4691683039523567) < le-12 print("Problem 3 Test 5: Success!") - 1 and x0 = 1." "Check function returns the correct datatype when exceed maximum iterations. (1 mark)" assert newton_ab (2,-1,-1,10, 2, 1e-12) == None, "Return value should be None when maximum iterations is exceeded." print("Problem 3 Test 4: Success!") Write a function called newton_ab which takes 6 input parameters a, b, c, x0, max_iter (default value 10 ) and epsilon (default value 1e-10) and implements Newton's method with initial guess x and returns an approximation of a solution of the equation f(x) = 0 where f(x) = x³ + ax² + bx + c The value_max_iter is the maximum number of iterations of Newton's method to implement. The value epsilon is the stopping criteria: f(xn) < €. Use may use the function newton defined below. ]: def newton (f, Df, x0,epsilon, max_iter): xn = x0 for n in range(0,max_iter): fxn = f(xn) if abs (fxn) < epsilon: print('Found solution after',n, 'iterations. ') return xn Dfxn = Df(xn) if abs (Dfxn) < 1e-12: print('Zero derivative. No solution found.') return None xn = xn - fxn/Dfxn print('Exceeded maximum iterations. No solution found. ') return None # YOUR CODE HERE "Check function accepts the right number of input parameters. (1 mark)" assert type (newton_ab(2,-1,-1,1)) == float, "Return value should be a float." assert type(newton_ab (2,-1,-1,1,10)) == float, "Return value should be a float." assert type (newton_ab(2,-1,-1,1,10,1e-4)) == float, "Return value should be a float." print("Problem 3 Test 2: Success!") "Check function returns the correct datatype when there is a zero derivative. (1 mark)" assert newton_ab(-2,-1,1,1,25,0.001) == None, "Return value should be None when f'(x) print("Problem 3 Test 3: Success!") = 5x^4 - 4x "Check function returns the correct values. This cell contains hidden tests. (2 marks)" assert abs (newton_ab(2, -1,-1,1) - 0.8421756416969274) < 1e-12 assert abs (newton_ab(5,4,-3,1,10,1e-12) - 0.4691683039523567) < le-12 print("Problem 3 Test 5: Success!") - 1 and x0 = 1." "Check function returns the correct datatype when exceed maximum iterations. (1 mark)" assert newton_ab (2,-1,-1,10, 2, 1e-12) == None, "Return value should be None when maximum iterations is exceeded." print("Problem 3 Test 4: Success!")
Expert Answer:
Answer rating: 100% (QA)
Solution for the above question is def newtonaba b x0 maxiter10 eps1e10 fx x5 ax b f lambda x x 5 ax ... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
4. Consider the production function f(K, L) = 4(K0.5 + L0.5)-2, where K, L > 0. Let I be the isoquant containing the point (K, L) = (8,4). Calculate the slope of isoquant I at point (K, ).
-
As part of her role, Jen is responsible for unloading some of the material that is transferred using a spool her team has put together (see the figure below). Each block of material (block A) is 20...
-
1. A project has the following cash flow diagram,calculate: $50 $100 2 $20 20 $120 a) The present worth of the project, giving that MARR-15%. b) The simple payback period( payback with no interest)...
-
A compound with molecular formula C 17 H 36 exhibits a 1 H NMR spectrum with only one signal. How many signals would you expect in the 13C NMR spectrum of this compound?
-
All electron with initial kinetic energy 6.0eV encounters a barrier with height 11.0eV. What is the probability of tunneling if the width of the barrier is? (a) 0.80 nm and (b) 0.40 run?
-
Breast-feeding mothers secrete calcium into their milk. Some of the calcium may come from their bones, so mothers may lose bone mineral. Researchers compared a random sample of 47 breast-feeding...
-
Consider the gasoline mileage performance data in Table B.3. a. Use the all-possible-regressions approach to find an appropriate regression model. b. Use stepwise regression to specify a subset...
-
Soldner Health Care Products Inc. expects to maintain the same inventories at the end of 2010 as at the beginning of the year. The total of all production costs for the year is therefore assumed to...
-
1. What is the difference between instrumental and terminal values? 2. Provide an example of how each of the Rokeach values might be linked with a brand's attributes and its benefits.
-
Presented below are excerpts from Note 1 to Starbucks' September 30, 2012, consolidated financial statements in which Starbucks describes accounting policy for long-lived assets. a. Leasehold...
-
The notion that decision makers simply do not have the ability or resources to process all available information and alternatives to make an optimal decision is known as Question 5 options: A)...
-
Write a memo addressed to Misters Conner and Martin, evaluating the risk of CMC and discussing the pros and cons of debt versus equity financing. Base your analyses on financial ratios calculated...
-
The financial statement that organizes costs by their behaviour instead of their function is the: Multiple choice question. statement of cash flows balance sheet contribution format income statement...
-
A manufacturing company is deciding between 3 different machines to produce parts they need for a final product. The first machine costs $150,000 to install and costs 25 cents per part, the second...
-
The assumption about production setup costs simplifies things by considering it a fixed cost, regardless of the batch size. However, larger batches may require a more complex setup, impacting costs....
-
do we add this Bought packing supplies at a total cost of $46,000 and paid for $25,000 of these supplies. There were$20,000 of these supplies that have not yet been sold or used
-
Explain the working principal of the circuit breaker?
-
Do the three planes x + 2x + x 3 = 4, X X 3 = 1, and x + 3x = 0 have at least one common point of intersection? Explain.
-
For the following exercises, use synthetic division to find the quotient. (x 4 10x 3 + 37x 2 60x + 36) (x 2)
-
For the following exercises, match each function in Figure 19 with the letter corresponding to its graph. g(x) = log 4 (x + 2) B II 54 21 3 i in y ILLE Figure 19
-
For the following exercises, use a calculator to find the length of each side to four decimal places. c = 50, B = 21
-
\(X\) is the number of bits in error in the next four bits transmitted. What is the expected value of the square of the number of bits in error? Now, \(h(X)=X^{2}\). Therefore, \[ \begin{aligned}...
-
In Example 4.1, \(X\) is the current measured in milliamperes. What is the expected value of power when the resistance is 100 ohms?
-
Correlation between height and weight for players on the 2014 Brazil World Cup Team, using data from all 23 players on the roster. State whether the quantity described is a parameter or a statistic...
Study smarter with the SolutionInn App