BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rohailk
Obsidian | Level 7

hi,

I am trying to solve the following problem

Capture.JPG

The initial point is =(0 0 0)

My code is the following

proc optmodel;
var x{1..3};
min f = x[1]^2  + 2*x[2]^2 + 5*x[3]^2 - 4*x[1] - 20*x[2] - 20*x[3] ;

/* starting point */
   x[1]= 0;
   x[2]= 0;
   x[3]=0;
solve; 
print x x.dual;
quit;

This code works fine

Now if P is the descent direction of f at Xo then

I need to find the minimizer Aplha for this problem

I mean to say that I am trying to solve this question:

Capture.JPG

 

I have tried the following code to calculate Alpha

proc optmodel;
   num n = 3;
   var x {1..n};
   min f = x[1]^2  + 2*x[2]^2 + 5*x[3]^2 - 4*x[1] - 20*x[2] - 20*x[3] ;
   
/* starting point */
   x[1]= 0;
   x[2]= 0;
   x[3]=0;
   solve; 
   print x x.dual;

   num p {1..n};
   for {j in 1..n} p[j] = -x[j].dual;
   var alpha >= 0;
   min g  = (x[1]+alpha*p[1])^2 + 2*(x[2]+alpha*p[1])^2 + 5*(x[3]+alpha*p[1])^2-4*(x[1]+alpha*p[1]) -20*(x[2]+alpha*p[1]) -20*(x[3]+alpha*p[1])
   solve;
   print alpha;
quit;

But this code is giving me wrong value of alpha...its showing alpha=0

Please help me to fix this code

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

You still need to correct the first error by adding a FIX statement.

View solution in original post

4 REPLIES 4
RobPratt
SAS Super FREQ

There are three errors:

1. You need to FIX x for the first solve, as in the previous examples.

2. You need a semicolon at the end of the declaration of g.

3. Some of the appearances of p[1] in g should instead be p[2] or p[3].

The corrected statement is:

 

min g = (x[1]+alpha*p[1])^2 + 2*(x[2]+alpha*p[2])^2 + 5*(x[3]+alpha*p[3])^2-4*(x[1]+alpha*p[1]) -20*(x[2]+alpha*p[2]) -20*(x[3]+alpha*p[3]);
rohailk
Obsidian | Level 7

Thanks for the quick response.

I fixed the code now like this:

proc optmodel;
   num n = 3;
   var x {1..n};
   min f = x[1]^2  + 2*x[2]^2 + 5*x[3]^2 - 4*x[1] - 20*x[2] - 20*x[3] ;
   
/* starting point */
   x[1]= 0;
   x[2]= 0;
   x[3]=0;
   solve; 
   print x x.dual;

   num p {1..n};
   for {j in 1..n} p[j] = -x[j].dual;
   var alpha >= 0;
   min g = (x[1]+alpha*p[1])^2 + 2*(x[2]+alpha*p[2])^2 + 5*(x[3]+alpha*p[3])^2-4*(x[1]+alpha*p[1]) -20*(x[2]+alpha*p[2]) -20*(x[3]+alpha*p[3]);

   solve;
   print alpha;
quit;

but when I run it. I get the value of alpha=0. Is it ok or need some adjustment in the code please?

thanks

RobPratt
SAS Super FREQ

You still need to correct the first error by adding a FIX statement.

rohailk
Obsidian | Level 7

thank you so much..i fixed it like this

proc optmodel;
   num n = 3;
   var x {1..n};
   min f = x[1]^2  + 2*x[2]^2 + 5*x[3]^2 - 4*x[1] - 20*x[2] - 20*x[3] ;
   
/* starting point */
   fix x[1] = 0;
   fix x[2] = 0;
   fix x[3] = 0;

   solve; 
   print x x.dual;

   num p {1..n};
   for {j in 1..n} p[j] = -x[j].dual;
   var alpha >= 0;
   min g = (x[1]+alpha*p[1])^2 + 2*(x[2]+alpha*p[2])^2 + 5*(x[3]+alpha*p[3])^2-4*(x[1]+alpha*p[1]) -20*(x[2]+alpha*p[2]) -20*(x[3]+alpha*p[3]);

   solve;
   print alpha;
quit;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

Discussion stats
  • 4 replies
  • 906 views
  • 0 likes
  • 2 in conversation