. @; ?4 W2 h6 |% r' efunction f = myfun( x,t,E,u,c ) %目标函数$ f& ^3 j/ S) k1 ?
%UNTITLED3 Summary of this function goes here ; k6 ^, J M. u* {- _% Detailed explanation goes here7 V! k+ @5 |4 ]) ^# K5 N
f=t*sqrt(x'*E*x)-(u'-c)*x; . U5 z B, w2 Send 9 g! S& s' ]. {3 I1 g) k : Z: o7 u/ X+ o$ `- Ffunction [C,Ceq] = mycon( x,t,k,E,u,c,R ) %非线性约束! M) G6 h& `+ q# V: q n6 G. I& I
%UNTITLED4 Summary of this function goes here' w3 f/ S1 q$ m: t& m) a/ E
% Detailed explanation goes here4 f. B0 F1 I% ]5 I
C=t*k*sqrt(x'*E*x)/(t-k)-t*(u'-c)*x/(t-k)+t*R/(t-k);' _% D' \/ [+ O7 K N8 H
Ceq=[];" B s7 _& X3 ?7 O( @. W2 j
end ) G* p7 p! C' s* K8 a4 U3 ~' R ' `, G8 W& R. j( Y2 u" L& c$ R! f1 X+ }
运行结果: % J4 G5 \( a4 i3 e/ LSolver stopped prematurely. + k' E2 [6 a I; H6 L$ e0 J" G1 Kfmincon stopped because it exceeded the function evaluation limit, $ b4 h8 i5 t' d: doptions.MaxFunEvals = 500 (the default value).+ K5 \* ^. l$ A! U; j# F: Y
q4 s' k2 d+ I/ C+ N4 |x =& O( d5 y% _, Q, F' {1 ?, f
-0.0175) p* z3 |6 j2 P1 L2 ~* R
0.48754 N; U. R$ M' e g! ^8 u
-0.0175 + f( R- w. p+ O; A, m3 _' D+ R 0.3074 . J& k# Q5 X7 u5 K 0.2328. P9 j/ X X: u& i" O* f* Z
# E4 o% F' c& ~* Efval =$ U1 D( m. U% N* J0 ^" A
-0.0390 & m* V! r" L- B$ W! @1 | 7 O+ `! t, v! g; E! c4 A- lexitflag = & U7 D% M) s9 i% K$ J3 _% R 0! M8 ~& G7 v% i) L% n2 G