BookmarkSubscribeRSS Feed
aya123
Calcite | Level 5
I want to put x as non negative decision variable in the following code, so how can I put this constraint in the code?

proc iml;
start fun(x)global(m,l,g);
sumf=0;
do i = 1 to 3;
sumf = sumf + (m*l)+ (g* k)**2 /(l+ x)**2;
end;return (sumf);finish fun;
start con(k) global(cl,l);
c=j(2,1,0);
sumc1=0; do i = 1 to 2;sumc1 = sumc1 + (cl1**2 *l/(l+x)**2);end;
c[1]= 10-sumc1;
c[2]=(max(l)/min(l))-(max(l)+x)/(min(l)+x);
return (c);
finish con;
k=j(1,1,0);
optn=j(1,11,.); optn[11]=0; optn[10]=2;
call nlpqn (rc, kres, "fun", k, optn) nlc="con";
3 REPLIES 3
Hutch_sas
SAS Employee
Just add x <= 0 to your constraint module:

start con(x) global(cl1,l);
c=j(3,1,0);
sumc1=0;
do i = 1 to 2;
sumc1 = sumc1 + (cl1**2 *l/(l+x)**2);
end;
c[1]= 10-sumc1;
c[2]=(max(l)/min(l))-(max(l)+x)/(min(l)+x);
c[3]= x; /* to satisfy x >= 0 */
return (c);
finish con;

You will also need to change optn[10] to 3
Hutch_sas
SAS Employee
don't know what happend to the last reply:

start con(x) global(cl1,l);
c=j(3,1,0);
sumc1=0;
do i = 1 to 2;
sumc1 = sumc1 + (cl1**2 *l/(l+x)**2);
end;
c[1]= 10-sumc1;
c[2]=(max(l)/min(l))-(max(l)+x)/(min(l)+x);
c[3]= x; /* satisfy x >= 0 */
return (c);
finish con;

You will also need to change optn[10] to 3
Rick_SAS
SAS Super FREQ
I'll remind everyone that this text editor treats LeftBracket-i-RightBracket
as "begin italicize." To work around this, use a different index variable (such as x) or put a space between the brackets (such as x[ i ]).

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 3 replies
  • 815 views
  • 0 likes
  • 3 in conversation