home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 4.ddi / OPTIM.DI$ / CUBICI3.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  833 b   |  23 lines

  1. function [stepmin,fbest]=cubici3(fnew,fold,graddnew,graddold,stepsize)
  2. %CUBICI3  Cubicly interpolates 2 points and gradients to find step and min.
  3. %
  4. %    This function uses cubic interpolation and the values of 
  5. %    two points and their gradients in order estimate the minimum of a 
  6. %    a function along a line.
  7.  
  8. %    Copyright (c) 1990 by the MathWorks, Inc.
  9. %    Andy Grace 7-9-90.
  10. if fnew==Inf, fnew=1/eps; end
  11. amat=[1/3*stepsize^3 , 0.5*stepsize^2; stepsize^2     stepsize];
  12. bmat=[fnew-graddold*stepsize-fold; graddnew-graddold];
  13. abd=amat\bmat;
  14. root=real(sqrt(abd(2)^2-4*abd(1)*graddold));
  15. x1=(-abd(2)+root)/(2*abd(1));
  16. if 2*abd(1)*x1+abd(2)>0
  17.     stepmin=x1;
  18.    else
  19.     stepmin=(-abd(2)-root)/(2*abd(1));;
  20. end
  21. if stepmin<0,  stepmin=-stepmin; end
  22. fbest=1/3*abd(1)*stepmin^3+0.5*abd(2)*stepmin^2+graddold*stepmin+fold;
  23.