Steepest Descent Method with Stopping Criteria using MATLAB
16 views (last 30 days)
Show older comments
Sayed Naseem Sadaat
on 2 Apr 2022
Edited: Sayed Naseem Sadaat
on 2 Apr 2022
I have the following quadratic function.
f(x1 ,x2 ) = 5x1^2 + x2^2 + 4x1x2 −14x1 − 6x2 + 20
I want to minimize it starting points X(0) = [x1^0, x2^0] = [0,10] and the stopping criteria (tolerance) = 10^-6 using steepest descent method. I need help.
0 Comments
Accepted Answer
Riccardo Scorretti
on 2 Apr 2022
Edited: Riccardo Scorretti
on 2 Apr 2022
Hi. I don't know it steepest descend is part of any of the Matlab toolbox (anyway, you can find a version here: https://fr.mathworks.com/matlabcentral/fileexchange/22532-steepest-descent-algorithm), but you can use the standard method fminsearch, which in this case works quite well, because the problem is very simple:
% Setup the problem
X0 = [0 10];
fun = @(X) 5*X(:,1).^2 + X(:,2).^2 + 4*X(:,1).*X(:,2) - 14*X(:,1) - 6*X(:,2) + 20;
% Perform the optimization (indeed not by using the steepest descent algorithm)
options = optimset('Display','iter', 'TolX', 1E-6);
[X,FVAL,EXITFLAG] = fminsearch(fun, X0)
Let's check if the result is reasonable:
[x, y] = meshgrid(-2:0.1:3, -2:0.1:3);
f = reshape(fun([x(:) y(:)]), size(x));
figure
mesh(x, y, f) ; hold on ; plot3(X(1), X(2), FVAL, 'r*') ; view(30, 60);
To be 100% sure, let's do some analytical computing:
syms x1 x2
f = 5*x1^2 + x2^2 + 4*x1*x2 - 14*x1 - 6*x2 + 20;
jac = jacobian(f)
det([10 4 ; 4 2])
The jacobian matrix is constant, and it is not singular: hence it exists only one solution:
solve(jac)
0 Comments
More Answers (1)
See Also
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!