Operators and Keywords

C++ API

# cart2sph.m File Reference

## Functions

endif if ((ismatrix(x)&&ismatrix(y)&&ismatrix(z))&&(size_equal(x, y)||isscalar(x)||isscalar(y))&&(size_equal(x, z)||isscalar(x)||isscalar(z))&&(size_equal(y, z)||isscalar(y)||isscalar(z))) theta
else error ("cart2sph: arguments must be matrices of same size, or scalar")
!assert (t,[0, pi/4, pi/4], eps)
!assert (p,[0, 1, 1]*atan(sqrt(0.5)), eps)
!assert (r,[0, 1, 2]*sqrt(3), eps)
!assert (t,[0, 1, 1]*pi/2, eps)
!assert (p,[0, 1, 1]*pi/4, eps)
!assert (r,[0, 1, 2]*sqrt(2), eps)
!assert (t,[0, 0, 0])
!assert (p,[0, 1, 1]*pi/4)
!assert (r,[0, 1, 2]*sqrt(2))
!assert (t,[0, 1, 1]*pi/4)
!assert (p,[0, 0, 0])

## Variables

function [theta, phi, r]
phi = atan2 (z, sqrt (x .^ 2 + y .^ 2))
r = sqrt (x .^ 2 + y .^ 2 + z .^ 2)
endif endfunction!test !x = [0, 1, 2]
!y = [0, 1, 2]
!z = [0, 1, 2]

## Function Documentation

 !assert ( p )

 !assert ( t , [0, 1, 1] *pi/ 4 )

 !assert ( r , [0, 1, 2] * sqrt2 )

 !assert ( p , [0, 1, 1] *pi/ 4 )

 !assert ( t )

 !assert ( r , [0, 1, 2] * sqrt2, eps )

 !assert ( p , [0, 1, 1] *pi/ 4, eps )

 !assert ( t , [0, 1, 1] *pi/ 2, eps )

 !assert ( r , [0, 1, 2] * sqrt3, eps )

 !assert ( p , [0, 1, 1] * atansqrt(0.5), eps )

 !assert ( t , eps )

 else error ( "cart2sph: arguments must be matrices of same size, or scalar" )

 endif if ( (ismatrix(x)&&ismatrix(y)&&ismatrix(z))&&(size_equal(x, y)||isscalar(x)||isscalar(y))&&(size_equal(x, z)||isscalar(x)||isscalar(z))&&(size_equal(y, z)||isscalar(y)||isscalar(z)) )

## Variable Documentation

 !test !x = [0, 1, 2]

 !y = [0, 1, 2]

 !z = [0, 1, 2]

 function[theta, phi, r]

Initial value:

``` cart2sph (x, y, z)

if (nargin != 3)
print_usage ()
```

 phi = atan2 (z, sqrt (x .^ 2 + y .^ 2))

 r = sqrt (x .^ 2 + y .^ 2 + z .^ 2)