沒有什麼神奇的數學操作。這僅僅是利用change-of-basis between cylindrical and Cartesian coordinates。這裏是一個快速和骯髒的執行使用符號變量進行類似的東西:
function vcar = cyl2car(vcyl)
%
% The elements of vcyl are expected to be order [v_r ; v_theta ; v_z] such that
% vcyl = v_r * rhat + v_theta * thetahat + v_z * zhat.
%
% The element of vcar will then be in the order: [v_x ; v_y ; v_z] such that
% vcar = v_x * xhat + v_y * yhat + v_z * zhat.
%
% For symbolic input, the expected symbolic symbols are [r,theta,z] for cylindrical
% and [x,y,z] for Cartesian.
%
% Declarations and change-of-basis
syms x y z r theta xhat yhat zhat rhat thetahat;
rhat = x/sqrt(x^2 + y^2) * xhat + y/sqrt(x^2 + y^2) * yhat;
thetahat = -y/sqrt(x^2 + y^2) * xhat + x/sqrt(x^2 + y^2) * yhat;
% Substitute and simplify
temp = simplify(subs(vcyl,[r,theta],[sqrt(x^2+y^2),atan(y/x)]));
temp = expand(sum(temp .* [rhat ; thetahat ; zhat]));
% Assign
vcar = sym(0)*vcyl;
[c,t] = coeffs(temp,[xhat,yhat,zhat]);
if (length(t)>=1)
vcar(1) = c(1);
end
if (length(t)>=2)
vcar(2) = c(2);
end
if (length(t)>=3)
vcar(3) = c(3);
end
end
它返回從數學類似的表述到:
>> vcyl = [0 ; sym(64)*sym(10^-7)*sym(pi)/(sym(2)*r) ; 0];
>> vcarsym = cyl2car(vcyl)
vcarsym =
-(pi*y)/(312500*(x^2 + y^2))
(pi*x)/(312500*(x^2 + y^2))
0