Cannot use sim command in genetic algorithm
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Imisi Jo
el 20 de Jul. de 2017
Comentada: Imisi Jo
el 25 de Jul. de 2017
For some reason I cannot seem to run the sim command to simulate a model which is required to estimate parameters in the model which the genetic algorithm will do. I pass the objective function to ga:
%%load measured data
load('data_R01_full','simVol_TECM','simTime_TECM','simSoC_TECM','simOCV_TECM');
cap=0;
R0=47e-3;
%%set bounds
lb=[0;47e-3]; %cap, R0
ub=[0.2;75e-3];
%%est fcn
estfcn=@(x) gafunc(x,simVol_TECM,simOCV_TECM,simSoC_TECM,simTime_TECM);
%%estimation
[xOpt,fVal] = ga(estfcn,2,[],[],[],[],lb,ub);A
And my objective function starts with this:
function G = gafunc(x,Vbat_meas,OCV_meas,SoC_meas,t_meas)
open('gatest_ss_standalone');
run 'ga_standalone_tests';%loads all the variables necessary for simulation
cap_val=x(1);
R0=x(2);
[tout,~,output]=sim('gatest_ss_standalone',StopTime);
close('gatest_ss_standalone')
It never simulates because I get an error saying some parameters are undefined in the model, even though I have specified it in the script 'ga_standalone_tests'. Anyone know why I get this error?
0 comentarios
Respuesta aceptada
Walter Roberson
el 20 de Jul. de 2017
Possibly your model is expecting to get the parameters from the base workspace. Some of the ways of fetching parameters can be configured specifically to look in the base workspace instead of in the current workspace.
Some of the blocks such as From Workspace normally look in the workspace of the function that calls sim() if the model is called by sim(), but look in the base workspace if the model is called by clicking on the model Run button or from the Simulink menus.
3 comentarios
Walter Roberson
el 20 de Jul. de 2017
What techniques are you using to fetch parameters from a workspace?
Más respuestas (0)
Ver también
Categorías
Más información sobre Genetic Algorithm en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!