RunMat
  • Pricing
RunMat
GitHub
GitHub
Sign inTry in browser
DesktopRuntimePhysicsCADAdministrationAgent

Get RunMat updates

New releases, guides and examples.

Product+
  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download
Math+
  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting
Physics+
  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA
Industries+
  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance
Learn+
  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students
Compare+
  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons
Company+
  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms

Product

  • Runtime
  • GPU
  • Parallel
  • Compile
  • Interop and MEX
  • Simulation
  • MCAD
  • ECAD
  • Enterprise
  • AI integrations
  • Pricing
  • Download

Math

  • Signal processing
  • Linear algebra
  • Statistics
  • Curve fitting
  • Differential equations
  • Control systems
  • Optimization
  • Finance
  • Data and tables
  • Plotting

Physics

  • Simulation overview
  • Structural
  • Thermal
  • Electromagnetic
  • Joule heating
  • Thermal stress
  • Acoustics
  • Fluid flow
  • Conjugate heat transfer
  • Fluid–structure
  • What is FEA

Industries

  • Aerospace
  • Automotive and transportation
  • Defense
  • Electronics and semiconductors
  • Energy
  • Industrial machinery
  • Life sciences
  • Quantitative finance

Learn

  • Guides
  • Docs
  • Function reference
  • Language reference
  • Migration guide
  • Changelog
  • MATLAB Online
  • MATLAB AI agent
  • For students

Compare

  • RunMat vs MATLAB
  • RunMat vs Ansys
  • RunMat vs SOLIDWORKS
  • RunMat vs Altium
  • RunMat vs Cadence
  • RunMat vs COMSOL
  • RunMat vs Python
  • RunMat vs Julia
  • RunMat vs Physics AI
  • RunMat vs Octave
  • Benchmarks
  • MATLAB alternatives
  • All comparisons

Company

  • About
  • Blog
  • Contact
  • Source code↗
  • License
  • Privacy
  • Terms
GitHubXLinkedIn

© Dystr, Inc. · RunMat v0.7.1, Nov 17, 2026

RunMat® is a registered trademark of Dystr, Inc. MATLAB® is a registered trademark of The MathWorks, Inc. RunMat is not affiliated with, endorsed by, or sponsored by The MathWorks, Inc.

/
See all docs
Builtin Reference
    • acceptancesa
    • annealingboltz
    • annealingfast
    • coneprog
    • crossoverarithmetic
    • crossoverheuristic
    • crossoverintermediate
    • crossoverlaplace
    • crossoverscattered
    • crossoversinglepoint
    • crossovertwopoint
    • eqnproblem
    • EquationProblem.solve
    • EquationProblem.subsasgn
    • EquationProblem.subsref
    • evaluate
    • fgoalattain
    • fitscalingprop
    • fitscalingrank
    • fitscalingshiftlinear
    • fitscalingtop
    • fminbnd
    • fmincon
    • fminimax
    • fminsearch
    • fminunc
    • fseminf
    • fsolve
    • fzero
    • ga
    • gacreationlinearfeasible
    • gacreationnonlinearfeasible
    • gacreationsobol
    • gacreationuniform
    • gacreationuniformint
    • gaplotbestf
    • gaplotbestindiv
    • gaplotdistance
    • gaplotexpectation
    • gaplotgenealogy
    • gaplotmaxconstr
    • gaplotrange
    • gaplotscorediversity
    • gaplotscores
    • gaplotselection
    • gaplotstopping
    • integerConstraint
    • integral
    • intlinprog
    • linprog
    • lsqcurvefit
    • lsqlin
    • LsqlinWarmStart.subsasgn
    • LsqlinWarmStart.subsref
    • lsqnonlin
    • lsqnonneg
    • mutationadaptfeasible
    • mutationgaussian
    • mutationpositivebasis
    • mutationpower
    • mutationuniform
    • optimexpr
    • optimget
    • OptimizationConstraint.evaluate
    • OptimizationConstraint.subsasgn
    • OptimizationConstraint.subsref
    • OptimizationExitflag.double
    • OptimizationExitflag.eq
    • OptimizationExitflag.ne
    • OptimizationExitflag.string
    • OptimizationExpression.acos
    • OptimizationExpression.acosh
    • OptimizationExpression.acot
    • OptimizationExpression.acoth
    • OptimizationExpression.acsc
    • OptimizationExpression.acsch
    • OptimizationExpression.asec
    • OptimizationExpression.asech
    • OptimizationExpression.asin
    • OptimizationExpression.asinh
    • OptimizationExpression.atan
    • OptimizationExpression.atanh
    • OptimizationExpression.cat
    • OptimizationExpression.cos
    • OptimizationExpression.cosh
    • OptimizationExpression.cot
    • OptimizationExpression.coth
    • OptimizationExpression.csc
    • OptimizationExpression.csch
    • OptimizationExpression.ctranspose
    • OptimizationExpression.cumprod
    • OptimizationExpression.cumsum
    • OptimizationExpression.diag
    • OptimizationExpression.diff
    • OptimizationExpression.dot
    • OptimizationExpression.eq
    • OptimizationExpression.evaluate
    • OptimizationExpression.exp
    • OptimizationExpression.ge
    • OptimizationExpression.horzcat
    • OptimizationExpression.ldivide
    • OptimizationExpression.le
    • OptimizationExpression.log
    • OptimizationExpression.mean
    • OptimizationExpression.minus
    • OptimizationExpression.mldivide
    • OptimizationExpression.mpower
    • OptimizationExpression.mrdivide
    • OptimizationExpression.mtimes
    • OptimizationExpression.norm
    • OptimizationExpression.plus
    • OptimizationExpression.power
    • OptimizationExpression.prod
    • OptimizationExpression.rdivide
    • OptimizationExpression.reshape
    • OptimizationExpression.sec
    • OptimizationExpression.sech
    • OptimizationExpression.sin
    • OptimizationExpression.sinh
    • OptimizationExpression.sqrt
    • OptimizationExpression.subsasgn
    • OptimizationExpression.subsref
    • OptimizationExpression.sum
    • OptimizationExpression.tan
    • OptimizationExpression.tanh
    • OptimizationExpression.times
    • OptimizationExpression.trace
    • OptimizationExpression.transpose
    • OptimizationExpression.uminus
    • OptimizationExpression.uplus
    • OptimizationExpression.vertcat
    • OptimizationExpression.zeros
    • OptimizationExpression.zerosLike
    • OptimizationProblem.solve
    • OptimizationProblem.subsasgn
    • OptimizationProblem.subsref
    • OptimizationVariable.subsasgn
    • OptimizationVariable.subsref
    • optimoptions
    • optimplotconstrviolation
    • optimplotfirstorderopt
    • optimplotfunccount
    • optimplotfval
    • optimplotfvalconstr
    • optimplotmilp
    • optimplotstepsize
    • optimplotx
    • optimproblem
    • optimset
    • optimvar
    • optimwarmstart
    • particleswarm
    • patternsearch
    • psplotbestf
    • psplotbestx
    • psplotfuncount
    • psplotmaxconstr
    • psplotmeshsize
    • pswcreationuniform
    • pswplotbestf
    • quad
    • quadprog
    • QuadprogWarmStart.subsasgn
    • QuadprogWarmStart.subsref
    • saplotbestf
    • saplotbestx
    • saplotf
    • saplotstopping
    • saplottemperature
    • saplotx
    • savemilpsolutions
    • secondordercone
    • selectionremainder
    • selectionroulette
    • selectionstochunif
    • selectiontournament
    • selectionuniform
    • simulannealbnd
    • solve
    • surrogateopt
    • surrogateoptplot
    • temperatureboltz
    • temperatureexp
    • temperaturefast

ga — Minimize scalar fitness by genetic selection, crossover and mutation with continuous or integer constraints.

Evolve a retained population using measured or explicitly supplied fitness, original linear/integer domains and nonlinear feasibility. Return the best feasible observation and the last completed population.

Syntax

[x,fval,exitflag,output,population,scores] = ga(fun,nvars)
[...] = ga(fun,nvars,A,b)
[...] = ga(fun,nvars,A,b,Aeq,beq)
[...] = ga(fun,nvars,A,b,Aeq,beq,lb,ub)
[...] = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon)
[...] = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,options)
All supported ga forms
[x,fval,exitflag,output,population,scores] = ga(fun,nvars)
[...] = ga(fun,nvars,A,b)
[...] = ga(fun,nvars,A,b,Aeq,beq)
[...] = ga(fun,nvars,A,b,Aeq,beq,lb,ub)
[...] = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon)
[...] = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,options)
[...] = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,intcon)
[...] = ga(fun,nvars,A,b,Aeq,beq,lb,ub,nonlcon,intcon,options)
[...] = ga(problem)

Inputs

fun
Type
Any
Required
Yes
Default
—
Description
Selected scalar fitness function; vectorized functions receive population rows.
nvars
Type
Any
Required
Yes
Default
—
Description
Positive exact integer-valued variable count.
A
Type
Any
Required
Yes
Default
—
Description
Full or sparse real linear inequality matrix, or [].
b
Type
Any
Required
Yes
Default
—
Description
Real right side for A*x<=b, or [].
Aeq
Type
Any
Required
Yes
Default
—
Description
Full or sparse real equality matrix, or [].
beq
Type
Any
Required
Yes
Default
—
Description
Real right side for Aeq*x=beq, or [].
lb
Type
Any
Required
Yes
Default
—
Description
Lower-bound prefix, or [] for unbounded coordinates.
ub
Type
Any
Required
Yes
Default
—
Description
Upper-bound prefix, or [] for unbounded coordinates.
nonlcon
Type
Any
Required
Yes
Default
—
Description
Selected two-output c<=0, ceq=0 function, or [].
options
Type
Any
Required
Yes
Default
—
Description
Canonical ga options or [].
intcon
Type
Any
Required
Yes
Default
—
Description
Exact one-based integer-variable indices, or [].
problem
Type
Any
Required
Yes
Default
—
Description
Scalar structure with fitnessfcn,nvars,options and optional Aineq,Bineq,Aeq,Beq,lb,ub,nonlcon,intcon,solver='ga',rngstate.
NameTypeRequiredDefaultDescription
funAnyYes—Selected scalar fitness function; vectorized functions receive population rows.
nvarsAnyYes—Positive exact integer-valued variable count.
AAnyYes—Full or sparse real linear inequality matrix, or [].
bAnyYes—Real right side for A*x<=b, or [].
AeqAnyYes—Full or sparse real equality matrix, or [].
beqAnyYes—Real right side for Aeq*x=beq, or [].
lbAnyYes—Lower-bound prefix, or [] for unbounded coordinates.
ubAnyYes—Upper-bound prefix, or [] for unbounded coordinates.
nonlconAnyYes—Selected two-output c<=0, ceq=0 function, or [].
optionsAnyYes—Canonical ga options or [].
intconAnyYes—Exact one-based integer-variable indices, or [].
problemAnyYes—Scalar structure with fitnessfcn,nvars,options and optional Aineq,Bineq,Aeq,Beq,lb,ub,nonlcon,intcon,solver='ga',rngstate.

Returns

x
Type
Any
Description
Best retained feasible point with finite real declared or measured fitness; [] before any such observation.
fval
Type
Any
Description
Raw fitness belonging to x, never a penalty or augmented selection score; [] when x is empty.
exitflag
Type
Any
Description
1 fixed-merit/feasibility tolerance; 3 unchanged; 5 fitness limit; 0 generations; -1 observer; -2 no feasible fitness; -4 stall time; -5 time; -9 unverified proposal.
output
Type
Any
Description
Generation, point/call counts, timing, constraint violation, initial RNG state, hybrid details, message and fitness provenance.
population
Type
Any
Description
Last completed population, excluding any separate hybrid point; [] before a completed initial population.
scores
Type
Any
Description
Last population raw fitness values, or penalty selection scores for mixed-integer problems; not the separate hybrid score.
NameTypeDescription
xAnyBest retained feasible point with finite real declared or measured fitness; [] before any such observation.
fvalAnyRaw fitness belonging to x, never a penalty or augmented selection score; [] when x is empty.
exitflagAny1 fixed-merit/feasibility tolerance; 3 unchanged; 5 fitness limit; 0 generations; -1 observer; -2 no feasible fitness; -4 stall time; -5 time; -9 unverified proposal.
outputAnyGeneration, point/call counts, timing, constraint violation, initial RNG state, hybrid details, message and fitness provenance.
populationAnyLast completed population, excluding any separate hybrid point; [] before a completed initial population.
scoresAnyLast population raw fitness values, or penalty selection scores for mixed-integer problems; not the separate hybrid score.

Returned values from ga depend on how many outputs the caller requests.

Errors

RunMat:ga:InvalidArgument
When
A public argument, active option, operator result or callback state violates its representation, geometry or numerical contract.
Message
ga: invalid argument
IdentifierWhenMessage
RunMat:ga:InvalidArgumentA public argument, active option, operator result or callback state violates its representation, geometry or numerical contract.ga: invalid argument

Calling forms and outputs

Use ga(fun,nvars), then optional complete A,b; Aeq,beq; lb,ub pairs, followed by nonlcon, intcon and options. The continuous ten-argument form puts options after nonlcon. A scalar problem structure requires fitnessfcn, nvars and options; optional fields are Aineq,Bineq,Aeq,Beq,lb,ub,nonlcon,intcon,solver='ga' and rngstate. nvars is positive and exactly representable as a structural count. intcon contains exact one-based indices; duplicates select the same integer coordinate once.

The six outputs are x,fval,exitflag,output,population,scores. x is a retained best feasible row, or the corresponding custom genome; fval is its raw finite real fitness. Both are [] when no such observation exists. Historical best observations survive a later user edit that removes their row from the active population. population is the last completed population, excluding a separate hybrid result. scores contains its raw fitness, except that mixed-integer problems expose penalty selection scores.

output.generations counts ordinary generations or completed augmented-Lagrangian subproblems. funccount counts fitness points, while objectiveCallCount counts semantic calls, so a vectorized call can contribute multiple points. nonlinearPointCount and nonlinearCallCount count the independent constraint work, including feasibility creation and final hybrid validation. innergenerations records total AL inner steps; linearnodes records internal linear/integer repair nodes. Other fields are maxconstraint,totaltime,rngstate,message,problemtype,fitnessprovenance,hybridflag,hybridfunccount and hybridaccepted. The hybrid's reported evaluation count is separate from measured GA callback counts.

Representations and constraints

The normal numerical form uses real double arrays; A and Aeq may be full or sparse. Right sides match matrix rows. Bounds are prefixes of at most nvars values, with trailing coordinates unbounded; [] means an absent role. Integer variables remain integer-valued in the returned binary64 representation. Mixed-integer problems require doubleVector and nonlcon must return an empty equality array. Numeric indices, not IntegerConstraint extended-domain objects, are the intcon form for ga.

PopulationType is doubleVector, bitstring or custom. Bitstring coordinates are exact zero/one doubles. Custom populations use their ordinary size, subsref and subsasgn semantics; custom crossover and mutation are required, with either a complete initial population or a custom creator. Bounds, linear and nonlinear constraints are inactive for bitstring/custom populations; nonempty intcon is rejected. HybridFcn is unavailable for custom, bitstring and integer populations.

ConstraintTolerance is nonnegative and defaults to 1e-3. Nonlinear feasibility uses that tolerance; linear rows use max(sqrt(eps),ConstraintTolerance), while bound and integer membership are checked directly. The reported maximum violation remains the physical residual, not a tolerance-subtracted value. Linear/integer repair uses the original model and can return a feasible witness rather than the nearest point. An infeasible or unverified proposal is not installed as a feasible chromosome.

Scalar fitness calls receive one 1-by-nvars row, or one selected custom row. UseVectorized=true passes an M-row population and requires M double measurements, including when M is one. Nonlcon returns c<=0 and ceq=0 with one row per evaluated member in vectorized mode. The number of constraints must remain fixed. FunValCheck='on' rejects undefined supplied or measured fitness; with 'off', complex/nonfinite measurements remain visible but cannot win a finite-real comparison. Exceptions, malformed carriers and cancellation are errors, not undefined fitness.

Callbacks bind through the invocation's selected program and retain that executable definition across repeated calls. Direct SDK calls need an execution context with a selected-program producer; a standalone context cannot resolve these callbacks. Active operator and observer options bind when the search starts and rebind only after an explicit accepted optchanged transition. Constructing an options structure does not bind callbacks to the ambient registry. Parallel eligibility and worker resources are checked independently.

Population and reproduction controls

PopulationSize defaults to 50 for nvars<=5, otherwise 200; mixed-integer defaults to min(max(10*nvars,40),100). A positive count vector creates RunMat subpopulations inside one retained population. EliteCount defaults to ceil(0.05*subpopulationSize) and cannot exceed a group. CrossoverFraction is in [0,1], default 0.8; the remaining nonelite rows are mutation children. Each complete transition owns all offspring before replacing the preceding generation.

InitialPopulationMatrix supplies a prefix with exactly nvars columns and at most PopulationSize rows. InitialScoresMatrix supplies up to PopulationSize raw scores; missing scores are measured. Scores are reused only for the exact coordinates to which they belong. A repair that changes an initial row invalidates only that row's score. For numerical nonlinear problems InitialScoresMatrix is inactive. InitialPopulationRange has two rows and one or nvars columns. Defaults are [-10;10], or [-9999;10001] for integer problems, adjusted to finite/one-sided bounds.

CreationFcn selects gacreationuniform, gacreationlinearfeasible, gacreationnonlinearfeasible, gacreationuniformint, gacreationsobol or a custom callable. Missing rows are filled and then admitted to the original domain. Uniform integer creation samples uniformly among representable integer-valued binary64 coordinates in the selected finite working interval. Sobol creation uses the bundled Joe-Kuo direction tables up to their 21201-dimensional limit and fails at its actual sequence/dimension frontier instead of substituting random draws.

FitnessScalingFcn is fitscalingrank, fitscalingprop, fitscalingtop, fitscalingshiftlinear or custom. SelectionFcn is selectionstochunif, selectiontournament, selectionremainder, selectionuniform, selectionroulette or custom. Tournament size defaults to four, or two for nonlinear problems. Nonlinear penalty mode uses its two-player tournament rule. Scaling expectations allocate parent selection weight; they do not become raw fval.

CrossoverFcn selects crossoverscattered, crossoversinglepoint, crossovertwopoint, crossoverintermediate, crossoverlaplace, crossoverheuristic, crossoverarithmetic or custom. MutationFcn selects mutationgaussian, mutationuniform, mutationadaptfeasible, mutationpower, mutationpositivebasis or custom. Cells add documented parameters: intermediate/heuristic ratio; Gaussian scale/shrink; uniform rate; tournament size; top fraction; shift-linear rate. RunMat uses centered unit-scale Laplace crossover and U^2 power mutation. These distribution parameters specify RunMat's numerical policy, not a proprietary random trajectory.

Named operators call their numerical implementation; function handles remain ordinary semantic callbacks. Custom creation receives (nvars,problem,options); crossover receives (parents,options,nvars,problem,scores,population); mutation receives (parents,options,nvars,problem,state,scores,population). problem.FitnessFcn is the objective and problem.options is empty because options is separate. Parent indices are one-based. Extra custom cell arguments follow these parameters. Numeric operator results must have the requested rows and nvars columns; custom results must preserve the selected representation's row count.

MigrationDirection is forward or both, MigrationFraction is in [0,1] (default 0.2), and MigrationInterval is positive (default 20). Migration simultaneously moves pre-migration source rows and their fitness/constraint observations into destination groups. It makes no extra objective calls. This population grouping is distinct from callback worker parallelism.

Nonlinear modes and stopping

NonlinearConstraintAlgorithm is auglag by default, or penalty; integer problems use penalty. Penalty fitness uses physical feasibility, raw fitness for feasible rows and the worst feasible raw value plus constraint violation for infeasible rows. Infeasible penalty rows can skip the objective and carry a constraint-rejected sentinel rather than a fabricated measurement. Once a row becomes admissible, its missing objective is evaluated.

Auglag evolves fixed-parameter shifted-log-barrier/equality augmented subproblems. Raw fitness, physical feasibility, restoration ordering and augmented selection scores are separate. For continuous nonlinear auglag only, InitialPenalty is finite and >=1 (default 10), and PenaltyFactor is finite and >1 (default 100); these controls are inactive for linear problems and penalty mode, including integer problems. Multipliers update only after a solved subproblem meets the physical update conditions; otherwise the penalty increases. Unrepresentable merit updates stop with -9. RunMat bounds an inexact inner epoch by 100*nvars steps; exhaustion is unsolved and cannot justify a convergence flag or multiplier update.

MaxGenerations defaults to 100*nvars; zero performs only initialization. For auglag it counts completed subproblems, not interrupt steps. MaxStallGenerations defaults to 50 and applies inside a fixed subproblem; FunctionTolerance is nonnegative, default 1e-6. StallTest is averageChange or geometricWeighted. RunMat's geometric weights decay by 1/2. A user-supplied selection-score edit invalidates the numerical comparison window rather than creating an observed improvement or solved subproblem.

Exitflag 1 reports the completed relative-change/feasibility test, with a physical/complementarity test for auglag; 3 reports unchanged comparison; 5 reports FitnessLimit at a feasible finite-real observation. Flag 0 is MaxGenerations, -1 an observer stop, -2 no feasible finite-real fitness, -4 MaxStallTime, -5 MaxTime, and -9 an unverified numerical proposal. These are genetic stopping criteria, not certificates of global optimality.

MaxTime defaults to Inf and accepts nonnegative seconds or scalar duration. MaxStallTime defaults to Inf and must be positive. All stages retain one selected timing origin; parameter changes do not reset elapsed time. Limits are checked at cooperative stage/start/generation and worker-wave boundaries, not by aborting an in-flight callback or factorization. A parallel feasibility wave can finish after its parent time threshold; no new starts are then issued. Custom stop/cancellation remain separate mechanisms.

Observers, local hybrid and services

OutputFcn accepts a handle or cell of handles and returns [state,options,optchanged]=f(options,state,flag). PlotFcn accepts a handle/name or cell and returns state=f(options,state,flag). Flags are init,iter,interrupt,done; interrupt occurs during auglag inner steps. Every selected observer runs even if an earlier one sets StopFlag. A nonempty text StopFlag requests a normal observer stop. Interrupt options and optchanged are inactive; done is a final notification, not another search transition.

State includes Generation,StartTime,StopFlag,LastImprovement,LastImprovementTime,Best,FunEval,Expectation,Selection,EvalElites,HaveDuplicates,Population and Score, with mode-specific Fitness/NonlinIneq/NonlinEq. The auglag how field records its most recent infeasible-point, multiplier-update or penalty-increase action. RunMat additionally exposes InnerGeneration and TotalInnerGenerations without changing Generation's outer meaning. GeneticOrigin records each row's creation, variation, migration or observer origin, and GeneticParents gives its one-based previous-generation parent indices (NaN when absent). Score is selection fitness, whereas Fitness is raw fitness in penalty mode. If a callback changes Population it must supply consistent Score and, in penalty mode, Fitness. Changed coordinates are independently checked against the original domain and nonlinear function; user-returned constraint fields are not feasibility evidence.

Mutable options take effect only when optchanged is true. Changes to PopulationType or NonlinearConstraintAlgorithm require a new invocation. A changed population count requires a correspondingly sized returned population/scores. Solver-owned evaluation/generation counters and timing are not writable work records; a modified Best vector is display history, not a convergence proof. EvalElites controls real reevaluation, and HaveDuplicates controls exact-bit duplicate reuse for numeric genomes. Opaque custom genomes have no inferred equality from handle or name identity.

PlotInterval and DisplayInterval are positive, default one. PlotInterval uses Generation for iter events and InnerGeneration for interrupt events; init and done always notify. Display is off/none,final,iter or diagnose; diagnose emits the selected dimension/population/constraint/parallel configuration and progress. Plot callbacks use one exact assigned axes receiver each; custom StopFlag can terminate the search. RunMat does not add MATLAB-specific Pause/Stop widgets. Retired plot receivers are not silently replaced.

HybridFcn is [] or fminsearch,fminunc,fmincon,patternsearch by selected name/handle, optionally paired with options. A nonempty hybrid requires a continuous doubleVector problem; integer, bitstring and custom populations do not support hybrids. Constrained continuous problems require fmincon or patternsearch. The local solver's candidate is checked against the original domain and nonlinear function before it can replace the retained best. Its reported raw fval is not obtained by a hidden final objective replay. The local solver's status and count remain separately reported.

UseParallel is off/auto/on; true maps to auto and false to off. UseVectorized=true takes precedence. Parallel callback waves use the selected executable/source and the adapter's real worker capacity; auto falls back only for known eligibility or unavailable-pool conditions, while on requires a working worker route. Failures after dispatch never replay serially. Nonlinear-feasible creation accepts SolverOpts,UseParallel and NumStartPts; the default runs one local start per missing row. Additional requested starts cycle those rows and retain each row's best observed constraint candidate; fewer starts leave remaining generated rows unchanged. Limits can stop before all requested starts. Feasible creation does not guarantee finding a feasible point.

The original random stream supplies short, non-overlapping draws around user calls. output.rngstate records its starting state; problem.rngstate restores through that same session owner. Clock is needed for elapsed-time controls. Callback, UI, workspace, worker and resource permissions remain with the selected runtime. Finite host-memory policies refuse the full solver before transfers/callbacks because its complete population, arbitrary-callback, exact-feasibility and hybrid workspace is not finitely certified.

RunMat-only numeric extensions admit role-compatible native integers/logicals and singles, converting exactly where required to host double. Native-integer controls have their own extension. Authenticated Automatic device residency may materialize transparently; Explicit or unproven intent must be gathered by the caller. Unused captures, unknown user state and inactive constraints are not recursively gathered. The numerical algorithm is host-based; parallel workers must provide their own required services and original resource leases.

Examples

Return the initial population and its raw fitness

o=optimoptions('ga','Display','off','PopulationSize',3,'InitialPopulationMatrix',[-1;0;2],'MaxGenerations',0);
[x,f,flag,out,pop,scores]=ga(@(x)x(1)^2,1,[],[],[],[],[],[],[],o);

Evolve offspring while preserving a feasible elite

rng(19); o=optimoptions('ga','Display','off','PopulationSize',4,'EliteCount',1,'CrossoverFraction',0,'InitialPopulationMatrix',[-1;0;0.5;1],'MaxGenerations',2);
[x,f,flag,out,pop,scores]=ga(@(x)x(1)^2,1,[],[],[],[],[],[],[],o);

Evaluate an admitted integer population

o=optimoptions('ga','Display','off','PopulationSize',4,'InitialPopulationMatrix',[0;1;2;3],'MaxGenerations',0);
[x,f,flag,out,pop,scores]=ga(@(x)(x(1)-2)^2,1,[],[],[],[],0,3,[],1,o);

Measure one complete vectorized population

o=optimoptions('ga','Display','off','PopulationSize',3,'InitialPopulationMatrix',[-1 1;0 0;1 -1],'UseVectorized',true,'MaxGenerations',0);
[x,f,flag,out,pop,scores]=ga(@(x)sum(x.^2,2),2,[],[],[],[],[],[],[],o);

Using ga with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how ga changes the result.

Run a small ga example, explain the result, then change one input and compare the output.

Related Math functions

Optim

acceptancesa · annealingboltz · annealingfast · coneprog · crossoverarithmetic · crossoverheuristic · crossoverintermediate · crossoverlaplace · crossoverscattered · crossoversinglepoint · crossovertwopoint · eqnproblem · EquationProblem.solve · EquationProblem.subsasgn · EquationProblem.subsref · evaluate · fgoalattain · fitscalingprop · fitscalingrank · fitscalingshiftlinear · fitscalingtop · fminbnd · fmincon · fminimax · fminsearch · fminunc · fseminf · fsolve · fzero · gacreationlinearfeasible · gacreationnonlinearfeasible · gacreationsobol · gacreationuniform · gacreationuniformint · gaplotbestf · gaplotbestindiv · gaplotdistance · gaplotexpectation · gaplotgenealogy · gaplotmaxconstr · gaplotrange · gaplotscorediversity · gaplotscores · gaplotselection · gaplotstopping · integerConstraint · integral · intlinprog · linprog · lsqcurvefit · lsqlin · LsqlinWarmStart.subsasgn · LsqlinWarmStart.subsref · lsqnonlin · lsqnonneg · mutationadaptfeasible · mutationgaussian · mutationpositivebasis · mutationpower · mutationuniform · optimexpr · optimget · OptimizationConstraint.evaluate · OptimizationConstraint.subsasgn · OptimizationConstraint.subsref · OptimizationExitflag.double · OptimizationExitflag.eq · OptimizationExitflag.ne · OptimizationExitflag.string · OptimizationExpression.acos · OptimizationExpression.acosh · OptimizationExpression.acot · OptimizationExpression.acoth · OptimizationExpression.acsc · OptimizationExpression.acsch · OptimizationExpression.asec · OptimizationExpression.asech · OptimizationExpression.asin · OptimizationExpression.asinh · OptimizationExpression.atan · OptimizationExpression.atanh · OptimizationExpression.cat · OptimizationExpression.cos · OptimizationExpression.cosh · OptimizationExpression.cot · OptimizationExpression.coth · OptimizationExpression.csc · OptimizationExpression.csch · OptimizationExpression.ctranspose · OptimizationExpression.cumprod · OptimizationExpression.cumsum · OptimizationExpression.diag · OptimizationExpression.diff · OptimizationExpression.dot · OptimizationExpression.eq · OptimizationExpression.evaluate · OptimizationExpression.exp · OptimizationExpression.ge · OptimizationExpression.horzcat · OptimizationExpression.ldivide · OptimizationExpression.le · OptimizationExpression.log · OptimizationExpression.mean · OptimizationExpression.minus · OptimizationExpression.mldivide · OptimizationExpression.mpower · OptimizationExpression.mrdivide · OptimizationExpression.mtimes · OptimizationExpression.norm · OptimizationExpression.plus · OptimizationExpression.power · OptimizationExpression.prod · OptimizationExpression.rdivide · OptimizationExpression.reshape · OptimizationExpression.sec · OptimizationExpression.sech · OptimizationExpression.sin · OptimizationExpression.sinh · OptimizationExpression.sqrt · OptimizationExpression.subsasgn · OptimizationExpression.subsref · OptimizationExpression.sum · OptimizationExpression.tan · OptimizationExpression.tanh · OptimizationExpression.times · OptimizationExpression.trace · OptimizationExpression.transpose · OptimizationExpression.uminus · OptimizationExpression.uplus · OptimizationExpression.vertcat · OptimizationExpression.zeros · OptimizationExpression.zerosLike · OptimizationProblem.solve · OptimizationProblem.subsasgn · OptimizationProblem.subsref · OptimizationVariable.subsasgn · OptimizationVariable.subsref · optimoptions · optimplotconstrviolation · optimplotfirstorderopt · optimplotfunccount · optimplotfval · optimplotfvalconstr · optimplotmilp · optimplotstepsize · optimplotx · optimproblem · optimset · optimvar · optimwarmstart · particleswarm · patternsearch · psplotbestf · psplotbestx · psplotfuncount · psplotmaxconstr · psplotmeshsize · pswcreationuniform · pswplotbestf · quad · quadprog · QuadprogWarmStart.subsasgn · QuadprogWarmStart.subsref · saplotbestf · saplotbestx · saplotf · saplotstopping · saplottemperature · saplotx · savemilpsolutions · secondordercone · selectionremainder · selectionroulette · selectionstochunif · selectiontournament · selectionuniform · simulannealbnd · solve · surrogateopt · surrogateoptplot · temperatureboltz · temperatureexp · temperaturefast

Elementwise

abs · angle · besselj · bsxfun · complex · conj · double · eps · erf · erfcinv · exp · expm1 · flintmax · gamma · gammaln · heaviside · hypot · imag · int16 · int32 · int64 · int8 · intmax · intmin · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · realmax · realmin · realsqrt · rescale · sign · single · sqrt · times · typecast · uint16 · uint32 · uint64 · uint8

Trigonometry

acos · acosd · acosh · acotd · acscd · asecd · asin · asind · asinh · atan · atan2 · atan2d · atand · atanh · cos · cosd · cosh · cospi · deg2rad · pol2cart · rad2deg · sin · sind · sinh · sinpi · tan · tand · tanh

Reduction

all · any · bounds · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · maxk · mean · median · min · mink · movmax · movmean · movmedian · movmin · movprod · movstd · movsum · movvar · nnz · prod · rms · std · sum · trapz · var

Structure

bandwidth · isdiag · ishermitian · issymmetric · istril · istriu · symrcm

Bitwise

bitand · bitcmp · bitget · bitor · bitset · bitshift · bitxor · swapbytes

Signal

blackman · butter · buttord · cheb2ord · conv · conv2 · deconv · downsample · envelope · filter · filtfilt · fir1 · freqz · gauspuls · hamming · hann · hilbert · periodogram · pulstran · pwelch · rectpuls · resample · sawtooth · sinc · spectrogram · square · tripuls · unwrap · upsample · zplane

Rounding

ceil · fix · floor · mod · rem · round

Factor

chol · decomposition · decomposition.ctranspose · decomposition.mldivide · decomposition.mrdivide · decomposition.mtimes · decomposition.rdivide · decomposition.subsref · decomposition.times · decomposition.uminus · decomposition.uplus · eig · eigs · gmres · ichol · ilu · lu · ordeig · ordqz · ordschur · pcg · qr · qz · rsf2csf · schur · svd

Solve

cond · det · inv · linsolve · norm · null · pinv · rank · rcond · rref · vecnorm

Ops

cross · ctranspose · dot · mldivide · mpower · mrdivide · mtimes · pagemtimes · pagetranspose · trace · transpose

Symbolic

digits · int · limit · piecewise · sym · syms · vpa

Discrete

factor · factorial · gcd · isprime · lcm · primes

Fft

fft · fft2 · fftn · fftshift · ifft · ifft2 · ifftn · ifftshift

Interpolation

griddedInterpolant · griddedInterpolant.subsref · interp1 · interp1q · interp2 · pchip · ppval · spline

Integer Division

idivide

Ode

ode15s · ode23 · ode45 · odeset

Poly

poly · polyder · polyfit · polyint · polyval · roots

Source you can read

Every RunMat function's source is public. Read exactly how ga is executed, line by line, in Rust.

  • View the source for ga in Rust on GitHub
  • Learn how the RunMat runtime works
  • Found a bug? Open an issue with a minimal reproduction.

About RunMat

RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.

Download RunMatOpen Sandbox
On this page
  • Syntax
  • Inputs
  • Returns
  • Errors
  • Calling forms and outputs
  • Representations and constraints
  • Population and reproduction controls
  • Nonlinear modes and stopping
  • Observers, local hybrid and services
  • Examples
  • Return the initial population and its raw fitness
  • Evolve offspring while preserving a feasible elite
  • Evaluate an admitted integer population
  • Measure one complete vectorized population
  • Using ga with coding agents
  • Related Math functions
  • Optim
  • Elementwise
  • Trigonometry
  • Reduction
  • Structure
  • Bitwise
  • Signal
  • Rounding
  • Factor
  • Solve
  • Ops
  • Symbolic
  • Discrete
  • Fft
  • Interpolation
  • Integer Division
  • Ode
  • Poly
  • Source you can read
  • About RunMat