00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "mex.h"
00025
00026 void
00027 mexFunction (int nlhs, mxArray* plhs[], int nrhs,
00028 const mxArray* prhs[])
00029 {
00030 mwIndex i;
00031 mwSize n;
00032 double *vri, *vro;
00033
00034 if (nrhs != 1 || ! mxIsNumeric (prhs[0]))
00035 mexErrMsgTxt ("expects matrix");
00036
00037 n = mxGetNumberOfElements (prhs[0]);
00038 plhs[0] = (mxArray *) mxCreateNumericArray
00039 (mxGetNumberOfDimensions (prhs[0]),
00040 mxGetDimensions (prhs[0]), mxGetClassID (prhs[0]),
00041 mxIsComplex (prhs[0]));
00042 vri = mxGetPr (prhs[0]);
00043 vro = mxGetPr (plhs[0]);
00044
00045 if (mxIsComplex (prhs[0]))
00046 {
00047 double *vii, *vio;
00048 vii = mxGetPi (prhs[0]);
00049 vio = mxGetPi (plhs[0]);
00050
00051 for (i = 0; i < n; i++)
00052 {
00053 vro [i] = vri [i] * vri [i] - vii [i] * vii [i];
00054 vio [i] = 2 * vri [i] * vii [i];
00055 }
00056 }
00057 else
00058 {
00059 for (i = 0; i < n; i++)
00060 vro [i] = vri [i] * vri [i];
00061 }
00062 }