MATLAB doesn't recognize the function optimoptions

I'm getting an error at the following line:
options = optimoptions('ga','PopulationSize',10,'MaxGenerations',10);
The following message exemplifies the problem.
I'm using the version 9.10 (R2021a) of MATLAB and the version 4.5 (R2021a) of the Global Optimization Toolbox
The photo is just an exemple, I must say that the version written in lowercase also doesn't work
Any suggestions will be appreciated

回答 (2 件)

Star Strider
Star Strider 2025 年 1 月 26 日

0 投票

MATLAB is case-sensitive.
Try this —
options = optimoptions('ga')
optionbs =
ga options: Set properties: No options set. Default properties: ConstraintTolerance: 1.0000e-03 CreationFcn: [] CrossoverFcn: [] CrossoverFraction: 0.8000 Display: 'final' EliteCount: '0.05*PopulationSize' FitnessLimit: -Inf FitnessScalingFcn: @fitscalingrank FunctionTolerance: 1.0000e-06 HybridFcn: [] InitialPopulationMatrix: [] InitialPopulationRange: [] InitialScoresMatrix: [] MaxGenerations: '100*numberOfVariables' MaxStallGenerations: 50 MaxStallTime: Inf MaxTime: Inf MutationFcn: [] NonlinearConstraintAlgorithm: 'auglag' OutputFcn: [] PlotFcn: [] PopulationSize: '50 when numberOfVariables <= 5, else 200' PopulationType: 'doubleVector' SelectionFcn: [] UseParallel: 0 UseVectorized: 0
.
.

7 件のコメント

Julio
Julio 2025 年 1 月 26 日
Thanks for your response, but it still doesn't work
Star Strider
Star Strider 2025 年 1 月 26 日
My pleasure!
Check the documentation for your MATLAB release (R2021a). The currently available online documentation is for R2024b. I am not certain which one you are using as a reference, and while both have worked over the years, there have also been changes over the years when the character vector ('ga') has worked and the other (@ga) has not, and the reverse.
The other possibility is to use the function handle in your optimoptions call, for example —
options = optimoptions(@ga)
options =
ga options: Set properties: No options set. Default properties: ConstraintTolerance: 1.0000e-03 CreationFcn: [] CrossoverFcn: [] CrossoverFraction: 0.8000 Display: 'final' EliteCount: '0.05*PopulationSize' FitnessLimit: -Inf FitnessScalingFcn: @fitscalingrank FunctionTolerance: 1.0000e-06 HybridFcn: [] InitialPopulationMatrix: [] InitialPopulationRange: [] InitialScoresMatrix: [] MaxGenerations: '100*numberOfVariables' MaxStallGenerations: 50 MaxStallTime: Inf MaxTime: Inf MutationFcn: [] NonlinearConstraintAlgorithm: 'auglag' OutputFcn: [] PlotFcn: [] PopulationSize: '50 when numberOfVariables <= 5, else 200' PopulationType: 'doubleVector' SelectionFcn: [] UseParallel: 0 UseVectorized: 0
Both work in R2024b.
.
Walter Roberson
Walter Roberson 2025 年 1 月 26 日
What is the error message when using optimoptions('ga') ?
Walter Roberson
Walter Roberson 2025 年 1 月 26 日
If the message is about unrecognized solver, then the problem is that the Global Optimization Toolbox is not installed.
Julio
Julio 2025 年 1 月 26 日

Walter, the error message that I receive is the same shown at the photo, Unrecognized function or variable 'optimoptions'.

Star Strider
Star Strider 2025 年 1 月 26 日
Do you have the Optimization Toolbox and the Global Optimizaztion Toolbox licensed and installed?
If you do (since it is still not working) run these from your Command Window or a scriptt:
restoredefaultpath
rehash toolboxcache
and try it again. If it is still not working after that, Contact Support.
.
Walter Roberson
Walter Roberson 2025 年 1 月 26 日
If the message is about optimoptions not being recognized, then you do not have the Optimization Toolbox installed, and certainly not the Global Optimization Toolbox.

サインインしてコメントする。

Walter Roberson
Walter Roberson 2025 年 1 月 26 日

0 投票

If really necessary you could use the older gaoptimset (which has not been recommended since R2018b)

カテゴリ

ヘルプ センター および File ExchangeIntroduction to Installation and Licensing についてさらに検索

製品

リリース

R2021a

質問済み:

2025 年 1 月 26 日

コメント済み:

2025 年 1 月 26 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by