- b0 ~8 q: R( Bfunction f = myfun( x,t,E,u,c ) %目标函数 E% ^* p% n7 H+ t6 ^2 H%UNTITLED3 Summary of this function goes here 1 w5 D8 d" }. k% Detailed explanation goes here+ x7 F( {/ o' I4 Y: z7 x
f=t*sqrt(x'*E*x)-(u'-c)*x; : G. w _, A& ~! q# Wend 3 }4 t2 C) T0 Y! O$ G8 l, R) d- @( Z% z. [, U5 G% L2 d
function [C,Ceq] = mycon( x,t,k,E,u,c,R ) %非线性约束 ; K2 _; s; Q/ L9 V%UNTITLED4 Summary of this function goes here9 J3 q( Q, j. `% z
% Detailed explanation goes here ' g6 t# p; H f2 CC=t*k*sqrt(x'*E*x)/(t-k)-t*(u'-c)*x/(t-k)+t*R/(t-k); 8 o. @) L/ ^) x& {Ceq=[];) a) f. e$ G: {0 M; H
end+ v/ a0 h: {. K" }! A. M4 s
5 U) T/ l& u* V6 d
$ J! y" l H2 H- V R S B运行结果:/ }# E& Y3 K4 T
Solver stopped prematurely.* |) K: l- h0 q* l( G0 I' y& |
fmincon stopped because it exceeded the function evaluation limit,5 S0 b* C# A9 l
options.MaxFunEvals = 500 (the default value). ( D. i! N# K5 l8 p& i+ ^* `5 Q3 @1 \' y
x = 0 n) y8 e* G& l1 {% R- D# T -0.0175 & G- c/ a- ^3 H9 k5 ~ 0.4875$ U% h1 D4 g( Q& o
-0.01752 B8 s; e$ D# F. C9 a# o; ~
0.30744 j8 d% R& I2 V) O' M
0.2328 2 o* o7 q! b* d5 a+ j5 r0 W9 ~+ I9 u c
fval = 7 s: S/ L: I+ i, ]! ^9 E- m -0.0390 3 j) O& k4 P v( h3 X$ S8 t 7 o2 s3 {% c7 v: sexitflag = - ]( ^- X/ E1 x1 k& F3 q! w 0* r% A0 l. I7 b5 U0 \# s
* \ K4 k! o: I" I- x% k- y# v/ ~
output = , O6 v! Q; [( i' K" m! Z4 Y iterations: 51) V- b- H" q# f4 G4 Y1 G _
funcCount: 505 # [( y R: G. F4 K8 |3 o6 z lssteplength: 0.1250* \9 {* y' Q2 B: M
stepsize: 0.0812 # }$ H. }) a2 F: o9 @9 \7 B2 [- Z algorithm: 'medium-scale: SQP, Quasi-Newton, line-search' ! ]0 v1 F }. E# V firstorderopt: 2.47320 s5 ^9 U0 D: u9 w$ V; R2 P
constrviolation: 0.0509 3 E% V: o0 L1 T message: [1x145 char] 6 H9 G- j6 [; J6 k, F各位大虾,程序如上所述,为什么函数提前就结束了,是不是要改默认参数设置,小弟也试过,但是捣鼓不出来,希望各位高人不吝赐教,小弟先拜谢了 Orz