0% found this document useful (0 votes)
15 views2 pages

MD23D006 Golden Section Q3

Uploaded by

Lakshmi Sampath
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)
15 views2 pages

MD23D006 Golden Section Q3

Uploaded by

Lakshmi Sampath
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/ 2

% Define the function

f = @(x) 3.^x - 3*x.^2 - 10*x;

% Define the range


a = 1;
b = 5;

% Golden Section Method


phi = (1 + sqrt(5)) / 2; % Golden ratio
tol = 1e-6; % Tolerance for convergence

% First iteration
x1 = b - (b - a) / phi;
x2 = a + (b - a) / phi;
f1 = f(x1);
f2 = f(x2);

while (b - a) > tol


if f1 < f2
b = x2;
x2 = x1;
f2 = f1;
x1 = b - (b - a) / phi;
f1 = f(x1);
else
a = x1;
x1 = x2;
f1 = f2;
x2 = a + (b - a) / phi;
f2 = f(x2);
end
end

% Quadratic Fit Iteration


% Construct a quadratic function around the minimum found
X = [a, (a + b) / 2, b];
Y = f(X);
A = [ones(3, 1), X', X'.^2];
coeff = A\Y';

% Find the minimum of the quadratic function


x_min_quad = -coeff(2) / (2 * coeff(3));

% Output the result


fprintf('Minimum found using Golden Section Method: %f\n', (a + b) / 2);

Minimum found using Golden Section Method: 2.934663

fprintf('Minimum found using Quadratic Fit Iteration: %f\n', x_min_quad);

Minimum found using Quadratic Fit Iteration: 2.934663

% Plot the function and the minima


x = linspace(1, 5, 100);

1
y = f(x);

figure;
plot(x, y);
hold on;
plot((a + b) / 2, f((a + b) / 2), 'ro', 'MarkerSize', 10); % Golden
section method minimum
plot(x_min_quad, f(x_min_quad), 'gx', 'MarkerSize', 10); % Quadratic fit
iteration minimum
xlabel('x');
ylabel('f(x)');
legend('f(x)', 'Golden Section Method Minimum', 'Quadratic Fit Iteration
Minimum');
title('Plot of the function');
grid on;

% Check with fminbnd


x_min_fminbnd = fminbnd(f, 1, 5);
fprintf('Minimum found using fminbnd(): %f\n', x_min_fminbnd);

Minimum found using fminbnd(): 2.934665

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