visualize the golden section search
2 views (last 30 days)
Show older comments
i have tried to visualize the code i did for the golden sectiom search but the figure window pops up with nothing to show. can someone help me out?
%%%Author: Enow Leonard Baiye %%% Golden Search Algorithm clear all clc syms x %%Input fx = (310/5.0862)*((sin((314.1593*0.0025)-0.6658))-(sin(x-0.6658))*(exp((x-(314.1593*0.0025))/(314.1593*0.0025)))); maxit = 50; es = 10^-4; R = (5^.5-1)/2; %%Determine the Interval for the Initial Guess x=[-10:10]; f = subs(fx,x); xlow = 0; xhigh = 1.4217; %%Perform Golden Search xl = xlow; xu = xhigh; iter = 1; d = R*(xu-xl); x1 = xl+d; x2 = xu-d; f1 = subs(fx,x1); f2 = subs(fx,x2); if f1>f2 xopt = x1; else xopt = x2; end % HI-REST FUNCTION xa=xl; xb=xu; xx=linspace(xa,xb); F =subs(fx,xx); while(1) %viturlise plot(xx,F); d = R*d; if f1>f2 xl = x2; x2 = x1; x1 = xl+d; f2 = f1; f1 = subs(fx,x1); else xu = x1; x1 = x2; x2 = xu-d; f1 = f2; f2 = subs(fx,x2); end iter = iter+1; if f1>f2 xopt = x1; else xopt = x2; end if xopt~=0 ea = (1-R)*abs((xu-xl)/xopt)*100; end if ea<=es||iter>=maxit,break end end Gold = xopt
0 Comments
Answers (0)
See Also
Categories
Find more on Windows in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!