Quartz | Level 8

## find initial guess for an optimization

Hello

I am writing a code in order to find an initial value for my optimization. For some reason, SAS keeps on giving me the following error

(ERROR: (execution) Matrices do not conform to the operation.)

I checked every single step, but can't find the error.

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
SAS Super FREQ

## Re: find initial guess for an optimization

It is always a good idea to post the log near the error, not just the error. In your case, the log says

```23182319 f= m*log(alpha*lambda)+(lambda-1)*Sum1 +2319! (alpha-1)*Sum2 + alpha*Sum3 +2320 alpha *(n-m-Rq[+])*log(1-(X[m]**lambda));2321232223232324 return( -f );2324! /* return -f so that extrema are maxima */2325 finish;2329  f = Camel(KK);
ERROR: (execution) Matrices do not conform to the operation.

operation : * at line 2319 column 22
operands  : alpha, lambda
alpha  10000 rows      1 col     (numeric)
lambda  10000 rows      1 col     (numeric)

statement : ASSIGN at line 2319 column 8
traceback : module CAMEL at line 2319 column 8

NOTE: Paused in module CAMEL.
```

"do not conform" for the '*' operation means that you are trying to perform matrix multiplication, but the matrices are the wrong dimension. By looking at the line number, you can see that matrix multiplication is not defined between two Nx1 vectors. Fortunately, you showed in a comment that you copied code from https://blogs.sas.com/content/iml/2014/06/11/initial-guess-for-optimization.html, and you can check that blog post to see that the author used the '#' operator (not the '*' operator) to perform elementwise multiplication of two vectors.

I don't know which of your symbols represent vectors vs scalars, but you can use # for multiplication when you define the function, like this:

```       f= m#log(alpha#lambda)+(lambda-1)#Sum1 + (alpha-1)#Sum2 + alpha#Sum3 +
alpha#(n-m-Rq[+])#log(1-(X[m]**lambda));
```
SAS Super FREQ

## Re: find initial guess for an optimization

It is always a good idea to post the log near the error, not just the error. In your case, the log says

```23182319 f= m*log(alpha*lambda)+(lambda-1)*Sum1 +2319! (alpha-1)*Sum2 + alpha*Sum3 +2320 alpha *(n-m-Rq[+])*log(1-(X[m]**lambda));2321232223232324 return( -f );2324! /* return -f so that extrema are maxima */2325 finish;2329  f = Camel(KK);
ERROR: (execution) Matrices do not conform to the operation.

operation : * at line 2319 column 22
operands  : alpha, lambda
alpha  10000 rows      1 col     (numeric)
lambda  10000 rows      1 col     (numeric)

statement : ASSIGN at line 2319 column 8
traceback : module CAMEL at line 2319 column 8

NOTE: Paused in module CAMEL.
```

"do not conform" for the '*' operation means that you are trying to perform matrix multiplication, but the matrices are the wrong dimension. By looking at the line number, you can see that matrix multiplication is not defined between two Nx1 vectors. Fortunately, you showed in a comment that you copied code from https://blogs.sas.com/content/iml/2014/06/11/initial-guess-for-optimization.html, and you can check that blog post to see that the author used the '#' operator (not the '*' operator) to perform elementwise multiplication of two vectors.

I don't know which of your symbols represent vectors vs scalars, but you can use # for multiplication when you define the function, like this:

```       f= m#log(alpha#lambda)+(lambda-1)#Sum1 + (alpha-1)#Sum2 + alpha#Sum3 +
alpha#(n-m-Rq[+])#log(1-(X[m]**lambda));
```
From The DO Loop