Hi,

I am running a Monte Carlo simulation. In short, in a loop, I generate data and estimate parameters by different methods. The code calls "eqSolvemt". There is actually no problem in the code but somehow with some simulated, the loop breaks and data I get the following error from eqSolvemt:

This is an overdetermined system. eqSolvemt requires that the system be square. ...

How can I change the code so that the simulation continues even this happens? I would like to draw a new sample if this happens or leave the results for this montecarlo sample as missing. I am using GAUSS 21.

Thanks

Best

## 6 Answers

This error comes up when your objective function returns a vector that is longer than the parameter vector.

I think this is more likely to be a problem in your code than a random problem from the simulation.

If you post your objective function and I can probably help.

I dont think the objective function is wrong given that I do not get this error for larger sample sizes at all. For small sample sizes I get it occasionally.

I would like to know how to prevent the code from stopping even if there is an error in eqsolvemt.

There is only one place in `eqsolvemt`

that reports this error. The code is here:

```
// Get current parameter vector from PV struct
x0 = pvGetParVector(par0);
// Count number of rows in parameter vector
n = rows(x0);
// Call objective function with current parameters
fvc = f(par0, ...);
// If the return from the objective function has
// more rows than the parameter vector error out
if rows(fvc) > n;
errorlog "\nERROR: This is an overdetermined system. eqSolvemt requ"\
"ires that\n the system be square. (i.e. that the number"\
" of variables\n equal the number of equations.\n";
end;
```

In this code,

`x0`

is the current parameter vector.`f`

is the call to your objective function.`fvc`

is the return from your objective function.

The only way this error can occur is if your objective function returns a vector with more rows than are in the parameter vector.

Do you know why your objective function might return more rows than there are in the parameter vector on some occasions?

I know this. I am not hundred percent sure why this is happening. Theoretically it should not happen. The data is generated always from the same process, so the dimensions of the parameter vector or the objective function is not changing. The objective function uses subsamples from data. The only explanation I can think of is for small sample size, one subsample is empty and this creates a problem. I am going to check this. However in the meantime I would like that the code still runs despite the error. Again, my question is how to prevent the code from stopping?

One option would be to add a couple of lines to `eqsolvemt.src`

around line 233 like this:

```
x0 = pvGetParVector(par0);
n = rows(x0);
fvc = f(par0, ...);
if rows(fvc) > n;
errorlog "\nERROR: This is an overdetermined system. eqSolvemt requ"\
"ires that\n the system be square. (i.e. that the number"\
" of variables\n equal the number of equations.\n";
// Set the retcode so we know what happened
out.retcode = 999;
retp(out);
```

Then you can check in your main code to see if this happened, like this:

```
for (start, stop, step);
...
...
out = eqsolvemt(&fct,...);
if out.retcode = 999;
// we know what happened
// and can avoid saving parameters
// and handle appropriately
endif;
```

That will keep things running. To debug and resolve the problem, you can add a check at the end of your objective function to compare the rows of the parameter vector and the output. If they don't match, you can save the parameter vector and any other relevant data and `end;`

the program.

Then you can debug the program with a single call to your objective function.

thanks, this almost helped:) But, eqsolve is used in other procedures with different outcome structures. I have to figure out how to deal with it.