Passing variables from one m-file to another

I am a beginner in MATLAB, so I would really appreciate any guidance on this seemingly obvious question. I have to minimize a function f(x)[Currently using fmincon]. f(x) has a number of parameters which I want to initialise during the run time itself, and each parameter has its own range. [Currently I am doing it using rand.] So I have created the my_fun file which initialises the parameters and creates the function. Now, how do I pass the values of these parameters to the constraint file?

 Respuesta aceptada

Matt J
Matt J el 23 de Mzo. de 2015
Editada: Matt J el 24 de Mzo. de 2015

0 votos

You should not be initializing parameters inside the file that implements your objective function, especially not random ones! That would make the output of your objective function random for any given input x, and therefore impossible to minimize iteratively. You should be initializing all parameters in the workspace of whatever code you have that calls fmincon. Once you've done that, you can pass the parameters both to f(x) and to your constraints using techniques discussed here,

Más respuestas (0)

Preguntada:

el 23 de Mzo. de 2015

Editada:

el 24 de Mzo. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by