scripts/general/cart2pol.m
| changeset 10289: |
4b124317dc38 |
| parent: | eb63fbe60fab |
| author: |
John W. Eaton <jwe@octave.org> |
| date: |
Tue Feb 09 20:58:55 2010 -0500 (51 minutes ago) |
| permissions: |
-rw-r--r-- |
| description: |
base_properties::set_children: account for hidden children |
1## Copyright (C) 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2009 Kai Habel
3## This file is part of Octave.
5## Octave is free software; you can redistribute it and/or modify it
6## under the terms of the GNU General Public License as published by
7## the Free Software Foundation; either version 3 of the License, or (at
8## your option) any later version.
10## Octave is distributed in the hope that it will be useful, but
11## WITHOUT ANY WARRANTY; without even the implied warranty of
12## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13## General Public License for more details.
15## You should have received a copy of the GNU General Public License
16## along with Octave; see the file COPYING. If not, see
17## <http://www.gnu.org/licenses/>.
20## @deftypefn {Function File} {[@var{theta}, @var{r}] =} cart2pol (@var{x}, @var{y})
21## @deftypefnx {Function File} {[@var{theta}, @var{r}, @var{z}] =} cart2pol (@var{x}, @var{y}, @var{z})
22## Transform Cartesian to polar or cylindrical coordinates.
23## @var{x}, @var{y} (and @var{z}) must be the same shape, or scalar.
24## @var{theta} describes the angle relative to the positive x-axis.
25## @var{r} is the distance to the z-axis (0, 0, z).
26## @seealso{pol2cart, cart2sph, sph2cart}
29## Author: Kai Habel <kai.habel@gmx.de>
32function [theta, r, z] = cart2pol (x, y, z)
34 if (nargin < 2 || nargin > 3)
35 error ("cart2pol: number of arguments must be 2 or 3");
38 if (nargin == 2 && nargout > 2)
39 error ("cart2pol: number of output arguments must not be greater than number of input arguments");
42 if ((ismatrix (x) && ismatrix (y) && (nargin == 2 || ismatrix (z)))
43 && (size_equal (x, y) || isscalar (x) || isscalar (y))
44 && (nargin == 2 || size_equal (x, z) || isscalar (x) || isscalar (z))
45 && (nargin == 2 || size_equal (y, z) || isscalar (y) || isscalar (z)))
48 r = sqrt (x .^ 2 + y .^ 2);
51 error ("cart2pol: arguments must be matrices of same size, or scalar");
59%! [t, r] = cart2pol (x, y);
60%! assert (t, [0, 0, 0]);
66%! [t, r] = cart2pol (x, y);
67%! assert (t, [0, pi/4, pi/4], sqrt(eps));
68%! assert (r, sqrt(2)*[0, 1, 2], sqrt(eps));
74%! [t, r, z2] = cart2pol (x, y, z);
75%! assert (t, [0, pi/4, pi/4], sqrt(eps));
76%! assert (r, sqrt(2)*[0, 1, 2], sqrt(eps));
83%! [t, r, z2] = cart2pol (x, y, z);
84%! assert (t, [0, 0, 0], eps);
92%! [t, r, z2] = cart2pol (x, y, z);
93%! assert (t, [0, 1, 1]*pi/2, eps);
101%! [t, r, z2] = cart2pol (x, y, z);