checkExitCondition
Description
Examples
Create a four-element linear array of dipole antennas. Use it as an exciter for a reflector antenna.
Calculate maximum directivity of this reflector antenna.
freq = 70e6; la = linearArray(NumElements=4); la.Tilt = 90; referenceAnt = reflector; referenceAnt.Exciter = la; referenceAnt.GroundPlaneLength = 8; referenceAnt.GroundPlaneWidth = 4; referenceAnt.Spacing = 4; InitialDirectivity = max(max(pattern(referenceAnt,freq)))
InitialDirectivity = 9.9029
figure pattern(referenceAnt,freq)

Find the lowest return loss among all ports of this antenna at 70 MHz.
sp = sparameters(referenceAnt,freq); RetLossPort1 = 20*log10(max(abs(rfparam(sp,1,1)))); RetLossPort2 = 20*log10(max(abs(rfparam(sp,2,2)))); RetLossPort3 = 20*log10(max(abs(rfparam(sp,3,3)))); RetLossPort4 = 20*log10(max(abs(rfparam(sp,4,4)))); InitialLowestRetLossVal = max([RetLossPort1,RetLossPort2,RetLossPort3,RetLossPort4]);
Choose spacing between the dipoles of the exciter and exciter to reflector spacing as design variables. Specify the lower and upper bounds of these design variables.
Use the TR-SADEA optimizer to optimize this reflector antenna for its directivity and return loss. Specify an evaluation function for optimization using the CustomEvaluationFunction property of the OptimizerTRSADEA object. The evaluation function used in this example is defined at the end of this example.
Set the maximum number of function evaluations to 90 and initial population sample size to 10. Setting these parameters is optional. The TR-SADEA optimizer calculates best sample size automatically if you do not specify it.
Bounds = [0.1 0.1; 10 10]; s = OptimizerTRSADEA(Bounds); s.CustomEvaluationFunction = @customEvaluationWithConstraint2; setMaxFunctionEvaluations(s,90); defineInitialPopulation(s,10);
Validate the optimizer setup. Run the optimization for 50 iterations and check if maximum function evaluations have been reached. Observe the convergence trends plot.
validateSetup(s)
ans = logical
1
optimize(s,50); flag0 = isFunctionEvaluationsExhausted(s)
flag0 = logical
0
showConvergenceTrend(s)

View the best member data.
bestDesign = s.getBestMemberData
bestDesign =
bestMemberData with properties:
member: [7.6028 5.3499]
performances: -6.4699
fitness: -6.4699
bestIterationId: 47
bestDesignValues = bestDesign.member
bestDesignValues = 1×2
7.6028 5.3499
Update the reference antenna with design values obtained from the optimization and calculate the directivity.
Observe the increase in directivity post optimization.
referenceAnt.Exciter.ElementSpacing = bestDesignValues(1); referenceAnt.Spacing = bestDesignValues(2); postOptimizationDirectivity = max(max(pattern(referenceAnt,freq)))
postOptimizationDirectivity = 11.4678
figure pattern(referenceAnt,freq)

Calculate the post optimization return loss. Use the lowest return loss value among all ports.
Observe that the value of return loss after optimization is better than its previous value.
sp = sparameters(referenceAnt,freq); RetLossPort1 = 20*log10(max(abs(rfparam(sp,1,1)))); RetLossPort2 = 20*log10(max(abs(rfparam(sp,2,2)))); RetLossPort3 = 20*log10(max(abs(rfparam(sp,3,3)))); RetLossPort4 = 20*log10(max(abs(rfparam(sp,4,4)))); NewLowestRetLossVal = max([RetLossPort1,RetLossPort2,RetLossPort3,RetLossPort4]);
Check the exit status of the optimizer.
flag1 = isFunctionEvaluationsExhausted(s)
flag1 = logical
0
flag2 = checkExitCondition(s)
flag2 = logical
0
Restore the optimizer parameters to their previous successful iteration values. Use this step if the current iteration is interrupted and the iteration data is incomplete.
res = performRestore(s)
res =
OptimizerTRSADEA with properties:
Bounds: [2×2 double]
CustomEvaluationFunction: @customEvaluationWithConstraint2
Weights: []
UseParallel: 0
GeometricConstraints: [1×1 struct]
EnableLog: 0
This code defines the evaluation function used in this example.
function fitness = customEvaluationWithConstraint2(designVariables) % Create geometry la = linearArray(NumElements=4); la.Tilt = 90; la.ElementSpacing = designVariables(1); r = reflector; r.Exciter = la; r.GroundPlaneLength = 8; r.GroundPlaneWidth = 4; r.Spacing = designVariables(2); % Calculate realized gain objective = max(max(pattern(r, 70e6))); objective = -objective; % As optimizer always minimizes objective, % sign is reversed to maximize gain. % Constraints s11 < -10 % Calculate S-parameters freq = 70e6; s = sparameters(r,freq); RetLossPort1 = 20*log10(max(abs(rfparam(s,1,1)))); RetLossPort2 = 20*log10(max(abs(rfparam(s,2,2)))); RetLossPort3 = 20*log10(max(abs(rfparam(s,3,3)))); RetLossPort4 = 20*log10(max(abs(rfparam(s,4,4)))); lowestRetLossVal = max([RetLossPort1,RetLossPort2,RetLossPort3,RetLossPort4]); expVal = -20; % As constraint is satisfied when it is less than -20 dB, better % values are made to be equal to -20 dB to not affect optimizer % direction. constraint = (lowestRetLossVal-expVal); constraint = max(constraint,0); % Handle errors during S-parameters computation. % High penalty value is used to handle errors. fitness = objective + constraint; end
Input Arguments
Optimizer, specified as an OptimizerSADEA or OptimizerTRSADEA object. The function checks the exit status of the
optimizer specified in obj.
Example: OptimizerSADEA([1;2])
Output Arguments
Status of function evaluations and convergence, returned as one of these logical values:
0if the optimizer has not completed evaluations or reached convergence.1if the optimizer has completed evaluations or reached convergence.
Version History
Introduced in R2025a
See Also
Objects
Functions
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)