Effacer les filtres
Effacer les filtres

converts a point in cartesian to cylindrical and spherical cooridante​s(error:ge​tting same answer in cylindrical & spherical coordinates)

1 vue (au cours des 30 derniers jours)
code:
function [Pcyl Psph] = cart2cylsph(Pcart)
% converts a point in cartesian to cylindrical and spherical cooridantes
% input and output as 3 by 1 vectors
x=Pcart(1);
y = Pcart(2);
z= Pcart(3);
rho= sqrt(x^2+y^2);
r = sqrt(x^2+y^2+z^2);
if x,y > 0
phi = atan(y/x);
elseif x,y < 0
phi = atan(y/x)+pi;
elseif x>0 && y<0
phi = 2*pi-atan(y/x);
else
phi = pi-atan(y/x);
end
if z>0
theta=atan(rho/z);
else
theta= pi - atan(rho/z);
end
Pcyl= [rho phi z]';
Psph = [r theta phi]';
end

Réponse acceptée

dpb
dpb le 31 Jan 2020
if x,y > 0
phi = atan(y/x);
elseif x,y < 0
phi = atan(y/x)+pi;
elseif x>0 && y<0
The if statements are bad syntax for the first two; they must be written in the same manner as the last...
if x>0 & y>0
phi = atan(y/x);
elseif x<0 & y<0
phi = atan(y/x)+pi;
elseif x>0 && y<0
...
I didn't read the rest of the function...

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by