• API
• FAQ
• Tools
• Archive
daily pastebin goal
3%
SHARE
TWEET

# Untitled

a guest Oct 16th, 2018 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. e = 0.02;
2. delta = 0.001;
3. a = 3;
4. b = 3.5;
5. phi = (sqrt(5) - 1) / 2;
6. phi_prime = (3 - sqrt(5)) / 2;
7. c = a + (b - a) * phi_prime;
8. d = a + (b - a) * phi;
9. v1 = fx(c);
10. v2 = fx(d);
11. calls = 2;
12. while b - a > e
13.     if v1 > v2
14.         a = c;
15.         c = d;
16.         d = a + (b - a) * phi;
17.         v1 = v2;
18.         v2 = fx(d);
19.     else
20.         b = d;
21.         d = c;
22.         c = a + (b - a) * phi_prime;
23.         v2 = v1;
24.         v1 = fx(c);
25.     end
26.     calls = calls + 1;
27. end
28. xMin = (a + b) / 2;
29. vMin = fx(xMin);
30. calls = calls + 1;
31. fprintf('Golden section\nMin at %f\nFunc calls %d\n\n', xMin, calls);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top