Question: X = [ 2 , 2 , 0 , - 3 , 0 ] ; Y = [ 0 . 5 , 1 . 1

X =[2,2,0,-3,0];
Y =[0.5,1.15,2,1.25,-1.5];
r = zeros(size(X));
theta = zeros(size(X));
lenX = length(X);
AngFact =180/pi;
for i =1:lenX
if (X(i)>0 && Y(i)>0)
r(i)= sqrt(X(i)^2+ Y(i)^2);
theta(i)= atan(Y(i)/ X(i));
theta(i)= AngFact * theta(i);
elseif (X(i)<0 && Y(i)>0)
r(i)= sqrt(X(i)^2+ Y(i)^2);
theta(i)= atan(Y(i)/ X(i))+ pi;
theta(i)= AngFact * theta(i);
elseif (X(i)<0 && Y(i)<0)
r(i)= sqrt(X(i)^2+ Y(i)^2);
theta(i)= atan(Y(i)/ X(i))- pi;
theta(i)= AngFact * theta(i);
elseif (X(i)<0 && Y(i)==0)
r(i)= sqrt(X(i)^2+ Y(i)^2);
theta(i)= pi;
theta(i)= AngFact * theta(i);
elseif (X(i)==0 && Y(i)>0)
r(i)= sqrt(X(i)^2+ Y(i)^2);
theta(i)= pi/2;
theta(i)= AngFact * theta(i);
elseif (X(i)==0 && Y(i)<0)
r(i)= sqrt(X(i)^2+ Y(i)^2);
theta(i)=-pi/2;
theta(i)= AngFact * theta(i);
else
r(i)=0;
theta(i)=0;
end
end
% Print the Outputs.
disp('The x-coordinate values:');
disp(X);
fprintf('
The y-coordinate values:');
disp(Y);
fprintf('
The r-coordinate values:');
disp(r);
fprintf('
The theta (in degrees) values:');
disp(theta);

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!