Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [ out ] = goldSplit(f,a,b,E) % Execute using command goldSplit('(x-100)^2' ,10, 150 , 0.001)/ Output 100.0001
- syms x
- f = eval(f);
- T = 0.618;
- x1=(b-a)*(-1 * T) + b;
- x2 = (b-a) * T + a;
- f1 = subs(f,x1);
- f2 = subs(f,x2);
- while abs(b-a) > 2 * E
- if f1 > f2
- a = x1;
- x1 = x2;
- f1 = f2;
- x2 = (b-a) * T + a;
- f2 = subs(f,x2);
- else
- b = x2;
- x2 = x1;
- f2 = f1;
- x1 = (b-a) * (-1*T) + b;
- f1 = subs(f,x1);
- end
- end
- out =(a+b)/2;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement