Method on @sym: [theta, phi, r] = cart2sph (x, y, z)
Method on @sym: [theta, phi, r] = cart2sph (C)

Transform symbolic Cartesian coordinates to spherical coordinates.

If called with three inputs x, y, and z, they must be of the same shape or scalar. The shape of the outputs theta, phi, and r matches that of the inputs (except when the input is a scalar).

If called with a single input C, it must be a column vector with 3 entries or a matrix with 3 columns. The column vector or each row of the matrix represents a point in Cartesian coordinates (x, y, z). If input C is a column vector, outputs theta, phi, and r are scalars. Otherwise, the shape of the outputs is a column vector with each row corresponding to that of the input matrix C.

Given a point (x, y, z) in Cartesian coordinates, the corresponding spherical coordinates are:

syms x y z real
[theta, phi, r] = cart2sph (x, y, z)
  ⇒ theta = (sym) atan2(y, x)
    phi = (sym)

           ⎛      _________⎞
           ⎜     ╱  2    2 ⎟
      atan2⎝z, ╲╱  x  + y  ⎠

    r = (sym)
         ______________
        ╱  2    2    2
      ╲╱  x  + y  + z

See also: cart2sph, sph2cart, cart2pol, pol2cart.

Package: symbolic