steepest descent using armijo rule

조회 수: 26 (최근 30일)
Kendall Donahoe
Kendall Donahoe 2022년 2월 16일
답변: Brahmadev 2024년 2월 8일
I need help using the armijo rule to find the steepest descent.
Here is the proplem I need to solve and the code I have so far. I know how to do it in 1-D but am having trouble translating that to 2-D.
Code a function to perform a generic steepest descent algorithm using the Armijo line-search rule. Your function should take as inputs, the number of iterations, the function to be minimized (fm), another function that returns the gradient of fm, some initial point x0, and the parameters needed for the line search. Turn in all of your code and the first five iterations when the algorithm is applied to minimizing the function
f(x,y)=(x-2y^2)(x-3y^2), starting at the initial point (-1,-1)
Use line-search parameters of s=1, beta=1/2, and sigma=0.1.
f=@(x) (x(1)-2*x(2).^2).*(x(1)-3*x(2).^2)
xk=[-1,-1]';
fg=@(x) [(x(1)-3*x(2).^2)+(x(1)-2*x(2).^2);4*x(2)*(x(1)-3*x(2).^2)+6*x(2)*(x(1)-2*x(2).^2)];
s=1;
beta=0.5;
sigma=0.1;
for j=1:6
xk(j+1)=armijostep(f,fg,-sign(fg(xk(j))),xk(j),s,beta,sigma); %inputs are f, fg, d, xk, s, beta, sigma in that order
end
hold on;
plot(xk,f(xk),'k*-')
xk
hold off;
  댓글 수: 2
Torsten
Torsten 2022년 2월 16일
Use xk{j} instead of xk(j) if xk is n-dimensional (n>1) (already set the inital xk as xk{1} = [-1,-1].')
Kendall Donahoe
Kendall Donahoe 2022년 2월 16일
I just tried that. I don't think it did anything. I'm not sure if I did it right. Before my main issue was getting an error on the number of array elements when trying to enter the gradient.

댓글을 달려면 로그인하십시오.

답변 (1개)

Brahmadev
Brahmadev 2024년 2월 8일
Assuming that 'armijostep' function written by you takes the x and y co-ordinates (2x1 vector) from the current iteration and returns the x and y co-ordinates for the next iteration as a 2x1 vector, we can store pre-allocate 'xk' and modify the code as shown below:
% Defining the function f
f=@(x) (x(1)-2*x(2).^2).*(x(1)-3*x(2).^2);
no_of_iter = 6; % Defining no. of iterations
xk = zeros([2, no_of_iter]); % Pre-allocating for each step
xk(:, 1)=[-1,-1]'; % Initial guess
% Defining the function fg
fg=@(x) [(x(1)-3*x(2).^2)+(x(1)-2*x(2).^2);4*x(2)*(x(1)-3*x(2).^2)+6*x(2)*(x(1)-2*x(2).^2)];
% Defining constants
s=1;
beta=0.5;
sigma=0.1;
% Calculating each new iteration and plotting it
hold on
for j=1:no_of_iter
xk(:, j+1) = armijostep(f, fg, -sign(fg(xk(:, j))), xk(:, j), s, beta, sigma); %inputs are f, fg, d, xk, s, beta, sigma in that order
plot(xk(:, j),f(xk(:, j)),'k*-'); % Plotting each iteration
end
hold off
Hope this helps in resolving your query!

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by