czlowiekzgon

matlab3

Mar 30th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. function wynik = minX(y)
  2. %UNTITLED3 Summary of this function goes here
  3. % Detailed explanation goes here
  4. stala = y;
  5. f=@(x) 2.*x.^2+stala.^2+x.*stala-6.*x-5.*stala+8;
  6. %x = -5:0.1:5;
  7. a = -5;
  8. b = 5;
  9. e = 0.000001;
  10. x1=a+0.382*(b-a);
  11. x2=a+0.618*(b-a);
  12. while (b-a)>e
  13. if (f(x1)<f(x2))
  14. b=x2;
  15. else
  16. a=x1;
  17. end
  18. x1=a+0.382*(b-a);
  19. x2=a+0.618*(b-a);
  20. end;
  21. wynik=(a+b)/2;
  22.  
  23. end
Add Comment
Please, Sign In to add comment