EDA365电子论坛网
标题:
错误使用e04wc,输出参数太多
[打印本页]
作者:
Uqzalq
时间:
2020-11-2 14:50
标题:
错误使用e04wc,输出参数太多
如下为NAG library里面e04wc的程序,是别人文章里给的,用来求某函数最小值的,但是我运行时会说错误使用e04wc,输出参数太多,球球大佬怎么搞?
5 k6 f$ a( x4 Q2 Y M
7 C1 L% } {6 L0 K
7 K' p* R: G9 h ] N( m
function e04wc_example
3 @3 b0 ^1 \: `7 g& w
" t% H! Z+ e$ B6 U& L/ L5 a
fprintf('e04wc example results\n\n');
# |0 R2 p3 i/ n9 i- a1 w& L$ p
a = [1, 1, 1, 1];
+ q+ C- v# ]$ C& x( T
bl = [1, 1, 1, 1, -1e25, -1e25, 25];
" c' I9 r! t4 x
bu = [5, 5, 5, 5, 20, 40, 1e25];
, P! H' U: j! b) y/ q% s
istate = zeros(7, 1, 'int64');
2 }, {, A8 l! A. A. u4 p( \" g7 [
ccon = zeros(2,1);
+ ]$ Y; c; g$ P2 Z, d
cjac = zeros(2,4);
0 U9 B. f( \% L5 ^
clamda = zeros(7,1);
$ y4 X0 X8 y% a) P
hess = zeros(4,4);
" }' T) J1 x ~
x = [1; 5; 5; 1];
# x1 f5 E* y. ~( L8 Z
[iw,rw,ifail]=e04wc;
7 o+ D$ p. N# t
[majits, istate, ccon, cjac, clamda, objf, grad, hess, x, ...
, ^! X( g/ p( i, D
iw, rw, user, ifail] = ...
# g6 D. Z$ l8 @* a. {6 H
e04wd(...
# I& D) V K7 X5 t- D
a, bl, bu, @confun, @objfun, istate, ccon, cjac, clamda, ...
& H F! O+ I- M+ {5 W
hess, x, iw, rw);
' O8 Q% M( D( l1 I: \' ~, j
fprintf('Final objective value : %8.1f\n',objf);
: {' M; U4 M: ], Q: N5 V& t n
fprintf('Optimal values for x : ');
, h. \( c1 r* m9 H( |' b
fprintf(' %9.2f',x);
% ]4 E$ t. S6 P# a: ?
fprintf('\nGradients at x : ');
q" y& t1 V. {
fprintf(' %9.2f',grad);
$ r/ U0 y/ i5 g7 _4 x# L
fprintf('\nConstraint functions at x: ');
" x3 c; ~" T, R; O( s. `/ Y
fprintf(' %9.2f',ccon);
4 M7 M' V- b* q1 {: s6 L" q5 X
fprintf('\nNumber of major iterations = %5d\n',majits);
- E- u, A% [& n2 r2 b! a
) w2 v( D+ l, k" K' P
function [mode, ccon, cjac, user] = ...
$ M2 ]1 S% r# g, i
confun(mode, ncnln, n, ldcj, needc, x, cjac, nstate, user)
; u4 Q! M: l2 r
ccon = zeros(ncnln, 1);
) }; a! c" q, B; J
if (nstate == 1)
4 m% s O$ Y% w9 U# n5 U
% first call to confun. set all jacobian elements to zero.
' f; i. Z- x# x7 n
% note that this will only work when 'derivative level = 3'
. B/ s- [4 M6 g9 |: V( F0 R
% (the default; see section 11.2).
) K8 u7 I8 A1 r% T" G7 x! W
cjac = zeros(ncnln, n);
) Y" h! ~% L2 k; h' v1 A# N8 ]% W
end
0 n% C5 i7 r0 P7 f4 f! @
if (needc(1) > 0)
$ E H }2 R" x3 V/ X
if (mode == 0 || mode == 2)
' b! K* p1 w d% v j. q$ z5 O& O
ccon(1) = x(1)^2 + x(2)^2 + x(3)^2 + x(4)^2;
4 k: l+ L7 k$ o# v8 ^
end
; i1 P) ~! F$ e! A* s# r
if (mode == 1 || mode == 2)
& Q+ {' ]; _1 l& c( x
cjac(1,1) = 2*x(1);
# _$ Z5 e! M2 V, i& _; [
cjac(1,2) = 2*x(2);
( A. V; B" _7 G; Q
cjac(1,3) = 2*x(3);
0 Z/ v' j7 `: F1 v
cjac(1,4) = 2*x(4);
3 g$ u% {& D. H* T1 ]9 ]3 _$ f y
end
" L- {7 w- E( I% M$ W1 P! g
end
9 @3 v# [* E7 P3 \
if (needc(2) > 0)
" s9 T) F, W7 z: x9 N" t
if (mode == 0 || mode == 2)
7 W, F! Y4 F; z1 B2 C0 c* ?
ccon(2) = x(1)*x(2)*x(3)*x(4);
0 L0 g3 Q" q: y/ n: k. g* B
end
8 A7 J- F( f5 v8 U8 N* |* m6 V4 O8 N
if (mode == 1 || mode == 2)
9 U; d9 A' I' G$ g! C
cjac(2,1) = x(2)*x(3)*x(4);
$ D9 P+ K& \" x' S( v" x6 j7 n* K
cjac(2,2) = x(1)*x(3)*x(4);
+ t9 m9 G; [* y
cjac(2,3) = x(1)*x(2)*x(4);
, u" u5 y; ?; \. _
cjac(2,4) = x(1)*x(2)*x(3);
( q# B: o0 k$ ^. e! V6 R+ C4 \" d
end
+ t( s6 ]+ f; e. @/ b. O6 e1 T
end
( C3 a! Q' x' u- M. \2 J
5 q5 g1 @2 ?6 Y" w
function [mode, objf, grad, user] = objfun(mode, n, x, grad, nstate, user)
: q& f/ x$ D# l1 o1 i5 C
if (mode == 0 || mode == 2)
! {. l) I; c6 W' W/ {" l% J
objf = x(1)*x(4)*(x(1)+x(2)+x(3)) + x(3);
# j/ e$ j& u3 E( ^
end
$ p. {( z0 ]/ B, X9 P: c
if (mode == 1 || mode == 2)
! _' d. o0 l: G) t% t6 O
grad(1) = x(4)*(2*x(1)+x(2)+x(3));
( o* [1 R5 q, W" L; `/ B
grad(2) = x(1)*x(4);
$ S1 b- _9 r+ Y
grad(3) = x(1)*x(4) + 1;
z/ g2 X' \! C6 T6 W. S4 }2 \
grad(4) = x(1)*(x(1)+x(2)+x(3));
; V) v4 {# O) C" z- `( W
end
9 R/ k+ D$ z+ Y& ?. c q* p! j
作者:
yin123
时间:
2020-11-2 16:35
来了,来了,专业赚积分顶起来
作者:
regngfpcb
时间:
2020-11-2 19:20
哪里有问题啊
欢迎光临 EDA365电子论坛网 (https://bbs.eda365.com/)
Powered by Discuz! X3.2