Getting Started Example (nlpsg01)
/***************************************************************/
/* */
/* S A S S A M P L E L I B R A R Y */
/* */
/* NAME: nlpsg01 */
/* TITLE: Getting Started Example (nlpsg01) */
/* PRODUCT: OR */
/* SYSTEM: ALL */
/* KEYS: OR */
/* PROCS: OPTMODEL */
/* DATA: */
/* */
/* SUPPORT: UPDATE: */
/* REF: */
/* MISC: Example from the Getting Started section of the */
/* Interior Point Nonlinear Programming Solver */
/* chapter of Mathematical Programming. */
/* */
/***************************************************************/
proc optmodel;
var x{1..3} >= 0;
minimize f = (x[1] + 3*x[2] + x[3])**2 + 4*(x[1] - x[2])**2;
con constr1: sum{i in 1..3}x[i] = 1;
con constr2: 6*x[2] + 4*x[3] - x[1]**3 - 3 >= 0;
/* starting point */
x[1] = 0.1;
x[2] = 0.7;
x[3] = 0.2;
solve with NLP;
print x;
quit;
proc optmodel;
number n = 1000;
number b = 5;
var x{1..n} >= -1 <= 1 init 0.99;
var y{1..n} >= -1 <= 1 init -0.99;
var z{1..b} >= 0 <= 2 init 0.5;
minimize f = sum {i in 1..n} x[i] * y[i] + sum {j in 1..b} 0.5 * z[j]^2;
con cons1{k in 1..n}: x[k] + y[k] + sum {j in 1..b} z[j] = b;
con cons2: sum {i in 1..n} (x[i] + y[i]) + sum {j in 1..b} z[j] >= b + 1;
solve with NLP / algorithm=activeset logfreq=10;
quit;
proc optmodel;
var x >= -1 <= 1;
var y >= -1 <= 1;
min f = exp(sin(50*x)) + sin(60*exp(y)) + sin(70*sin(x)) + sin(sin(80*y))
- sin(10*(x+y)) + (x^2+y^2)/4;
solve with nlp / multistart=(maxstarts=30) seed=94245;
quit;
data samples;
input x1 x2 y;
datalines;
4 8 43.71
62 5 351.29
81 62 2878.91
85 75 3591.59
65 54 2058.71
96 84 4487.87
98 29 1773.52
36 33 767.57
30 91 1637.66
3 59 215.28
62 57 2067.42
11 48 394.11
66 21 932.84
68 24 1069.21
95 30 1770.78
34 14 368.51
86 81 3902.27
37 49 1115.67
46 80 2136.92
87 72 3537.84
;
/* Reqression model with interactive term: y = a*x1 + b*x2 + c*x1*x2 */
proc optmodel;
set obs;
num x1{obs}, x2{obs}, y{obs};
num mycov{i in 1.._nvar_, j in 1..i};
var a, b, c;
read data samples into obs=[_n_] x1 x2 y;
impvar Err{i in obs} = y[i] - (a*x1[i]+b*x2[i]+c*x1[i]*x2[i]);
min f = sum{i in obs} Err[i]^2;
solve with nlp/covest=(cov=5 covout=mycov);
print mycov;
print a b c;
quit;