Advertisement
makispaiktis

Optimization - Minimize function - fminbnd, fminunc

Nov 1st, 2022 (edited)
1,280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. clear all
  2. close all
  3. clc
  4.  
  5. %% fminbnd
  6. display('*************************************');
  7. f1 = @(x) x - log(x) + (1-x)^2 + (2-sqrt(x))^3;
  8. f2 = @(x) sin(x);
  9. lb = 0;
  10. ub = 2*pi;
  11. [x_opt1, f_min1] = fminbnd(f1, lb, ub)
  12. [x_opt2, f_min2] = fminbnd(f2, lb, ub)
  13. display('*************************************');
  14. display(' ');
  15.  
  16.  
  17. %% fminunc
  18. display('*************************************');
  19. fun = @(x)3*x(1)^2 + 2*x(1)*x(2) + x(2)^2 - 4*x(1) + 5*x(2);
  20. x0 = [1,1];
  21. [x,fval] = fminunc(fun,x0)
  22. x0 = [-50,500];
  23. [x,fval] = fminunc(fun,x0)
  24. display('*************************************');
  25. display(' ');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement