Dew MtxVec NET
TJacobianFunction Type
Summary
Defines procedure for calculating the jacobian matrix.

Unit
Optimization

Declaration
TJacobianFunction = procedure(X,Y: TVec; Jac: TMtx);
Description
Jacobian matrix element (i,j) is defined as partial(f(j))/partial(x(i)).
 See Also 
TVectorFunction 

Example 1

Define the Jacobian for the banana function.
Uses MtxVec, Math387; // Split banana function in two parts procedure BananaFun(x,f: TVec; Const Consts: Array of TSample; Const PConsts: Array of TObject); begin f[0] := 100*Sqr(x[1]-Sqr(x[0])); f[1] := Sqr(1-x[0]); end; // Jacobian is 2x2 matrix procedure BananaJac(x,f: TVec; Jac: TMtx); begin Jac[0,0] := -400*(X[1]-Sqr(X[0]))*X[0]; // partial(f0)/ partial(x0) Jac[0,1] := -2*(1-X[0]); // partial(f1)/ partial(x0) Jac[1,0] := 200*(X[1]-Sqr(X[0])); // partial(f0)/ partial(x1) Jac[1,1] := 0.0; // partial(f1)/ partial(x1) end;
#include "MtxVecCpp.h" //MtxVecCPP.cpp must be included in the project #include "Math387.hpp" void __fastcall VecFun(TVec* x, TVec* f, const double* c, conts int c_count, System::TObject* const* o, const int o_count); { double* X = x->PValues(0); double* F = f->PValues(0); F[0] = 100.0*IntPower(X[1]-IntPower(X[0],2),2); F[1] = IntPower(1.0-X[0],2); } // Jacobian is 2x2 matrix void __fastcall BananaJac(TVec* x,TVec* y, TMtx* Jac); begin double* X = x->PValues(0); Jac->Values[0,0] = -400*(X[1]-IntPower(X[0],2))*x[0]; // partial(f0)/ partial(x0) Jac->Values[0,1] = -2*(1-X[0]); // partial(f1)/ partial(x0) Jac->Values[1,0] = 200*(X[1]-IntPower(X[0],2)); // partial(f0)/ partial(x1) Jac->Values[1,1] = 0.0; // partial(f1)/ partial(x1) end;
// Split banana function in two parts private void BananaFun(TVec x, TVec f,double[] c, object[] o); { f[0] = 100*Math387.IntPower(x[1]-Math387.IntPower(x[0],2),2); f[1] = Math387.IntPower(1-x[0],2); } // Jacobian is 2x2 matrix private void BananaJac(TVec x, TVec f, TMtx Jac); { Jac[0,0] = -400*(x[1]-Math387.IntPower(x[0],2))*x[0]; // partial(f0)/ partial(x0) Jac[0,1] = -2*(1-x[0]); // partial(f1)/ partial(x0) Jac[1,0] = 200*(x[1]-Math387.IntPower(x[0],2)); // partial(f0)/ partial(x1) Jac[1,1] = 0.0; // partial(f1)/ partial(x1) }

Copyright 2008 Dew Research
http://www.dewresearch.com