visualize the golden section search

1 回表示 (過去 30 日間)
Enow Leonard
Enow Leonard 2018 年 10 月 31 日
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 件)

カテゴリ

Help Center および File ExchangeWindows についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by