~ubuntu-branches/debian/sid/octave3.0/sid

« back to all changes in this revision

Viewing changes to examples/mypow2.c

  • Committer: Bazaar Package Importer
  • Author(s): Rafael Laboissiere
  • Date: 2007-12-23 16:04:15 UTC
  • Revision ID: james.westby@ubuntu.com-20071223160415-n4gk468dihy22e9v
Tags: upstream-3.0.0
ImportĀ upstreamĀ versionĀ 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
Copyright (C) 2006, 2007 John W. Eaton
 
4
 
 
5
This file is part of Octave.
 
6
 
 
7
Octave is free software; you can redistribute it and/or 
 
8
modify it under the terms of the GNU General Public License 
 
9
as published by the Free Software Foundation; either
 
10
version 3  of the License, or (at your option) any later 
 
11
version.
 
12
 
 
13
Octave is distributed in the hope that it will be useful, 
 
14
but WITHOUT ANY WARRANTY; without even the implied warranty
 
15
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
 
16
See the GNU General Public License for more details.
 
17
 
 
18
You should have received a copy of the GNU General Public 
 
19
License along with Octave; see the file COPYING.  If not,
 
20
see <http://www.gnu.org/licenses/>.
 
21
 
 
22
*/
 
23
 
 
24
#include "mex.h"
 
25
 
 
26
void
 
27
mexFunction (int nlhs, mxArray* plhs[], int nrhs, 
 
28
             const mxArray* prhs[])
 
29
{
 
30
  mwIndex i;
 
31
  mwSize n;
 
32
  double *vri, *vro;
 
33
  
 
34
  if (nrhs != 1 || ! mxIsNumeric (prhs[0]))
 
35
    mexErrMsgTxt ("expects matrix");
 
36
 
 
37
  n = mxGetNumberOfElements (prhs[0]);
 
38
  plhs[0] = (mxArray *) mxCreateNumericArray 
 
39
    (mxGetNumberOfDimensions (prhs[0]),
 
40
     mxGetDimensions (prhs[0]), mxGetClassID (prhs[0]),
 
41
     mxIsComplex (prhs[0]));
 
42
  vri = mxGetPr (prhs[0]);
 
43
  vro = mxGetPr (plhs[0]);
 
44
 
 
45
  if (mxIsComplex (prhs[0]))
 
46
    {
 
47
      double *vii, *vio;
 
48
      vii = mxGetPi (prhs[0]);
 
49
      vio = mxGetPi (plhs[0]);
 
50
 
 
51
      for (i = 0; i < n; i++)
 
52
        {
 
53
          vro [i] = vri [i] * vri [i] - vii [i] * vii [i];
 
54
          vio [i] = 2 * vri [i] * vii [i];
 
55
        }
 
56
    }
 
57
  else
 
58
    {
 
59
      for (i = 0; i < n; i++)
 
60
        vro [i] = vri [i] * vri [i];
 
61
    }
 
62
}