turn on suggestions

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

Showing results for

Find a Community

Topic Options

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-10-2014 01:39 PM

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.

Accepted Solutions

Solution

06-10-2014
04:15 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-10-2014 04:15 PM

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.

All Replies

Solution

06-10-2014
04:15 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-10-2014 04:15 PM

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
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-12-2014 05:32 AM

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
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-12-2014 08:35 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-12-2014 02:40 PM

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!