Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function x = golden_ratio_method(a, b, max_error, max_iter, my_function)
- c = (3 - sqrt(5))/2;
- for i = 1:max_iter
- x_1 = a + c*(b - a);
- x_2 = b - c*(b - a);
- if feval(my_function, x_1) > feval(my_function, x_2)
- a = x_1;
- elseif feval(my_function, x_2) > feval(my_function, x_1)
- b = x_2;
- else
- % Novi par tacaka ?
- a = x_1;
- b = x_2;
- end
- if abs(b-a) < max_error
- x = (a+b)/2;
- return;
- end
- end
- x = (a+b)/2;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement