Matlab does not find function, after it has found it >50 times

5 visualizaciones (últimos 30 días)
Vincent
Vincent el 11 de Mayo de 2012
Dear all,
I am running a rather large fmincon optimization. The objective function is named 'Main' in my simulation and is located in the same directory as the calling function and all other relevant functions and files. 'Main' is called by the optimizer multiple times. In order to finish the simulation probably about 500 times. After a certain amount of iterations, I get the error, "Main(x) not defined", as if suddenly it could not be found. For the very same simulation, the very same code, this error happens at different number of iterations, sometimes as early as 50, sometimes at the 450ths iteration. It happens earlier when I simultaneously work on the computer. I believe this to be a software error, not a user error, but what can I do about this? I need this simulation to run. Please help.
  2 comentarios
Jan
Jan el 11 de Mayo de 2012
Please use meaningful tags, which allow to identify the class of a problem. "error" is not useful.
Vincent
Vincent el 11 de Mayo de 2012
Dear Jan.
1.)
Nothing differs. Its the exact same code, the same folder, the same names. I change absolutely NOTHING. But when I execute the code, it crashes with the said error at a random number of iterations. I did observe, that it crashes sooner, as I continue working on the same machine (for example write in Word).
2.)
??? Undefined function or method 'Main' for input arguments of type 'double'.
Error in ==> ObjectiveAndConstraints>constraint at 27
[obj1,c1,ceq1] = Main(x);
Error in ==> C:\Program Files\MATLAB\R2011a\toolbox\optim\optim\private\evalObjAndConstr.p>evalObjAndConstr
at 43
Error in ==> C:\Program
Files\MATLAB\R2011a\toolbox\optim\optim\private\backtrackLineSearch.p>backtrackLineSearch at 75
Error in ==> C:\Program Files\MATLAB\R2011a\toolbox\optim\optim\sqpLineSearch.p>sqpLineSearch at 280
Error in ==> fmincon at 832
[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN] =
sqpLineSearch(funfcn,X,full(A),full(B),full(Aeq),full(Beq), ...
Error in ==> MASTER at 124
x = fmincon(objective_handle,x_0,[],[],[],[],lb,ub,constraint_handle,options);
3.)
I do not know what you mean by Matlab path, but as said, its all in just one and the same folder. There is no time driven function involved.
4.)
There is no automatic modifying of M-files. All the m-files remain unchanged. There is also no clear command in files the optimizer uses.
However, deep down in the code, I run a a subroutine. This subroutine requires a DAT file as import. This DAT files is written new on every iteration. But that is a few levels below 'Main' (Main calls a function, which calls a function which writes the input DAT file).

Iniciar sesión para comentar.

Respuestas (2)

Jan
Jan el 11 de Mayo de 2012
Please explain more details:
  1. What differs, if the problem occurs after 50 or 450 iterations? Is this the same problem and a deterministic model?
  2. Please copy the complete error message. The abbreviation "Main(x) not defined" may conceal important details.
  3. Is the Main.m file included in the Matlab path? If not, is the parent folder the current folder and a function driven by the timer() command changes the current folder?
  4. Do you modify M-files automatically and trigger a reload by the clear() command?
[EDITED after additional comments]
The Matlab path is the list of folders to search functions in, see "help path".
If the DAT-file reading changes the current folder and the parent folder of the Main.m file is not added to the path (addpath, pathtool, "Set Path..." menu in the command window), you can get the posted error message. But the random appearance is surprising then. Do you use any other TIMER objects?
I suggest to check the path -question at first. Then use the debugger:
dbstop if error
and wait until the error stops Matlab. Then type "which Main -all". Is the Main.m file found?
Are the DAT files closed correctly after reading? You can check this by "fopen -all".

Vincent
Vincent el 15 de Mayo de 2012
Dear Jan,
thx for all your help. It in deed had to do with Matlab somehow somewhere loosing its path. I added the following to the code:
restoredefaultpath
addpath(pwd)
then it all worked fine.

Categorías

Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by