No BSD License  

Highlights from
Steepest Decent Method

from Steepest Decent Method by Duc
Solves a multi-variable unconstrained optimization problem using the Steepest Decent Method

GradientAlgorithm.m
clc;
clear all;
close all;

%perform steepest gradient method
%input initial values
xk1=input('x10= ');
xk2=input('x20= ');
xk=[xk1;xk2];

%the desired magnitude of fianl direction vector
epsilon=0.00001;
%create symbolic function f(x1,x2)
syms x1 x2 alpha1
f='10*(2*x1-5)^2+2*(3*x2-6)^2'

%gradient of fuction f
gradf=[diff(f,x1);diff(f,x2)];

maximumIterationNo=10 
iterationNo=1;

while iterationNo<=maximumIterationNo 
    %gradient of f at [xk1;xk2]
    gradfxk=subs(subs(gradf,x1,xk(1)),x2,xk(2));
    
    if gradfxk==[0;0]
        break;
    end
    
    %create symbolic function phiAlpha
    temp=xk-alpha1*(subs(subs(gradf,x1,xk(1)),x2,xk(2)));
    phiAlpha=subs(subs(f,x1,temp(1)),x2,temp(2));
    %calculate alphavalue
    alphaVal=fminimum(phiAlpha);
    
    %x(k+1)
    xk_1=xk-alphaVal*gradfxk;
    fprintf('x%d= %f %f\n',iterationNo, xk_1(1), xk_1(2));
    
    if (abs(xk_1-xk)<epsilon) 
        break;
    else 
        xk=xk_1;
        iterationNo=iterationNo+1;
    end
end

Contact us at files@mathworks.com