Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.91 KB | None | 0 0
  1. clear
  2. clc
  3. %ANALITYCZNIE
  4. f = @(x) (x(1)+10*x(2))^2 + 5*(x(3)-x(4))^2 + (x(2)-2*x(3))^4 + 10*(x(1)-x(4))^4;
  5. x0 = [3 -1 0 1]';
  6. eps = 0.0001;
  7.  
  8. g = @(x) [2*x(1)+20*x(2)+40*(x(1)-x(4))^3;
  9.           20*x(1)+200*x(2)+4*(x(2)-2*x(3))^3;
  10.           10*x(3)-10*x(4)-8*(x(2)-2*x(3))^3;
  11.           10*x(4)-10*x(3)-40*(x(1)-x(4))^3];
  12.      
  13. h = @(x) [120*(x(1)-x(4))^2+2 20 0 -120*(x(1)-x(4))^2;
  14.             20 12*(x(2)-2*x(3))^2+200 -24*(x(2)-2*x(3))^2 0;
  15.             0 -24*(x(2)-2*x(3))^2 48*(x(2)-2*x(3))^2+10 -10;
  16.             -120*(x(1)-x(4))^2 0 -10 120*(x(1)-x(4))^2+10];
  17.        
  18.        
  19. for i = 1:100
  20.     x = x0 - (h(x0)^-1)*g(x0);
  21.     if(norm(g(x))<=eps)
  22.         break
  23.     end
  24.     x0 = x;
  25. end
  26. x_ana(1,:) = x;
  27.  
  28. %CVX
  29. cvx_begin
  30. variable x(4)
  31. minimize ((x(1)+10*x(2))^2 + 5*(x(3)-x(4))^2 + (x(2)-2*x(3))^4 + 10*(x(1)-x(4))^4)
  32. cvx_end
  33. x_cvx = x;
  34.  
  35. %fminsearch
  36. x0 = [3 -1 0 1]';
  37. x_fmin = fminsearch(f,x0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement