golden - x2 = xU - p1 * (xU - xL); fx2 = f(x2); x for k = 1...

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

View Full Document Right Arrow Icon
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);
Background image of page 1
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

This note was uploaded on 10/18/2010 for the course SYSC 3600 taught by Professor Adsd during the Spring '10 term at Universidad Alfonso X El Sabio.

Ask a homework question - tutors are online