Search code examples
matlabtransformationsymbolic-math

Convert symbolic Cartesian coordinates to spherical


Is there any way to do a symbolic transformation from Cartesian to spherical. I could do:

x = r * sin(theta)*cos(phi)

And so on, and then plug into an expression of x,y and z. Is there any easier command to do this?


Solution

  • I'm not sure if cart2sph can do the conversion on symbolic objects, but its documentation has the mapping conveniently spelled out for you:

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

    I think you'll have to resort to this explicit transformation.