% This script allows the user to input a coordinate in either
% rectangular, cylindrical, or spherical coordinates and
% retrieve the answer in the other coordinate systems clear % prompt the user for the coordinate system dsp('Enter the coordinate system of the input coordinate'); coord_sys = input(' (r, c, or s)... \n > ','s'); % if user entered something other than "r" "c" or "s" if isempty(coord_sys); coord_sys = 'r'; end if corrd_sys == 'r'; % prompt6 the user for the coordinate disp('Enter the rectangular coordinate in the'); crd = input('format [x y z]... \n > '); % check inp�t to see if empty and set to 0 if so if isempty(crd); crd = [0 0 0]; end disp('Cylindrical corrdinates [rho phi(rad) z]:) % display teh result... the [ ] and enclose a % three-dimensional vector disp([sqrt(crd(1)^2+crd(2)^2) atan2(crd(2),crd(1)) crd(3)]) disp('spherical coordinates [r phi(rad) theta(rad]:') disp(norm(crd) atan(crd(2),crd(1)) acos(crd(3)/ norm(crd))]) elseif coord_sys == 'c'; % if not r but c excecute this block disp('enter the Cylindrical coordinate in the format'); crd = input('format \rho \phi(rad) z]... \n > '); % check inp�t to see if empty and set to 0 if so if isempty(crd); crd = [0 0 0]; end disp('Rectangular coordinates [x y z]:') disp([crd(1)*cos(crd(2)) crd(1)*sen(crd(2)) crd(3)]) disp('Spehrical coordinates [ r phi(rad) theta(rad]:') disp([sqrt(crd(1)^2+crd(3)^2) crd(2) crd(3)*cos(crd(3))]) elseif coord_sys == 's'; % if not r nor c but s excecute this block disp('enter the Spherical coordinate in the format'); crd = input('format [\r \phi \theta]... \n > '); % check inp�t to see if empty and set to 0 if so if isempty(crd); crd = [0 0 0]; end disp('Rectangular coordinates [x y z]:') disp([crd(1)*cos(crd(2))*sin(crd(3)) ... crd(1)*sin(crd(2))*cos(crd(3)) crd(1)*cos(crd(3))]) disp('Cylindrical coordinates [r phi(rad) theta(rad]:) disp([crd(1)*sin(crd(3)) crd(2) crd(1)*cos(crd(3))]) end