You are here: Symbol Reference > Dew Namespace > Dew.Math Namespace > Classes > TMtxOptimization Class
Dew Math for .NET
ContentsIndexHome
Example

How to solve the optimization problem using TMtxOptimization component?

using Dew.Math; using Dew.Math.Units; namespace Dew.Examples { // define the real function to be minimized private double Banana(TVec pars, TVec consts, params object[] objConsts) { return 100*Math.Pow(pars[1]-Math.Pow(pars[0],2),2)+Math.Pow(1-pars[0],2); } private void Example(TMtxOptimization MtxOptim); { if (MtxOptim != null) { // define two variables and their initial values MtxOptim.VariableParameters.SetIt(false, new double[] {2,-1}); // use BFGS optimization method MtxOptim.OptimizationMethod = TOptMethod.optBFGS; // tolerance for MinValue and gradient calculation // additional note : since we did not define the GradProc, // the internal numerical gradient approximation will be used MtxOptim.Tolerance = 2.0e-6; MtxOptim.GradTolerance = 2.0e-6; // function to be minimized MtxOptim.RealFunction = Banana; // finally, calculate minimum MtxOptim.Recalculate(); } } }
Copyright (c) 1999-2024 by Dew Research. All rights reserved.