Optimization: fmincon, error

4 visualizaciones (últimos 30 días)
niket shah
niket shah el 4 de Nov. de 2018
Respondida: Walter Roberson el 4 de Nov. de 2018
Can anyone please help me out why i am getting this error. Thank You.
  1 comentario
niket shah
niket shah el 4 de Nov. de 2018
Output argument "y" (and maybe others) not assigned during call to "obj1".
This the error

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 4 de Nov. de 2018
Your cost function only assigns to y within the for loop. Your for loop executes from 1 to H. If H is empty or is less than one then your for loop will not execute at all, leaving y undefined.
Your H is declared global. You do not show any code that assigns values to any of the global variables. The default value for global variables is empty.
Note that in order to assign a value to a global variable you need to declare it global and then assign to it. In trial_u you assign some values to variables that appear to be local variables (or possibly in the base workspace). Unless there is a global you have not shown us, those are not the same variables as the global variables. When you use global, it does not mean that every reference to a variable of that name everywhere is suddenly shared: only the places that declare it global share it.
Every iteration of your for loop overwrites ALL of y.
You are assigning a function handle to y. The return from a cost function needs to be a numeric scalar.
Your calculation is inefficient. You calculate a number of expressions that do not change between calls. It would be more efficient to precalculate them and pass their values into the function. You should read about Paramaterizing Functions, which is also a good way to avoid using global variables. As you have already noticed, global variables can be difficult to debug.

Más respuestas (0)

Categorías

Más información sobre Surrogate Optimization en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by