Question: Supplied Matlab Program Below: ______________________________ function [xopt,fx,ea,iter]=demo_07_golden(demo_07_fctn,xl,xu,es,maxit) % Golden Section Search method for finding maximum value of a function % Inputs: % demo_07_fctn = function

 Supplied Matlab Program Below: ______________________________ function [xopt,fx,ea,iter]=demo_07_golden(demo_07_fctn,xl,xu,es,maxit) % Golden Section Search

Supplied Matlab Program Below:

______________________________

function [xopt,fx,ea,iter]=demo_07_golden(demo_07_fctn,xl,xu,es,maxit)

% Golden Section Search method for finding maximum value of a function

% Inputs:

% demo_07_fctn = function whose maximum value is sought

% outside function rather than a sub-function

% xl = lower guess

% xu = upper guess

% es = desired relative error (stopping criteria)

% maxit = maximum number of iterations

% Outputs:

% xopt = input to the function that produces the max value

% fx = maximum value of the function

% ea = approximate relative error (%)

% iter = number of iterations

% Define Golden Ratio and inital values of x1 and x2

GR = (1+sqrt(5))/2;

d = (GR-1)*(xu-xl);

x1 = xl + d;

x2 = xu - d;

% Initialize

iter = 0;

ea = 100;

% Loop until error criterion has been met

while ea > es,

fx1 = demo_07_fctn(x1);

fx2 = demo_07_fctn(x2);

if fx1 > fx2; % Case A

xopt = x1;

xl = x2;

x2 = x1;

d = (GR-1)*(xu-xl);

x1 = xl + d;

else % Case B

xopt = x2;

xu = x1;

x1 = x2;

d = (GR-1)*(xu-xl);

x2 = xu - d;

end

iter = iter + 1;

if iter > maxit, error ('Max number of iterations exceeded'), end

%Eps_approximate for Golden Search

ea = (2 - GR)*abs((xu - xl)/xopt) * 100;

end

fx = demo_07_fctn(xopt);

end

QUESTION 1 Use the supplied function demo_07_golden" to solve for the maximum of g= (2c)/(4 + 0.8c + c2 +0.223) The function is found on BlackBoard Learn Write a script which calls demo_07_golden (@myfunction, xl, xu, es, maxit) to find the maximum of the function. Note the use of the '@' to pass the address of the function. Your script calls demo_07_golden, which in turn, calls myfunction. You might try to experiment with xl, xu, and es. Use maxit = 100 %IC 05 Script xu = 1; xl = 3.; es = 0.01; [xopt,fx,ea, iter]=demo_07_golden(@IC05_gfromc, xl,xu, es,maxit) What is the maximum of c? O c = xopt = 1.5125 O c = xopt = 1.5287 O c = xopt = 1.5679 O c= xopt = 1.5975 QUESTION 1 Use the supplied function demo_07_golden" to solve for the maximum of g= (2c)/(4 + 0.8c + c2 +0.223) The function is found on BlackBoard Learn Write a script which calls demo_07_golden (@myfunction, xl, xu, es, maxit) to find the maximum of the function. Note the use of the '@' to pass the address of the function. Your script calls demo_07_golden, which in turn, calls myfunction. You might try to experiment with xl, xu, and es. Use maxit = 100 %IC 05 Script xu = 1; xl = 3.; es = 0.01; [xopt,fx,ea, iter]=demo_07_golden(@IC05_gfromc, xl,xu, es,maxit) What is the maximum of c? O c = xopt = 1.5125 O c = xopt = 1.5287 O c = xopt = 1.5679 O c= xopt = 1.5975

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!