MATLAB Answers

Trying to find the minimum of this function using steepest descent, unsure why I keep getting the wrong answer. (1.5,1) should be the optimal

2 views (last 30 days)
Zach Simmons
Zach Simmons on 18 Feb 2020
%Steepest Descent
clc
x0 = [5 2];
k = 0;
while k < 6
f = @(x1,x2) 5.*x1.^2+7.*x2.^2-5.*x1-10.*x1.*x2+x2;
dfdx1 = @(x1,x2) 10.*x1-10.*x2-5;
dfdx2 = @(x1,x2) 14.*x2-10.*x1+1;
x1 = x0(1);
x2 = x0(2);
s1 = -feval(dfdx1,x1,x2)
s2 = -feval(dfdx2,x1,x2)
alpha = (-10.*x1.*s1-14.*s2.*x2-5.*s1-10.*s1.*x2-10.*s2.*x1-s2)/(10.*(s1.^2)+14.*(s2.^2)-20.*s1.*s2)
x0 = [x0 + alpha.*[s1 s2]]
k=k+1;
end

  0 Comments

Sign in to comment.

Answers (0)