Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %POWELL SA ZLATNIM
- function [ x,fx ] = p( fun,x0,tol )
- %P Summary of this function goes here
- % Detailed explanation goes here
- n = length(x0);
- e = eye(n);
- x = x0; t = x0 + 2*tol;
- while abs(t - x) > tol
- x = t;
- for i = 1 : n
- g = @(k) t + k*e(:,i);
- c = @(j) fun(g(j));
- teta = z(c,-10,10,tol);
- t = t + teta * e(:,i);
- end
- e = [e(:,2:n) t-x];
- g = @(k) t + k*e(:,i);
- c = @(j) fun(g(j));
- teta = z(c,-10,10,tol);
- t = t + teta * e(:,i);
- end
- x = t;
- fx = feval(fun,x);
- %ZLATNI
- function [ x ] = z( fun,a,b,tol )
- %Z Summary of this function goes here
- % Detailed explanation goes here
- c = (3 - sqrt(5) )/ 2;
- x1 = a + c*(b-a);
- x2 = a + b - x1;
- while (b - a) > tol
- if feval(fun,x1) > feval(fun,x2)
- a = x1;
- x1 = x2;
- x2 = a + b - x1;
- else
- b = x2;
- x2 = x1;
- x1 = a + b - x2;
- end
- end
- if feval(fun,x1) < feval(fun,x2)
- x = x1;
- else
- x = x2;
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment