Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python -> having trouble with figuring out logistic_2 [109]: def logistic(r, x_i): x_old x_i x new x_old (1 x_old) while(abs(x_new x_old) 10e-9): x_old X_new X_new

image text in transcribedPython -> having trouble with figuring out logistic_2

[109]: def logistic(r, x_i): x_old x_i x new x_old (1 x_old) while(abs(x_new x_old) 10e-9): x_old X_new X_new r x_old (1 x_old) return(x_new) [110]: # Test code: Execute this immediately after executing your solution cell above it. assert allclose(logistic(0.5, 0.4), e) assert allclose(logistic(0.5, 0.6), ) assert allclose(logistic(1.5, 0.3), 1/3) assert allclose(logistic(1.5, 0.7), 1/3) assert allclose(logistic(2.5, 0.3), 0.6) assert allclose(logistic(2.5, 0.7), 0.6) b) Iterating until, with limit Implement a function named logistic_2 that does exactly the same thing as logistic, except that: 1. it takes a third argument, max_iterations, specifying the maximum number of times to apply the old-x -> new-x calculation; and 2. if it reaches the maximium number of iterations before meeting the termination condition, it should print "Iteration limit reached." and then return None instead of a number. Hint: You actually have two ways to approach this: by defining a counter variable and then explicitly incrementing and checking it in your while loop, or by using a for. in range() loop and then using break to stop at the appropriate time. Each has advantages and disadvantages depending on the specific use case, so pick whichever lets you write more compact, cleaner, more expresive (directly obvious/readable) code. On a line below the function definition, add a line that executes logistic_2(0.5, 0.4, 1e3) and verify that the result is within 10-9 of zero. (Make sure that when your function is called, the value for max_iterations can be provided with exponential notation, such as 1e3.) [121]: def logistic_2(r, x_i, max_iterations): if max_iterations 10e-9: print("Iterations limit reached") return None else: return max_iterations logistic_2(0.5,0.4,1e3) Iterations limit reached

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions

Question

What was the role of the team leader? How was he or she selected?

Answered: 1 week ago

Question

What were the issues and solutions proposed by each team?

Answered: 1 week ago

Question

Were all members comfortable brainstorming in front of each other?

Answered: 1 week ago