GoldenMin - fxaM(iter,:) = fxa fxbM(iter,:) = fxb if Plot

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 function [xopt]=GoldenMin(fhandle, xl,xu,varargin) Plot = 1 gratio = 0.5*(sqrt(5.0)-1) fxl = feval(fhandle,xl,varargin{:}) fxu = feval(fhandle,xu,varargin{:}) % first step, calculate both interior points d = (xu-xl) % define range xa = xu - gratio*d % define point a xb = xl + gratio*d % define point b fxa = feval(fhandle,xa,varargin{:}) % evaluate point a fxb = feval(fhandle,xb,varargin{:}) % evaluate point b F =figure scatter(xa,fxa,'r'),hold on scatter(xb,fxb,'b') xlim([xl,xu]) set(gca,'fontsize',14) xall = xl:.1:xu fxall = feval(fhandle,xall,varargin{:}) plot(xall,fxall) legend('xa','xb','actual') % Loop doing test then evaluating at new point iter=1 % save points to matricx for later plotting xaM(iter,:) = xa xbM(iter,:) = xb
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: fxaM(iter,:) = fxa fxbM(iter,:) = fxb if Plot scatter(xaM(iter,:),fxaM(iter,:),iter*10,'r') scatter(xbM(iter,:),fxbM(iter,:),iter*10,'b') pause end if fxa<fxb % xl,xa,xb,xu % throw out xu xopt = xa fxopt = fxa xu = xb xb=xa d = xu-xl xa = xu - gratio*d % define point a fxb=fxa fxa = feval(fhandle,xa,varargin{:}) % evaluate point a elseif fxb<fxa % xl,xa,xb,xu % throw out xl xopt = xb fxopt = fxb xl = xa xa=xb Sheet1 Page 2 d = xu-xl xb = xl + gratio*d % define point b fxa=fxb fxb = feval(fhandle,xb,varargin{:}) % evaluate point b end iter = iter+1 end scatter(xopt,fxopt,1000,'x','LineWidth',3) title(sprintf('evolution of interior points, iterations reached = %d',iter-1),'fontsize',14)...
View Full Document

This note was uploaded on 09/05/2011 for the course EGM 3344 taught by Professor Raphaelhaftka during the Spring '09 term at University of Florida.

Page1 / 2

GoldenMin - fxaM(iter,:) = fxa fxbM(iter,:) = fxb if Plot

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online