Cannot use sim command in genetic algorithm
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2017-7-20
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!