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

I am trying to minimize the function

f =(w1+a1x+b1y)^2 +(w2+a2x+b2y)^2 subject to

1 < x,y< 55 using the nlpcg routine.

I first define a global variable m which contains the

coefficients Wi, Ai, Bi-the data. So

m is a 2x3 matrix with first row (w1 a1 b1) and second row

(w2 a2 b2).The starting point is x=(1,1). I want the optimal x that will minimize f.I have the following sas code to define the Objective function.

Start f(x) global (m);

               sum= m [,2:3]*x + m [,1];

                res = ssq (sum);

                return res;

Finish f;

con={ 1        1,

            55      55};

x=j (2,1,1);

opt={0 3};

call nlpcg (rc, xr,"f", x, con);

print rc; print xr;

I get an error that says (execution) matrix does not conform to operation pointing to the line inside f where I do the multiplication m [,2:3]*x. I don't recall the exact words in the message but IML objects to the part where I multiply m and x. Then it says rc and xr do not have values.  I have tried doing the multiplication inside a DO LOOP ...extracting each row of m and multiplying by x. This also gives an error though the message is slightly different-it says rc=100. I thought rc is at most 10. In any case I would rather not use the DO loop.


Would appreciate any help with the problem.

1 ACCEPTED SOLUTION

Accepted Solutions
Hutch_sas
SAS Employee

The problem is that when IML calls your objective function during the optimization, it is supplying a row vector for x. Try transposing x in the second line of your objective module, i.e.

sum= m [,2:3]*x` + m [,1];

and see if that doesn't work as it is supposed to.

View solution in original post

4 REPLIES 4
Hutch_sas
SAS Employee

The problem is that when IML calls your objective function during the optimization, it is supplying a row vector for x. Try transposing x in the second line of your objective module, i.e.

sum= m [,2:3]*x` + m [,1];

and see if that doesn't work as it is supposed to.

nstdt
Quartz | Level 8

I tried that but it gives me a different error now :

Execution error as noted previously (rc = 100).I have also dropped the constants with from my input since they should not make a difference to the minimization.

What does this rc=100 indicate?

Thanks for any help.

Hutch_sas
SAS Employee

Could you post your current program, and your run-time log?

nstdt
Quartz | Level 8

Actually you're suggestion does work. I think that in addition to the transposed vector x, the variable passed into f was called something else inside the body of f( it was not called x inside).

Thanks so much for the help!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 1150 views
  • 0 likes
  • 2 in conversation