Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 06-10-2014 01:39 PM
(1507 views)

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

4 REPLIES 4

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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!

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 16. Read more here about **why** you should contribute and **what is in it** for you!

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.