Download as pdf
Download as pdf
You are on page 1of 2
4/24/16 7:25 PM_/Users/ben/Docume.../myModSecOptim2D_bmorris9.m lof 2 function [xVec, fxy,gradF,H, eaVec, numIter]. = myModSecOptim2d_bmorris9(myfunc, x0Vec, es,maxIter) sFunction file: myModSecOpt im2D_username. im % Purpose: % To determine the optimum value of function f(x,y) associated with myfunc % using Modified Secant method % SRecord of revisions (Date | Programmer | Change): % 3/22/16 | Ben Morris | Original program % Slain Variables: SsINPUTS: % myfunc —- function handle for [fxy]=myfune(x,y) % x0Vec = (2x2) initial value of x,y and values of deltax,deltay. % sxOVec(1,1) will be initial value of x sxOVec(1,2) will be deltax sxOVec(2,1) will be initial value of y sxOVec(2,2) will be deltaY % es- % % maxIter - (1x1) maximum number of iterations that can be performed % Ss0UTPUTS: xVec — (2x1) estimate of the optimum fxy ~ (1x1) value of function at xVec gradF - (2x1) gradient of function at xVec H = (2x2) Hessian of function at xVec eaVec - (2x1) approx. percentage relative error at xVec nunIter- (1x1) number of iterations required to obtain xVec were re sbasic checks on inputs assert (Length(x@Vec(1, :))==2 6& Length(xoVec(:,1))==2,... *x0Vec should have initial value of x,y AND deltaX,deltay'); assert ((e5>0)&&(es<100),'es should be between (0,100) '); assert(maxIter=1, ‘maxIter should be >1'); ‘initialize the outputs eaVec=(100; 100] ; numlter=0; myfunc(x,y); (my func (x#dx, y)-my func (x-dx, y))/ (2kdx) 5 (myfunc(x, y+dy)-my func (x, y-dy) )/ (Dkdy) 2x2 = (myfunclx+dx, y)-2my func (x, y)4my func x-dx, y) )/(dx*2) 5 d2fy2_= (myfunc(x, y+dy)-24my func (x, y)4¢myfunc(x, y-dy) )/ (dy2) + d2fxy2 gradF=[dtxsdtyl; = [d2fx2 d2fxy2;d2fxy2 d2fy2]; assert(det(H)~=@, ‘Hessian should have non-zero determiannt to be invertible'); myfunc (x+dx, y+dy)) =myfunc (x+dx, y-dy) ~my Func (x-dx, y+dy) ¢myfunc(x-dx, y-dy) }/ (4skdxedy) 5 4/24/16 7:25 PM_/Users/ben/Docume whi asse (4nd end; ./myModSecOpt.im2D_bmorris9.m ¢ (max(eaVec)>=es) &4(numIter

You might also like