1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| // En-tête de "MatrixDivide"
#if !defined(_WIN32)
#define dgesv dgesv_
#endif
#include "mex.h"
#include "lapack.h"
// Définition de la fonction mex
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mwSignedIndex *iPivot; /* inputs to DGESV */
mxArray *Awork, *mxPivot, *Bwork;
mwSignedIndex info, dims[2];
mxArray * prhsc0, * prhsc1;
double *A2, *B2;
mwSignedIndex mmw, nmw, pmw;
double * matInv, * vecInv, *resCube;
int nb_nnul,k,l;
prhsc0 = prhs[0];
prhsc1 = prhs[1];
// Définition de la taille de la matrice
nb_nnul = 17;
mmw = nb_nnul+1;
nmw = 1;
pmw = nb_nnul+1;
dims[0] = mmw;
dims[1] = pmw;
// Allocation de la matrice et du vecteur, pour résoudre l'équation :
// matInv*X = vecInv
matInv = (double *) malloc(mmw*pmw*sizeof(double));
vecInv = (double *) malloc(pmw*sizeof(double));
// Remplissage au hasard de la matrice et du vecteur
for (k=0;k<mmw*pmw;k++)
matInv[k] = k+2;
for (k=0;k<pmw;k++)
vecInv[k] = k*k;
// Transformation de ces matrices pour que ça ressemble au fichier "MatrixDivide.c"
mxPivot = mxCreateNumericArray(2, dims, mxINT32_CLASS, mxREAL);
iPivot = (mwSignedIndex*)mxGetData(mxPivot);
Awork = mxCreateDoubleMatrix(mmw, pmw, mxREAL);
A2 = mxGetPr(Awork);
Bwork = mxCreateDoubleMatrix(pmw, nmw, mxREAL);
B2 = mxGetPr(Bwork);
memcpy(A2, matInv, mmw*pmw*mxGetElementSize(prhsc0));
memcpy(B2, vecInv, pmw*nmw*mxGetElementSize(prhsc1));
// Calcul de la solution de l'équation. (Et bug...)
dgesv(&mmw,&nmw,A2,&mmw,iPivot,B2,&pmw,&info);
return;
} |
Partager