Matrix Elements VB-800 Manuel d'utilisateur Page 18

  • Télécharger
  • Ajouter à mon manuel
  • Imprimer
  • Page
    / 172
  • Table des matières
  • MARQUE LIVRES
  • Noté. / 5. Basé sur avis des utilisateurs
Vue de la page 17
10 Appendix A1 Extending Ox
The myFunc function is a wrapper which calls the Ox function:
Space for the arguments and the return value is required. There is always only
one return value: even multiple returns are returned as one array. Here we also
have just one argument for the Ox function, resulting in the OxVALUE rtn and
arg. We mainly work with pointers to OxVALUEs, stored here in prtn and parg
for convenience. The argument is set to a 1×cP matrix. A VECTOR is defined as
a double * and a MATRIX as a double **, so that the type of &vP is MATRIX,
which is always the type used for a matrix in the OxVALUE.
FOxCallBack calls the Ox function in the rst argument. The next three argu-
ments are the arguments to that Ox function: return type, function arguments,
and number of arguments. FOxCallBack returns TRUE when successful, FALSE
otherwise.
After checking the returned value for type OX
DOUBLE, we can extract that double
and return it in what pdFunc points to.
The following Ox code uses the pre-programmed Ox function for the numerical
differentiation, and then the function just written in callback.c.ThedRosenbrock
function is the Ox code which is called from C. The difference between the two here is
that the second expects and returns a row vector.
.............................................ox/dev/windows/callback/callback.ox
#include <oxstd.h>
#import <maximize>
extern "callback,FnNumDer" FnNumDer(const sFunc, vP);
fRosenbrock(const vP, const adFunc, const avScore,
const amHessian)
{
adFunc[0] = -100 * (vP[1] - vP[0] ^ 2) ^ 2
- (1 - vP[0]) ^ 2; // function value
return 1; // 1 indicates success
}
dRosenbrock(const vP)
{
decl f = -100 * (vP[1] - vP[0] ^ 2) ^ 2
- (1 - vP[0]) ^ 2;
return f; // return function value
}
main()
{
decl vp = zeros(2, 1), vscore;
//numerical differentiation using provided Ox function
Num1Derivative(fRosenbrock, vp, &vscore);
print(vscore);
// now using provided C function from DLL
vscore = FnNumDer(dRosenbrock, vp’);// expects row vec
Vue de la page 17
1 2 ... 13 14 15 16 17 18 19 20 21 22 23 ... 171 172

Commentaires sur ces manuels

Pas de commentaire