{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# golden - x2 = xU p1(xU xL fx2 = f(x2 x for k = 1 1000 f...

This preview shows page 1. Sign up to view the full content.

function x = golden (f, xL, xU, Edes, display) % GOLDEN Finds a minimum by performing a golden section search. % Inputs: f = a function of one variable % xL = lower bound of region containing minimum % xU = upper bound of region containing minimum % Edes = function stops when x within Edes of minium % display = display option (0 = no display (default), 1 = display) % Outputs: x - estimate of minimum % if nargin < 5; display = 0; end i p1 = ((1 + sqrt(5)) / 2) - 1; % golden ratio - 1 p if display fprintf ... (' k xL x2 x1 xU Emax\n'); end e % set up for first iteration x1 = xL + p1 * (xU - xL); fx1 = f(x1);
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: x2 = xU - p1 * (xU - xL); fx2 = f(x2); x for k = 1 : 1000 f Emax = (xU - xL) / 2; if display fprintf ('%5d %12.6f %12.6f %12.6f %12.6f %12.6f\n', . .. k, xL, x2, x1, xU, Emax); end if Emax <= Edes x = (xL + xU) / 2; return; end if fx2 < fx1 xU = x1; x1 = x2; fx1 = fx2; % old x2 becomes new x1 x2 = xU - p1 * (xU - xL); fx2 = f(x2); % brand new x2 required else xL = x2; x2 = x1; fx2 = fx1; % old x1 becomes new x2 x1 = xL + p1 * (xU - xL); fx1 = f(x1); % brand new x1 required end end e error ('Golden section search has not converged.'); e end...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern