Matlab Maths
Matlab Maths
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:
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: