Advertisement
kaburen

zloty

Apr 3rd, 2019
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.42 KB | None | 0 0
  1. function[wyn] = zl_podzial(g,a,b)
  2. f = @(x)eval(g);
  3. ep = 0.001;
  4. t = 0.618;
  5.  x1 = (b-a)*(-t)+b;
  6.    f1 = f(x1);
  7.    x2 = (b-a)*t+a;
  8.    f2 = f(x2);
  9. while(abs(b-a)>ep)  
  10.    if(f1>f2)
  11.         a = x1;
  12.         x1 = x2;
  13.         f1 = f2;
  14.         x2 = (b-a)*t+a;
  15.         f2 = f(x2);
  16.    else
  17.        b = x2;
  18.        x2 = x1;
  19.        f2 =f1;
  20.        x1 = (b-a)*(-t)+b;
  21.        f1 = f(x1);
  22.    end
  23. end
  24. wyn = round((a+b)/2);
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement