資源簡介
梯度下降法matlab程序,需要手動輸入參數梯度下降法matlab程序,需要手動輸入參數

代碼片段和文件信息
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%????????????Developed?by?Bapi?Chatterjee?IIT?Delhi?India???????????????%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%?The?script?steepest.m?optimizes?a?multivariable?function?using?steepest
%?descent?method.
%?Input:
%???????1)Dimensionality?of?the?multivariable?function.
%???????2)Function?in?the?proper?format.
%?????????Note:?Kindly?ensure?that?the?function?is?entered?in?the?proper
%?????????format?readable?by?MATLAB.?This?is?the?only?point?where?the
%?????????maximum?possibility?of?error?is?there.
%???????3)Initial?approximation?vector.
%?????????Note:?Kindly?ensure?that?the?dimensionalty?matches?with?the
%?????????dimension?of?initial?approximation?vector.
%???????4)Error?tolerance.
%
%?For?the?theory?of?steepest?decent?method?see?“Practical?methods?of
%?optimization-?R.?Fletcher?Second?edition?2003?John?Wiley?&?Sons“?or
%?any?other?good?book?on?unconstrained?optimization?methods.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(‘Would?you?like?to?clear?your?workspace?memory?and?command?screen?‘);
z=input(‘To?do?so?enter?1?any?other?number?to?continue:‘);
if?z==1
????clc;clear
end
choice=input(‘To?do?a?maximization?enter?1?for?minimization?enter?2:‘);a=2;
while?a==2
????if?choice~=1&&choice~=2
????????disp(‘Wrong?input!‘);a=2;
????????choice=input(‘To?do?a?maximization?enter?1?for?minimization?enter?2:‘);
????else
????????a=1;
????end
end
a=2;
mark=0;
flag=0;
count=0;
syms?b;
u=[];
warning?off?all
try
????while?a==2
????????n=floor(input(‘Enter?the?dimension?of?function:‘));
????????if?n<1
????????????disp(‘Kindly?enter?a?positive?integer‘);a=2;
????????else
????????????a=1;
????????end
????end
catch
????disp(‘Kindly?enter?a?positive?integer‘);
end
a=2;
for?i=1:n
????syms?([‘x‘?num2str(i)]);
end
while?a==2
????try
????????f=input(‘Enter?the?function?in?terms?of?variables?x_i(i.e.?x1x2etc.):‘);a=1;
????catch
????????disp(‘Kindly?recheck?the?index?of?variables?and?format?of?expression!‘);a=2;
????end
end
if?choice==1
????f=-f;
end
x0=input(‘Enter?the?initial?approximation?row?vector?of?variables:‘);a=2;
while?a==2
????if?length(x0)~=n
????????disp(‘The?dimension?of?initial?approximation?is?incorrect!‘);a=2;
????????x0=input(‘Enter?the?initial?approximation?as?row?vector?of?variables:‘);
????else
????????a=1;
????end
end
try
????eps=abs(input(‘Enter?the?error?tolerance:‘));
catch
????disp(‘Kindly?enter?a?real?number!‘);
end
g=f;
try
????for?i=1:n
????????h(i)=diff(g[‘x‘?num2str(i)]);
????????for?j=1:n
????????????k(ij)=diff(h(i)[‘x‘?num2str(j)]);
????????end
????end
catch
????disp(‘Your?optimization?problem?can?not?be?solved‘);
????return
end
disp(‘Hessian?matrix?of?the?function=‘)
if?choice==1
????disp(-k)
elseif?choice==2
????disp(k)
end
for?i=1:n
????for?j=1:n
????????if?i==j
??????????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????8987??2019-06-04?10:45??steep.m
????I..D...?????????0??2019-06-04?10:50??親測可用
-----------?---------??----------?-----??----
?????????????????8987????????????????????2
評論
共有 條評論