steepest descent using armijo rule
68 次查看(过去 30 天)
显示 更早的评论
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
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].')
回答(1 个)
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!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!