Matrix Elements VB-800 Instrukcja Użytkownika Strona 48

  • Pobierz
  • Dodaj do moich podręczników
  • Drukuj
  • Strona
    / 172
  • Spis treści
  • BOOKMARKI
  • Oceniono. / 5. Na podstawie oceny klientów
Przeglądanie stron 47
40 Appendix A2 Exported Function Summary
A2.5 Ox exported mathematics functions
A2.5.1 MATRIX and VECTOR types
This section documents the C functions exported from the OxWin DLL to perform
mathematical tasks. With the DLL installed, any C or C
++
function could call these
functions to perform a mathematical task. The primary purpose is, if you, for example,
wish to use some random numbers in your C extension to Ox. It is also possible to just
use these functions without using Ox at all.
To use any of the functions in this section, you need to include both jdtypes.h and
jdmath.h (in this order), e.g.
#include "/ox/dev/jdtypes.h"
#include "/ox/dev/jdmath.h"
Or, if you have set up the information for your compiler such that /ox/dev is in the
include search path:
#include "jdtypes.h"
#include "jdmath.h"
Several types are defined in ox/dev/jdtypes.h, of which the most important are
MATRIX, VECTOR and bool.
The MATRIX type used in this library is a pointer to a column of pointers, each point-
ing to a row of doubles. A VECTOR is just a pointer to an array of doubles. In a MATRIX,
consecutive rows (the VECTORs) do occupy contiguous memory space (although that
would not be strictly necessary in this pointer to array of pointers model). Suppose m is
a 3 by 3 matrix, then the memory layout can be visualized as:
m −→ m[0]
m[0] −→ m[0][0], m[0][1], m[0][2] first row
m[1] −→ m[1][0], m[1][1], m[1][2] second row
m[2] −→ m[2][0], m[2][1], m[2][2] third row
Matrices can be manipulated as follows, using the 3 × 3 matrix m:
m[0] is a VECTOR,therstrowofm;
&m[1] is a MATRIX, the last two rows of m;
&m[1][1] is a VECTOR, the last two elements of the second row.
&(&m[1])[1] is a MATRIX, the last two elements of the second row (this is only
a 1 row matrix, since there is no pointer to the third row).
A MATRIX is allocated by a call to MatAlloc and deallocated with MatFree.Fora
VECTOR the functions are VecAlloc and free, e.g.:
MATRIX m; VECTOR v; int i, j;
m = MatAlloc(3, 3);
v = VecAlloc(3);
if (!m || !v) /* yes: error exit */
Przeglądanie stron 47
1 2 ... 43 44 45 46 47 48 49 50 51 52 53 ... 171 172

Komentarze do niniejszej Instrukcji

Brak uwag