global variables in fmincon
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Philipp Siebel
le 6 Avr 2020
Réponse apportée : Anmol Dhiman
le 9 Avr 2020
Hi there,
at the moment I am using the fmincon function to identify parameters in a given equation to find a selected point x.
For example,
I have the value for x and the fmincon should find the values for (u,v,t)
x=t*sin(u)*cos(v)
Therefore the code is running with a global variable. Does anyone know how to use this without any global variables????
%%% CODE %%%%
globalx
x=2
... some constraints...
fun = @myfun;
X = fmincon(fun,x0,A,b,Aeq,beq,minW,maxW,[],opts);
functionF = myfun(ZW)
globalx
u = ZW(1);
v = ZW(2);
t = ZW(3);
.
.
.
some calculations...
.
.
.
0 commentaires
Réponse acceptée
Anmol Dhiman
le 9 Avr 2020
Hi Philipp,
Global variables are used to share a single value among various functions.
There are many other ways to do. You can refer to
The most secure way to extend the scope of a function variable is to use function input and output arguments, which allow you to pass values of variables.
Thanks,
Anmol Dhiman
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Nonlinear Optimization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!