fval =
5.4234e-031
exitflag =
1
2£® minsearchº¯Êý
µ÷Óøñʽ£º x=fminsearch(fun,x0) x=fminsearch(fun,x0,options) x=fminsearch(fun,x0,options,P1,P2) [x,fval]=fminsearch(¡) [x,fval, exitflag]=fminsearch(¡) [x,fval, exitflag,output]=fminsearch(¡)
[x,fval, exitflag,output,grad]=fminsearch(¡) [x,fval, exitflag,output,grad,hessian]=fminsearch(¡)
˵Ã÷£º²ÎÊý¼°·µ»Ø±äÁ¿Í¬ÉÏÒ»º¯Êý¡£¶ÔÇó½â¶þ´ÎÒÔÉϵÄÎÊÌ⣬fminsearchº¯Êý±Èfminuncº¯ÊýÓÐЧ¡£
3£® ¶àÔª·ÇÏßÐÔ×îС¶þ³ËÎÊÌ⣺
·ÇÏßÏßÐÔ×îС¶þ³ËÎÊÌâµÄÊýѧģÐÍΪ£º
ÆäÖÐLΪ³£Êý¡£
µ÷Óøñʽ£º x=lsqnonlin(fun,x0) x=lsqnonlin(fun,x0,lb,ub)
x=lsqnonlin(fun,x0,options)
x=lsqnonlin(fun,x0,options,P1,P2)
[x,resnorm]=lsqnonlin(¡)
[x,resnorm, residual,exitflag]=lsqnonlin(¡)
[x,resnorm, residual , exitflag,output]=lsqnonlin(¡)
[x,resnorm, residual,exitflag, output,lambda]=lsqnonlin(¡)
[x,resnorm, r esidual,exitflag, output,lambda,jacobian]=lsqnonlin(¡)
˵Ã÷£ºx·µ»Ø½âÏòÁ¿£»resnorm·µ»Øx´¦²Ð²îµÄƽ·½·¶ÊýÖµ£ºsum(fun(x).^2)£»residual·µ»Øx´¦µÄ²Ð²îÖµfun(x)£»lambda·µ»Ø°üº¬x´¦À¸ñÀÊÈÕ³Ë×ӵĽṹ²ÎÊý£»jacobian·µ»Ø½âx´¦µÄfunº¯ÊýµÄÑſɱȾØÕó¡£
lsqnonlinĬÈÏʱѡÔñ´óÐÍÓÅ»¯Ëã·¨¡£Lsqnonlinͨ¹ý½«options.LargeScaleÉèÖÃΪ¡¯off¡¯À´×÷ÖÐÐÍÓÅ»¯Ëã·¨¡£Æä²ÉÓÃһάËÑË÷·¨¡£
Àý4£®Çó minf=4(x2-x1)2+(x2-4)2 £¬Ñ¡Ôñ³õʼµãx0(1,1) ³ÌÐò£º
f ='4*(x(2)-x(1))^2+(x(2)-4)^2' [x,reshorm]=lsqnonlin(f,[1,1]) ½á¹û£º x =
3.9896 3.9912
reshorm =
5.0037e-009
Àý5£ºÇó
Çó½â£ºÏȱà¼ff5.mÎļþ£º function f=ff5(x) k=1:10;
f=2+2*k-exp(k*x(1))-exp(k*x(2)); È»ºó×÷³ÌÐò£ºx0=[0.2,0.3];
[x,resnorm]=lsqnonlin(@ff5,x0)
Ñ¡Ôñ³õʼµã£¬x0(0.2,0.3)
½á¹û £º x =
0.2578 0.2578
resnorm =
124.3622
¶þ£® ÓÐÔ¼Êø·ÇÏßÐԹ滮ÎÊÌ⣺
ÊýѧģÐÍ£º min F(x)
s.t Gi (x) ¡Ü0 i=1,¡,m Gj (x) =0 j=m+1,¡,n xl¡Üx¡Üxu
ÆäÖУºF(x)Ϊ¶àԪʵֵº¯Êý£¬G(x)ΪÏòÁ¿Öµº¯Êý£¬
ÔÚÓÐÔ¼Êø·ÇÏßÐԹ滮ÎÊÌâÖУ¬Í¨³£Òª½«¸ÃÎÊÌâת»»Îª¸ü¼òµ¥µÄ×ÓÎÊÌ⣬ÕâЩ×ÓÎÊÌâ¿ÉÒÔÇó²¢×÷Ϊµü´ú¹ý³ÌµÄ»ù´¡¡£Æä»ùÓÚK-T·½³Ì½âµÄ·½·¨¡£ËüµÄK-T·½³Ì¿É±í´ïΪ£º
·½³ÌµÚÒ»ÐÐÃèÊöÁËÄ¿±êº¯ÊýºÍÔ¼ÊøÌõ¼þÔڽ⴦ÌݶȵÄÈ¡Ïû¡£ÓÉÓÚÌݶÈÈ¡Ïû£¬ÐèÒªÓÃÀ¸ñÀÊÈÕ³Ë×Ó¦ËiÀ´Æ½ºâÄ¿±êº¯ÊýÓëÔ¼ÊøÌݶȼä´óСµÄ²îÒì¡£
µ÷Óøñʽ: x=fmincon(f,x0,A,b)
x=fmincon(f,x0,A,b,Aeq,beq) x=fmincon(f,x0,A,b,Aeq,beq,lb,ub) x=fmincon(f,x0,A,b,Aeq,beq,lb,ub,nonlcon) x=fmincon(f,x0,A,b,Aeq,beq,lb,ub,nonlcon,options) [x,fval]=fmincon(¡)
[x, fval, exitflag]=fmincon(¡) [x, fval, exitflag, output]=fmincon(¡)
[x, fval, exitflag, output, lambda]=fmincon(¡)
˵Ã÷£ºx=fmincon(f,x0,A,b)·µ»ØÖµxΪ×îÓŽâÏòÁ¿¡£ÆäÖУºx0Ϊ³õʼµã¡£A,bΪ²»µÈʽԼÊøµÄϵÊý¾ØÕóºÍÓÒ¶ËÁÐÏòÁ¿¡£
x=fmincon(f,x0,A,b,Aeq,beq) ×÷ÓеÈʽԼÊøµÄÎÊÌâ¡£ÈôûÓв»µÈʽԼÊø£¬ÔòÁîA=[ ]¡¢b=[ ] ¡£
x=fmincon(f, x0,A,b,Aeq,beq,lb,ub, nonlcon ,options) ÖÐlb ,ubΪ±äÁ¿xµÄϽçºÍÉϽ磻nonlcon=@fun,ÓÉMÎļþfun.m¸ø¶¨·ÇÏßÐÔ²»µÈʽԼÊøc (x) ¡Ü0ºÍµÈʽԼÊøg(x)=0£»optionsΪָ¶¨ÓÅ»¯²ÎÊý½øÐÐ×îС»¯¡£
Àý6£ºÇó½â£ºmin 100(x2-x12 )2+(1-x1)2 s.t x1¡Ü2;
x2¡Ü2
³ÌÐò£ºÊ×ÏȽ¨Á¢ff6.mÎļþ£º
function f=ff6(x)
f=100*(x(2)-x(2)^2)^2+(1-x(1))^2;
È»ºóÔÚ¹¤×÷¿Õ¼ä¼üÈë³ÌÐò£º
x0=[1.1,1.1]; A=[1 0;0 1]; b=[2;2];
[x,fval]=fmincon(@ff6,x0,A,b) ½á¹û£º x = 1.0000 1.0000
fval =
3.1936e-011
Àý7£ºÇó½â£º