Changeset 1416
 Timestamp:
 Mar 5, 2009 6:14:06 PM (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/develpeter/Ipopt/contrib/MatlabInterface/ipopt.m
r1412 r1416 17 17 % 18 18 % Calculates the objective function at the current point. It takes one 19 % point, the current iterate x. 19 % point, the current iterate x. For example, the definition of the 20 % objective function for the Hock & Schittkowski (H&S) test problem #71 21 % (with 4 optimization variables) would be 22 % 23 % function f = objective (x) 24 % f = x(1)*x(4)*sum(x(1:3)) + x(3); 20 25 % 21 26 % funcs.gradient (required) 22 27 % 23 % Computes the gradient of the objective at the current point. It 24 % takes one input, the current iterate x. 28 % Computes the gradient of the objective at the current point. It takes 29 % one input, the current iterate x. For H&S test problem #71, the 30 % definition of the gradient callback would be 31 % 32 % function g = gradient (x) 33 % g = [ x(1)*x(4) + x(4)*sum(x(1:3)) 34 % x(1)*x(4) 35 % x(1)*x(4) + 1 36 % x(1)*sum(x(1:3)) ]; 25 37 % 26 38 % funcs.constraints (optional) … … 30 42 % point. It takes one input, x. The return value is a vector of length 31 43 % equal to the number of constraints (it must be of the same length as 32 % options.cl and options.cu). 44 % options.cl and options.cu). For H&S test problem #71, the 45 % callback definition would be 46 % 47 % function c = constraints (x) 48 % c = [ prod(x); sum(x.^2) ]; 33 49 % 34 50 % funcs.jacobian (optional) … … 39 55 % sparse matrix, where M is the number of constraints and N is the 40 56 % number of variables. Type HELP SPARSE for more information on 41 % constructing sparse matrices in MATLAB. 57 % constructing sparse matrices in MATLAB. The definition of the 58 % callback function for H&S test problem #71 would be 59 % 60 % function J = jacobian (x) 61 % sparse([ prod(x)./x; 2*x ]); 62 % 63 % Notice that the return value is a sparse matrix. 42 64 % 43 65 % funcs.jacobianstructure (optional) … … 46 68 % variables. It takes no inputs. The return value is a sparse 47 69 % matrix whereby an entry is nonzero if and only if the Jacobian of 48 % the constraints is nonzero at ANY point. 70 % the constraints is nonzero at ANY point. The callback function for 71 % the H&S test problem #71 simply returns a 2 x 4 matrix of ones in 72 % the sparse matrix format: 73 % 74 % function J = jacobianstructure() 75 % J = sparse(ones(2,4)); 49 76 % 50 77 % funcs.hessian (optional) … … 67 94 % the output value, then X must be the same as TRIL(X). 68 95 % 96 % Here is an implementation of the Hessian callback routine for the 97 % H&S test problem #71: 98 % 99 % function H = hessian (x, sigma, lambda) 100 % H = sigma*[ 2*x(4) 0 0 0; 101 % x(4) 0 0 0; 102 % x(4) 0 0 0; 103 % 2*x(1)+x(2)+x(3) x(1) x(1) 0 ]; 104 % H = H + lambda(1)*[ 0 0 0 0; 105 % x(3)*x(4) 0 0 0; 106 % x(2)*x(4) x(1)*x(4) 0 0; 107 % x(2)*x(3) x(1)*x(3) x(1)*x(2) 0 ]; 108 % H = sparse(H + lambda(2)*diag([2 2 2 2])); 109 % 69 110 % funcs.hessianstructure (optional) 70 111 % … … 72 113 % for the Hessian matrix. Again, it is not needed if you are using the 73 114 % limitedmemory quasiNewton approximation to the Hessian. It takes no 74 % inputs, and must return a sparse, lower triangular matrix. 115 % inputs, and must return a sparse, lower triangular matrix. For H&S 116 % test problem #71, the MATLAB callback routine is fairly 117 % straightforward: 118 % 119 % function H = hessianstructure() 120 % H = sparse(tril(ones(4))); 75 121 % 76 122 % funcs.iterfunc (optional) … … 112 158 % IPOPT optimization. The auxiliary data keep the same values as they 113 159 % possessed in the initial call. If you need variables that change over 114 % time, you may want to consider global variables (type HELP GLOBAL). 160 % time, you may want to consider global variables (type HELP 161 % GLOBAL). See the lasso.m file in the examples subdirectory for an 162 % illustration of how the auxiliary data is passed to the various 163 % callback functions. 115 164 % 116 165 % options.zl, options.zu, options.lambda
Note: See TracChangeset
for help on using the changeset viewer.