Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
初级会员
注册日期: 2013-04-16
帖子: 1
声望力: 0 ![]() |
![]()
主要程序如下(后面关于fun(x)函数太长去掉了),请高手帮忙解读下,从第二个end到第三个end之间的程序? 另外我需要用到这段程序来解自建的模型,有偿求合作。。
function x=Porjection3() clc sigama=0.5; gama=0.8; x0=[10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 0 0 0 0 0 0 0 0]; x=x0; fun(x) z=max_fun(x) r=(x-z) t=1 while norm(r)>1e-3 norm(r) m=0; f=fun(x); xx=x-gama^m*r; ff=fun(xx); while sum((f-ff).*r)>sigama*norm(r)^2 m=m+1; xx=x-gama^m*r; ff=fun(xx); if m>200 m break; end end yita=gama^m; y=(1-yita)*x+yita*z d=-(yita*r-yita*fun(x)+fun(y)) alfa=yita*sum(r.*(r-fun(x)+fun(y)))/(norm(d)^2) x=max(0,x+alfa*d) z=max_fun(x) r=(x-z) t=t+1 end function z=max_fun(x) f=fun(x); xx=x-f; z=max(xx,0); |
![]() |
![]() |