Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python 3 Search Question Golden Section Search 5 points Complete the code doing Golden Section Search for function minimization below. Stop the iteration when your

Python 3 Search Question

image text in transcribed

Golden Section Search 5 points Complete the code doing Golden Section Search for function minimization below. Stop the iteration when your brackets are less than 10 wide. The supplied plotting code shows the evolution of your brackets. Observe how one of the bracket midpoints stays the same from one iteration to the next. INPUT . a function to minimize. Note: f is not unimodal. and b, the left and right ends of the starting bracket. OUTPUT . a, b,the final ends of your bracket. Problem set-up code (cick to view) This is the code that is used to set up the problem and produce test data for your submission. It is reproduced here for your information, or if you would like to run your submission outside of. You should not copy/paste this code into the code box below. This code is run automatically'behind the scenes before your submitted code import numpy as np import scipy.optimize as opt a - a start 1e def f(x): return x*"2+ 18 np.sin(x) def not_allowed ( args, *kwargs): raise RuntimeError( "Calling this function is not allowed") opt.golden not_allowed opt.minimize not_allowed opt.minimize_scalar not_allowed Starter code (dick to view) mport numpy as np import matplotlib.pyplot as plt brackets [] while False: # replace this with the proper condition gs -(np.sqrt(5) - 1) / 2 m2-a gs(b a) n1=a+(1-gs) * (b-a) brackets.append (a, ml, m2, b]) Replace this with the proper bracket update pass Plotting code below, no need to modify xnp.1inspace(-18, 18) plt.plot(x, f(x)) brackets np.array (brackets) for i in range(4) plt.plot (brackets[:, i], 3*np.arange(len(brackets)), o-') Golden Section Search 5 points Complete the code doing Golden Section Search for function minimization below. Stop the iteration when your brackets are less than 10 wide. The supplied plotting code shows the evolution of your brackets. Observe how one of the bracket midpoints stays the same from one iteration to the next. INPUT . a function to minimize. Note: f is not unimodal. and b, the left and right ends of the starting bracket. OUTPUT . a, b,the final ends of your bracket. Problem set-up code (cick to view) This is the code that is used to set up the problem and produce test data for your submission. It is reproduced here for your information, or if you would like to run your submission outside of. You should not copy/paste this code into the code box below. This code is run automatically'behind the scenes before your submitted code import numpy as np import scipy.optimize as opt a - a start 1e def f(x): return x*"2+ 18 np.sin(x) def not_allowed ( args, *kwargs): raise RuntimeError( "Calling this function is not allowed") opt.golden not_allowed opt.minimize not_allowed opt.minimize_scalar not_allowed Starter code (dick to view) mport numpy as np import matplotlib.pyplot as plt brackets [] while False: # replace this with the proper condition gs -(np.sqrt(5) - 1) / 2 m2-a gs(b a) n1=a+(1-gs) * (b-a) brackets.append (a, ml, m2, b]) Replace this with the proper bracket update pass Plotting code below, no need to modify xnp.1inspace(-18, 18) plt.plot(x, f(x)) brackets np.array (brackets) for i in range(4) plt.plot (brackets[:, i], 3*np.arange(len(brackets)), o-')

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

Discuss the evolution of nursing.

Answered: 1 week ago