Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function x = fibonacci_method_optimization(a, b, max_error, my_function)
- max_iter = -2;
- fibonacci_a = 1;
- fibonacci_b = 1;
- condition = (b - a)/max_error;
- while fibonacci_b < condition
- t = fibonacci_b;
- fibonacci_b = fibonacci_b + fibonacci_a;
- fibonacci_a = t;
- max_iter = max_iter + 1;
- end
- if fibonacci_a > condition || fibonacci_b < condition
- x = NaN;
- return;
- end
- for i = 1:max_iter
- x_1 = a + ((fibonacci_b - fibonacci_a)/fibonacci_b)*(b - a);
- x_2 = a + b - x_1;
- 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
- end
- x = (a+b)/2;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement