Discussion Closed This discussion was created more than 6 months ago and has been closed. To start a new discussion with a link back to this one, click here.
Genetic Algorithm in Matlab to optimize reaction force in Comsol model
Posted Aug 16, 2022, 9:33 a.m. EDT Optimization Version 5.5 1 Reply
Please login with a confirmed email address before reporting spam
I have a problem concerning the Genetic Algorithm in collaboration between Matlab and Comsol. I have a parameterized model in Matlab code that I calculate in Comsol. This works without problems and I get the reaction force (Fmax) I need output in Matlab. Now I want to embed the whole thing in a genetic algorithm. With the help of the variation of geometric variables I want to get a maximum reaction force (Fmax). However, at the moment I have difficulties to program this. If I try to optimize Fmax via a variation of thickness dx as follows:
function Fmax=objFun
Fmax=@(dx)ComsolTestGA;
dx = optimvar("dx","LowerBound",0.4,"UpperBound",0.8);
prob = optimproblem("Objective",Fmax(dx));%optimproblem("Objective",f(Fmax));
options=optimoptions("ga",'PopulationSize',100,'MaxStallGenerations',50,'MaxGenerations',100,'Display','iter',"PlotFcn","gaplotbestf");
startTime = tic;
nvar=3;
[sol,fval] = solve(prob,"Solver","ga","Options",options) timega = toc(startTime);
fprintf('GA optimization takes %g seconds.\n',timega)
end
I get the following error message: "Objective must be an OptimizationExpression or a struct containing scalar OptimizationExpressions."
Can someone help me and give me a hint what I am doing wrong? Thank you very much.
Hello Kim
Your Discussion has gone 30 days without a reply. If you still need help with COMSOL and have an on-subscription license, please visit our Support Center for help.
If you do not hold an on-subscription license, you may find an answer in another Discussion or in the Knowledge Base.