lagrmult.m
来自「various matlab programs to slove various」· M 代码 · 共 18 行
M
18 行
function [x,vinc,nit]=lagrmult(x0,lambda0,alpha0,beta,f,h,toll)x = x0; [r,c]=size(h); vinc = 0; lambda = lambda0;for i=1:r, vinc = max(vinc,eval(h(i,1:c))); endnorm2h=['(',h(1,1:c),')^2'];for i=2:r, norm2h=[norm2h,'+(',h(i,1:c),')^2']; endalpha = alpha0; options(1)=0; options(2)=toll*0.1; nit = 0;while vinc > toll lh=['(',h(1,1:c),')*',num2str(lambda(1))]; for i=2:r, lh=[lh,'+(',h(i,1:c),')*',num2str(lambda(i))]; end g=[f,'+0.5*',num2str(alpha,16),'*',norm2h,'+',lh]; [x]=fmins(g,x,options); vinc=0; nit = nit + 1; for i=1:r, vinc = max(vinc,eval(h(i,1:c))); end alpha=alpha*beta; for i=1:r, lambda(i)=lambda(i)+alpha*eval(h(i,1:c)); endendreturn
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?