Parameter tunning using GA
显示 更早的评论
Hello dears,
I need urgent help
I developed a simulink model on matlan 2023 and i tried to obtain the gain parameters using GA algorithm. A code is written by calling the simulink model , but the algorithm can not be excuted.
here is my code that calls the simulink model
function [cost]= optimization_SMC(z)
assignin('base','cz',z(1));
assignin('base','kz',z(2));
assignin('base','cp',z(3));
assignin('base','kp' ,z(4));
assignin('base','ct',z(5));
assignin('base','kt',z(6));
assignin('base','cs',z(7));
assignin('base','ks',z(8));
sim("SMC_designed_Completed_airdrag_pqr.slx");
cost(1)= ITAEZ(length(ITAEZ));
cost(2) = ASEP(length(ASEP));
cost(3) = ITAET(length(ITAET));
cost(4) = ASES(length(ASES));
end
.......
.......and Here is the GA command
% GA parameter
var=8;
lb=[1 1 1 0.4 1.3 1 1 0.3];
ub=[700 700 700 700 700 700 700 700];
%% Set solver options
options = optimoptions('ga','PopulationSize',200,...
'MaxGenerations',inf,'MaxStallGenerations',inf,...
'SelectionFcn','selectionstochunif','CrossoverFcn',...
'crossoverheuristic','MutationFcn','mutationadaptfeasible',...
'FunctionTolerance',1e-9,'ConstraintTolerance',1e-6,...
'Display','iter','PlotFcn','gaplotbestf');
%% Solve
obj_fn = @(z)optimization_SMC(z);
z= ga(obj_fn,var,[],[],[],[],lb,ub,[],options);
........
Here is the error after simulation
>> GA_Tunning
Error using makeState (line 61)
Your fitness function must return a scalar value.
Error in galincon (line 22)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 402)
[x,fval,exitFlag,output,population,scores] = galincon(FitnessFcn,nvars, ...
Error in GA_Tunning (line 28)
z= ga(obj_fn,var,[],[],[],[],lb,ub,[],options);
How can I solve???
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!