0% found this document useful (0 votes)
10 views3 pages

Matlab Maths

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

Matlab Maths

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

22EC240 – OPTIMIZATION : MATLAB ASSIGNMENT

1) Problem 1A :
Find the number of experiments to be conducted in the following methods to obtain a value of
Ln/L0 = 0.001 a)Fibonacci method b)Golden section method

Program :
i=1;
t=0.001;
while true
ln_lo=round(1/(fibonacci(i)),4);
if ln_lo==t
disp("Number of iterations =" + " " + i);
break
end
i=i+1;
end

Output:

Problem 1B:

Program:
golden_count = 0;
phi = (1 + sqrt(5)) / 2; % Golden ratio
while true
golden_count = golden_count + 1; Ln_LO_value = 1 /
phi^(golden_count - 1);
if Ln_LO_value < 0.001
break;
end
end
disp("The number of experiments in Golden Section method"); disp(golden_count);

Output:
2) Problem 2A :
Find the value of X in the interval [79,80] which minimizes the function f = x(x -1.5) + 79
to within 0.05 by a)the golden section b) the fibanocci method.
Program:

clc; close all; clear all;


f = @(x) x.*(x - 1.5) + 79; L = 0;
R = 1;
n = 6;
ratio = 0.618;
x2 = L + ratio.*(R-L); x1 = L + R - x2;
fx1 = f(x1); fx2 = f(x2);
if fx1 > fx2
L = x1;
x1 = x2;
x2 = L +R-x1;
elseif fx1 < fx2 R = x2;
x2 = x1;
= L +R-x2;
elseif fx1 == fx2
if min(abs(x1),abs(L)) == abs(L) R = x2;
else
L = x1;
end
end
xopt = (L+R)/2; fopt = f(xopt);
fprintf('Optimum value of x = %f \n', xopt); fprintf('Optimum value of f(x) = %f \n', fopt);

Output:

Problem 2B:
Program:
clc; close all; clear all;
f = @(x) x.*(x - 1.5) + 79; L = 0;
R = 1;
n = 6;
Fib = ones(1,n); for i = 3:n+1
Fib(i) = Fib(i-1) + Fib(i-2);
end
for k = 1:n
ratio = (Fib(n+1-k)./Fib(n+2-k)); x2 = L + ratio.*(R-L);
x1 = L+R-x2;
fx1 = f(x1); fx2 = f(x2); if fx1 < fx2
R = x2;
elseif fx1 > fx2 L = x1;
elseif fx1 == fx2
if min(abs(x1), abs(L)) == abs(L) R = x2;
else
L = x1;
end
end
end
xopt = (L+R)/2; fopt = f(xopt);
fprintf('Optimum value of x = %f \n', xopt); fprintf('Optimum value of f(x) = %f \n', fopt);

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy