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

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.


1 Reply Last Post 31.10.2022, 08:35 GMT-4
COMSOL Moderator

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.


Kristian Ejlebjærg Jensen COMSOL Employee

Please login with a confirmed email address before reporting spam

Posted: 2 years ago 31.10.2022, 08:35 GMT-4

This looks like a problem with MATLAB syntax. I suggest trying some standard benchmark problem. Possibly the MATLAB documentation will include an example.

This looks like a problem with MATLAB syntax. I suggest trying some standard benchmark problem. Possibly the MATLAB documentation will include an example.

Note that while COMSOL employees may participate in the discussion forum, COMSOL® software users who are on-subscription should submit their questions via the Support Center for a more comprehensive response from the Technical Support team.