0% found this document useful (0 votes)
42 views5 pages

201400384-Assignemnt 2

This document describes an algorithm called GoldenSection1 that uses the golden section search method to find the minimum of a function. It takes in a function handle Func, and initial lower and upper bounds a and b. It iteratively evaluates the function at points based on the golden section ratio, updates the bounds, and converges on the minimum value.

Uploaded by

Georges Khalil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views5 pages

201400384-Assignemnt 2

This document describes an algorithm called GoldenSection1 that uses the golden section search method to find the minimum of a function. It takes in a function handle Func, and initial lower and upper bounds a and b. It iteratively evaluates the function at points based on the golden section ratio, updates the bounds, and converges on the minimum value.

Uploaded by

Georges Khalil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Problem

1:
function [min] = GoldenSection1(Func, a, b)
% Function that finds the minimum using a search method: Golden Section

alpha = 0.618;

mu = a + alpha * (b - a);
lambda = a + (1 - alpha) * (b - a);

fmu = Func(mu);
flambda = Func(lambda);

i = 0;

while abs(b - a) >= 0.00001 && i < 1000

if flambda > fmu


a = lambda;
lambda = mu;
mu = a + alpha*(b - a);
flambda = fmu;
fmu = Func(mu);

else
b = mu;
mu = lambda;
lambda = a + (1 - alpha)*(b - a);
fmu = flambda;
flambda = Func(lambda);

end

i = i + 1;

end

min = (a + b) / 2;

function [ y ] = f( x )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
y=((150+30*12/x+9*144/(x*x))*12*0.012*500+450*x);

end
function [ y ] = f( x )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
y=((150+30*x+9*(x*x))*x*0.012*500+450)*1/x;
end

Problem 3:
function [xopt]=Cyclic(f,xguess)
n=length(xguess);
lastx=xguess;
directions=eye(n);
tol=0.001;
LB = [5,434];
UB = [1000,2000];
s=0;

for i=1:1000
s=lastx;
for j=1:n
dvect=directions(j,:);
a=[max(-10,LB(1)-lastx(1)) max(-10,LB(2)-lastx(2))];
b=[min(10,UB(1)-lastx(1)) min(10,UB(2)-lastx(2))];

lambdaopt=GoldenSection(@(lambda)(feval(f,lastx+dvect*lambda)),a(j),b(j));
lastx=lastx+dvect*lambdaopt;
end
if norm(lastx-s)<tol
break
end
end
xopt=s;
end

>> [xopt]=Cyclic(@f,[100,100])

xopt =

5.0000 434.0000

>>

You might also like