hi,
I am trying to solve the following problem
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:
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
You still need to correct the first error by adding a FIX statement.
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]);
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
You still need to correct the first error by adding a FIX statement.
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.