最速下降梯度法matlab程序
% Steepest Descent Method% By Kshitij Deshpande
clc
clear all
warning off
prompt = {'Coeficients if X1=','Coefficients of X2=','Coefficeint of X1X2=','Initial Point='};
def = {'','','2',''};
a=inputdlg(prompt,'Data',1,def);
a=char(a);
=size(a);
x1 = eval(a(1,1:n));x2=eval(a(2,1:n));x1x2=eval(a(3,1:n));X1=eval(a(4,1:n));
delf1(1) = polyval(polyder(x1),X1(1));
delf1(1) = (delf1(1))+(x1x2*X1(2));
delf1(2) = polyval(polyder(x2),X1(1));
delf1(2) = (delf1(2))+(x1x2*X1(1));
s=-delf1;
%%%%%%%%%%
%report
srep(1,1:2)=s;
%%%%%%%%%%
x1new(1)=s(1)^2;x1new(2)=2*X1(1)*s(1);x1new(3) = X1(1)^2;
x1new=x1new*x1(1);
x1new_(2)=x1(2)*s(1);x1new_(3)=x1(2)*X1(1);
x1new = x1new+x1new_;
x2new(1)=s(2)^2;x2new(2)=2*X1(2)*s(2);x2new(3) = X1(2)^2;
x2new=x2new*x2(1);
x2new_(2)=x2(2)*s(2);x2new_(3)=x2(2)*X1(2);
x2new = x2new+x2new_;
x1x2new(1)=s(1)*s(2);x1x2new(2)=X1(1)*s(2)+X1(2)*s(1);x1x2new(3)=X1(1)*X1(2);
x1x2new=x1x2*x1x2new;
df = polyder(x1new+x2new+x1x2new);
lambda(1) = roots(df);
X1=X1+lambda(1)*s;
Xrep(1,1:2)=X1;
delf1(1) = polyval(polyder(x1),X1(1));
delf1(1) = (delf1(1))+(x1x2*X1(2));
delf1(2) = polyval(polyder(x2),X1(2));
delf1(2) = (delf1(2))+(x1x2*X1(1));
if all(X1)== 0
fprintf('%d %d is the optimum point',X1(1),X1(2));
end
itrep(1)=1;
it=2;
while all(delf1)==1
s=-delf1;
x1new(1)=s(1)^2;x1new(2)=2*X1(1)*s(1);x1new(3) = X1(1)^2;
x1new=x1new*x1(1);
x1new_(2)=x1(2)*s(1);x1new_(3)=x1(2)*X1(1);
x1new = x1new+x1new_;
x2new(1)=s(2)^2;x2new(2)=2*X1(2)*s(2);x2new(3) = X1(2)^2;
x2new=x2new*x2(1);
x2new_(2)=x2(2)*s(2);x2new_(3)=x2(2)*X1(2);
x2new = x2new+x2new_;
x1x2new(1)=s(1)*s(2);x1x2new(2)=X1(1)*s(2)+X1(2)*s(1);x1x2new(3)=X1(1)*X1(2);
x1x2new=x1x2*x1x2new;
df = polyder(x1new+x2new+x1x2new);
lambda(it) = roots(df);
X1=X1+lambda(it)*s;
delf1(1) = polyval(polyder(x1),X1(1));
delf1(1) = (delf1(1))+(x1x2*X1(2));
delf1(2) = polyval(polyder(x2),X1(2));
delf1(2) = (delf1(2))+(x1x2*X1(1));
itrep(it)=it;
srep(it,1:2)=s;
Xrep(it,1:2)=X1;
it=it+1;
end
=size(itrep);
matrix=;
answer = char(num2str(X1));
answer = ['The optimal point is [' answer ']'];
msgbox(answer,'Solution');
disp(' Press Any key to View Detailed Report............');
pause
echo off
report steep;
clc
[ 本帖最后由 suffer 于 2006-10-9 20:37 编辑 ] 这个是用什么语言写的?有点没看懂土人啊~~ <P>最速下降法我一直都没学会,看来我的水平还很差</P> 看到程序才感到自己真应该在细读基础课本了。 把这些常用的数学算法编程实现太让我们感谢了!盼多见到这类作品亚 原帖由 broad 于 2006-5-15 22:02 发表
这个是用什么语言写的?有点没看懂土人啊~~
当然是matlab版了,没看这里是matlab实例赏析吗? 有没有共轭梯度的算法实现啊 原帖由 freeway 于 2006-10-10 22:50 发表
有没有共轭梯度的算法实现啊
http://forum.vibunion.com/forum/viewthread.php?tid=27826
[ 本帖最后由 eight 于 2007-2-3 17:48 编辑 ] 原帖由 freeway 于 2006-10-10 22:50 发表
有没有共轭梯度的算法实现啊
http://forum.vibunion.com/forum/viewthread.php?tid=28933
[ 本帖最后由 eight 于 2007-2-3 17:48 编辑 ]
页:
[1]