SHARE
TWEET

Untitled

a guest Mar 26th, 2020 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function [x0, f0]= opt_quad (f, x0, TolX, TolFun, MaxIter)
  2. if length(x0)>2, x012= x0(1:3);
  3. else
  4.     if length(x0)==2,a=x0(1); b=x0(2);
  5.     else a= x0-10; b=x0+10;
  6.     end
  7.     x012=[a(a+b)/2 b];
  8. end
  9. f012 = f(x012);
  10. [x0,f0]=opt_quad(f,x012,f012,TolX,TolFun,MaxIter);
  11.  
  12. function [x0,f0] =opt_quad0(f,x012,f012,TolX,TolFun,k)
  13. x0= x012(1);
  14. x1=x012(2);
  15. x2=x012(3);
  16. f0= f012(1);
  17. f1=f012(2);
  18. f2=f012(3);
  19. nd=[f0-f2 f1-f0 f2-f1][x1x1 x2x2 x0x0]';
  20. x3= nd(1)/2/nd(2);
  21. f3=feval(f,x3);
  22. if k<=0 | abs(x3-x1)<TolX|abs(f3-f1)<TolFun
  23.     x0=x3;
  24.     f0=f3;
  25.     if k== 0 printf('Just the been in given'), end
  26.  
  27. else
  28.     if x3<x1
  29.         if f3<f1, x012=[x0 x3 x1];
  30.             f012=[f0 f3 f1];
  31.         else
  32.             x012=[x3 x1 x2];
  33.             f012=[f3 f1 f2];
  34.         end
  35.     else
  36.         if f3<=f1, x012= [x1 x3 x2];
  37.                 f012=[f1 f3 f2];
  38.         else x012=[x0 x1 x3];
  39.             f012=[f0 f1 f3];
  40.         end
  41.     end
  42.     [x0,f0] = opt_quad0(f,x012,f012,TolX,TolFun,k-1);
  43. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top