Mercurial > octave-nkf
annotate examples/mypow2.c @ 17296:3a9efb68272d ss-3-7-6
snapshot 3.7.6
* configure.ac (OCTAVE_VERSION): Bump to 3.7.6.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 20 Aug 2013 15:17:54 -0400 |
parents | be41c30bcb44 |
children | 224e76250443 |
rev | line source |
---|---|
6593 | 1 #include "mex.h" |
2 | |
3 void | |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
9932
diff
changeset
|
4 mexFunction (int nlhs, mxArray* plhs[], |
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
9932
diff
changeset
|
5 int nrhs, const mxArray* prhs[]) |
6593 | 6 { |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
9932
diff
changeset
|
7 mwSize n; |
6686 | 8 mwIndex i; |
6593 | 9 double *vri, *vro; |
10 | |
11 if (nrhs != 1 || ! mxIsNumeric (prhs[0])) | |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
9932
diff
changeset
|
12 mexErrMsgTxt ("ARG1 must be a matrix"); |
6593 | 13 |
14 n = mxGetNumberOfElements (prhs[0]); | |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
9932
diff
changeset
|
15 plhs[0] = mxCreateNumericArray |
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
9932
diff
changeset
|
16 (mxGetNumberOfDimensions (prhs[0]), mxGetDimensions (prhs[0]), |
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
9932
diff
changeset
|
17 mxGetClassID (prhs[0]), mxIsComplex (prhs[0])); |
6593 | 18 vri = mxGetPr (prhs[0]); |
19 vro = mxGetPr (plhs[0]); | |
20 | |
21 if (mxIsComplex (prhs[0])) | |
22 { | |
23 double *vii, *vio; | |
24 vii = mxGetPi (prhs[0]); | |
25 vio = mxGetPi (plhs[0]); | |
26 | |
27 for (i = 0; i < n; i++) | |
9932
6cb30a539481
untabify files in examples directory
John W. Eaton <jwe@octave.org>
parents:
9053
diff
changeset
|
28 { |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
9932
diff
changeset
|
29 vro[i] = vri[i] * vri[i] - vii[i] * vii[i]; |
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
9932
diff
changeset
|
30 vio[i] = 2 * vri[i] * vii[i]; |
9932
6cb30a539481
untabify files in examples directory
John W. Eaton <jwe@octave.org>
parents:
9053
diff
changeset
|
31 } |
6593 | 32 } |
33 else | |
34 { | |
35 for (i = 0; i < n; i++) | |
16867
be41c30bcb44
Re-write documentation and all examples of dynamically linked functions.
Rik <rik@octave.org>
parents:
9932
diff
changeset
|
36 vro[i] = vri[i] * vri[i]; |
6593 | 37 } |
38 } |