## Minimizing an unconstrained NLP problem

I want to minimize an unconstrained NLP problem, having 4 variables. But, upon running the SAS file the solution status was failed and I got a warning that the "Objective function cannot be evaluated at the starting point." Can somebody PLEASE help me with this? I attached here the code. I am new to SAS by the way, it would be a great help for me.

``````proc optmodel;
var x{1..4} >=0 <=50;
min g=(-1) * ((-1) * (((10/x)^x) * ((12/x)^x) *
((0.5/(2*(0.4*x-0.2*x-1)))^(0.4*x-0.2*x-1)) *
((0.4/(2*(0.55*x-0.6*x-1)))^(0.55*x-0.6*x-1)) *
((50/(0.6*x-0.8*x))^(0.6*x-0.8*x)) *
((60/(0.5*x-0.4*x))^(0.5*x-0.4*x)) * ((100/x)^(-x)) *
((120/x)^(-x)) * ((((-0.34*x-0.08*x-0.475*x+0.66*x+3)*4)/(195*(-0.34*x-0.08*x+1.6)))^(-0.34*x-0.08*x+1.6))
* ((((-0.34*x-0.08*x-0.475*x+0.66*x+3)*2)/(195*(-0.475*x-0.66*x+1.4)))^(-0.475*x+0.66*x+1.4)))^(-1));

/* starting point */
x=0.5;
x=0.5;
x=0.5;
x=0.5;
solve with nlp / algorithm=activeset;
print x;
quit;``````
1 ACCEPTED SOLUTION

Accepted Solutions

## Re: Minimizing an unconstrained NLP problem

``````   min log_g = -(
x*log(10/x)
+ x*log(12/x)
+ y*log(0.5/(2*y))
+ y*log(0.4/(2*y))
+ y*log(50/y)
+ y*log(60/y)
- x*log(100/x)
- x*log(120/x)
+ y*log(y*4/(195*y))
+ y*log(y*2/(195*y))
);
``````

The resulting solution status is then Optimal rather than Best Feasible.

10 REPLIES 10

## Re: Minimizing an unconstrained NLP problem

I have a suggestion that should help, but first I want to make sure that your objective function is defined correctly.  In the final line of the MIN statement, did you really mean to have both -0.66*x and +0.66*x, or should those coefficients be the same?

## Re: Minimizing an unconstrained NLP problem

Hi Rob,

I am sorry for typo error, I mean to have only +0.66 in the objective function. By the way the objective function should be define by:

``````proc optmodel;
var x{1..4} >=0 <=50;
min g=(-1) * ((-1) * (((10/x)^x) * ((12/x)^x) *
((0.5/(2*(0.4*x-0.2*x-1)))^(0.4*x-0.2*x-1)) *
((0.4/(2*(0.55*x-0.6*x-1)))^(0.55*x-0.6*x-1)) *
((50/(0.6*x-0.8*x))^(0.6*x-0.8*x)) *
((60/(0.5*x-0.4*x))^(0.5*x-0.4*x)) * ((100/x)^(-x)) *
((120/x)^(-x)) * ((((-0.34*x-0.08*x-0.475*x+0.66*x+3)*4)/(195*(-0.34*x-0.08*x+1.6)))^(-0.34*x-0.08*x+1.6)) * ((((-0.34*x-0.08*x-0.475*x+0.66*x+3)*2)/(195*(-0.475*x+0.66*x+1.4)))^(-0.475*x+0.66*x+1.4)))^(-1));

/* starting point */
x=0.5;
x=0.5;
x=0.5;
x=0.5;
solve with nlp / algorithm=activeset;
print x;
quit;``````

## Re: Minimizing an unconstrained NLP problem

I hope you can help me with this :))

## Re: Minimizing an unconstrained NLP problem

One way to avoid typos is to use implicit variables to represent expressions that appear in multiple places:

``````   impvar y {i in 1..7} =
if i = 1 then 0.4*x-0.2*x-1
else if i = 2 then 0.55*x-0.6*x-1
else if i = 3 then 0.6*x-0.8*x
else if i = 4 then 0.5*x-0.4*x
else if i = 5 then -0.34*x-0.08*x-0.475*x+0.66*x+3
else if i = 6 then -0.34*x-0.08*x+1.6
else if i = 7 then -0.475*x+0.66*x+1.4;
min g=(-1) * ((-1) * (((10/x)^x) * ((12/x)^x) *
((0.5/(2*y))^y) *
((0.4/(2*y))^y) *
((50/y)^y) *
((60/y)^y) * ((100/x)^(-x)) *
((120/x)^(-x)) * (((y*4)/(195*y))^y)
* (((y*2)/(195*y))^y))^(-1));
``````

With or without these changes, try using the multistart option:

``````   solve with nlp / ms;
``````

## Re: Minimizing an unconstrained NLP problem

Hi Rob, I just want to know it is necessary to replace the X variables in the if statements with Y? Or I just need to have it that way?

## Re: Minimizing an unconstrained NLP problem

Hi there, I tried running the code that you sent me however I got this error saying "Statement is not valid or it is used out of proper order.

``````
1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73            impvar y {i in 1..7} =
______
180
ERROR 180-322: Statement is not valid or it is used out of proper order.

74               if i = 1 then 0.4*x-0.2*x-1
75               else if i = 2 then 0.55*x-0.6*x-1
76               else if i = 3 then 0.6*x-0.8*x
77               else if i = 4 then 0.5*x-0.4*x
78               else if i = 5 then -0.34*x-0.08*x-0.475*x+0.66*x+3
79               else if i = 6 then -0.34*x-0.08*x+1.6
80               else if i = 7 then -0.475*x+0.66*x+1.4;

81            min g=(-1) * ((-1) * (((10/x)^x) * ((12/x)^x) *
___
180
ERROR 180-322: Statement is not valid or it is used out of proper order.

82               ((0.5/(2*y))^y) *
83               ((0.4/(2*y))^y) *
84               ((50/y)^y) *
85               ((60/y)^y) * ((100/x)^(-x)) *
86               ((120/x)^(-x)) * (((y*4)/(195*y))^y)
87               * (((y*2)/(195*y))^y))^(-1));

88
89                  solve with nlp / ms;
_____
180

ERROR 180-322: Statement is not valid or it is used out of proper order.

90
91         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
104

``````

## Re: Minimizing an unconstrained NLP problem

Hi Rob, I just want to ask what if I run this code and I don't want to set an upper bound for my Variables X.. X, therefore I would like them only to be greater than or equal to zero. However, I've tried running this code multiple times and I've got different results for X and it only says that it has only the "best feasible solution" everytime I run it. I was just concerned about how can I deal with this type of problem? or Can we have options other than multistart, or shall we incorporate a search method for this? I'm clueless. Thanks for the help! 🙂

``````proc optmodel;
var x{1..4} >=0;
min g=(-1) * ((-1) * (((10/x)^x) * ((12/x)^x) *
((0.5/(2*(0.4*x-0.2*x-1)))^(0.4*x-0.2*x-1)) *
((0.4/(2*(0.55*x-0.6*x-1)))^(0.55*x-0.6*x-1)) *
((50/(0.6*x-0.8*x))^(0.6*x-0.8*x)) *
((60/(0.5*x-0.4*x))^(0.5*x-0.4*x)) * ((100/x)^(-x)) *
((120/x)^(-x)) * ((((-0.34*x-0.08*x-0.475*x+0.66*x+3)*4)/(195*(-0.34*x-0.08*x+1.6)))^(-0.34*x-0.08*x+1.6))
* ((((-0.34*x-0.08*x-0.475*x+0.66*x+3)*2)/(195*(-0.475*x+0.66*x+1.4)))^(-0.475*x+0.66*x+1.4)))^(-1));

impvar y {i in 1..7} =
if i = 1 then 0.4*x-0.2*x-1
else if i = 2 then 0.55*x-0.6*x-1
else if i = 3 then 0.6*x-0.8*x
else if i = 4 then 0.5*x-0.4*x
else if i = 5 then -0.34*x-0.08*x-0.475*x+0.66*x+3
else if i = 6 then -0.34*x-0.08*x+1.6
else if i = 7 then -0.475*x+0.66*x+1.4;
min f=(-1) * ((-1) * (((10/x)^x) * ((12/x)^x) *
((0.5/(2*y))^y) *
((0.4/(2*y))^y) *
((50/y)^y) *
((60/y)^y) * ((100/x)^(-x)) *
((120/x)^(-x)) * (((y*4)/(195*y))^y)
* (((y*2)/(195*y))^y))^(-1));

solve with nlp / ms;
print x;``````

## Re: Minimizing an unconstrained NLP problem

``````   min log_g = -(
x*log(10/x)
+ x*log(12/x)
+ y*log(0.5/(2*y))
+ y*log(0.4/(2*y))
+ y*log(50/y)
+ y*log(60/y)
- x*log(100/x)
- x*log(120/x)
+ y*log(y*4/(195*y))
+ y*log(y*2/(195*y))
);
``````

The resulting solution status is then Optimal rather than Best Feasible.

## Re: Minimizing an unconstrained NLP problem

Indeed the solution that you recommended was brilliant and I thank you for that. I never had that idea before 🙂 In line with this, I tried this approach in evaluating the optimal values for another unconstrained minimization, however, it says that the solution status is failed. I guess I've had some problem with formulation? or in dealing with this type should require other type of solver?

``````proc optmodel;
var x{1..4} >=0;

impvar y {i in 1..8} =
if i = 1 then -((-0.6*4.5)/(1.6*5.5))*x-(4.5/5.5)*x
else if i = 2 then -((-0.7*5.2)/(1.7*6.2))*x-(5.2/6.2)*x
else if i = 3 then (-1/0.72)+((1/0.72)+((-0.6*15.5)/(0.72*1.6*5.5)))*x+((15.5/(0.72*5.5))-((1/0.72)+1))*x
else if i = 4 then (-1/0.78)+((1/0.78)+((-0.7*17.6)/(0.78*1.7*6.2)))*x+((17.6/(0.78*6.2))-((1/0.78)+1))*x
else if i = 5 then (0.6/(1.6*5.5))*x-(1/5.5)*x
else if i = 6 then (0.7/(1.7*6.2))*x-(1/6.2)*x
else if i = 7 then (-1/0.72)+((1/0.72)+(((4.5*5.5)/0.72)+(2/0.72)+1)*(-0.6/1.6))*x-(((5.5*4.5)+1)/0.72)*x
else if i = 8 then (-1/0.78)+((1/0.78)+(((5.2*6.2)/0.78)+(2/0.78)+1)*(-0.7/1.7))*x-(((5.2*6.2)+1)/0.78)*x;

min log_h = -(
- x*log(3500/(300*x))
- x*log(4000/(300*x))
+ x*log(175/x)
+ x*log(64000/(300*x))
+ y*log(3500/(300*y))
+ y*log(4000/(300*y))
+ y*log(0.15/(600*y))
+ y*log(0.2/(600*y))
+ y*log(5250/y)
+ y*log(2000000/(300*y))
- y*log(3.9/(45*y))
- y*log(4.3/(45*y))
);

solve with nlp / ms;
print x;
quit;``````

## Re: Minimizing an unconstrained NLP problem

The log function requires a positive argument, and that implies that each x[i] and y[i] should be positive.  But x, y, and y cannot all be nonnegative, as detected by using the IIS functionality:

``````   con c {i in 1..8}: y[i] >= 0;
solve noobj with lp / iis=on;
expand / iis;
``````

SAS Output

 ```Var x >= 0 Constraint c: y >= 0 Constraint c: y >= 0 ```

Now expand y and y:

``````   expand y;
expand y;
``````

SAS Output

 ```Impvar y = 1.3573200993*x - 0.2165134044*x - 1.2820512821 ```

 ```Impvar y = - 42.615384615*x - 17.205128205*x - 1.2820512821 ```

Indeed, x >= 0 and y >= 0 together imply x >= 0, which forces y < 0.  I would recommend checking your formula for y, which should not have all coefficients negative.

Discussion stats
• 10 replies
• 1287 views
• 3 likes
• 2 in conversation