Professional Documents
Culture Documents
201400384-Assignemnt 2
201400384-Assignemnt 2
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;
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
>>