kaburen

polowa

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