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

  1. function [maximum,err]=cubic(pts,checkpt,location)
  2. %CUBIC    Cubicly interpolates four points to find the maximum value.
  3. %        The second argument is for estimation of the error in the 
  4. %        interpolated maximum. 
  5. d=pts(1);
  6. abc=[0.5 -0.5 1/6 ; -2.5 2 -0.5; 3 -1.5 1/3]*[pts(2:4)-d*ones(3,1)];
  7. root=real(sqrt(4*(abc(2)^2)-12*abc(1)*abc(3)));
  8. x1=(-2*abc(2)+root)/(6*abc(1));
  9. if 6*abc(1)*x1+2*abc(2)<0
  10.     stepmin=x1; 
  11.    else
  12.     stepmin=(-2*abc(2)-root)/(6*abc(1));
  13. end
  14. maximum=abc(1)*stepmin^3+abc(2)*stepmin^2+abc(3)*stepmin+d;
  15. if nargin>1
  16.     if location==0
  17.         checkpt2=-abc(1)+abc(2)-abc(3)+d;
  18.     else
  19.         checkpt2=64*abc(1)+16*abc(2)+4*abc(3)+d;
  20.     end
  21.     err=abs(checkpt-checkpt2);
  22. end
  23.