Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear
- clc
- %ANALITYCZNIE
- 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;
- x0 = [3 -1 0 1]';
- eps = 0.0001;
- g = @(x) [2*x(1)+20*x(2)+40*(x(1)-x(4))^3;
- 20*x(1)+200*x(2)+4*(x(2)-2*x(3))^3;
- 10*x(3)-10*x(4)-8*(x(2)-2*x(3))^3;
- 10*x(4)-10*x(3)-40*(x(1)-x(4))^3];
- h = @(x) [120*(x(1)-x(4))^2+2 20 0 -120*(x(1)-x(4))^2;
- 20 12*(x(2)-2*x(3))^2+200 -24*(x(2)-2*x(3))^2 0;
- 0 -24*(x(2)-2*x(3))^2 48*(x(2)-2*x(3))^2+10 -10;
- -120*(x(1)-x(4))^2 0 -10 120*(x(1)-x(4))^2+10];
- for i = 1:100
- x = x0 - (h(x0)^-1)*g(x0);
- if(norm(g(x))<=eps)
- break
- end
- x0 = x;
- end
- x_ana(1,:) = x;
- %CVX
- cvx_begin
- variable x(4)
- 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)
- cvx_end
- x_cvx = x;
- %fminsearch
- x0 = [3 -1 0 1]';
- x_fmin = fminsearch(f,x0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement