Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please do both short question and write matlab code. Q2: [25pts] Write a MATLAB

ID: 2266160 • Letter: P

Question

Please do both short question and write matlab code.

Q2: [25pts] Write a MATLAB function that takes inputs x and y coordinates of a point and determines the quadrant e I I or IV) that point belongs to. You are expected to display your results by using fprintf. For example, the point, P, has coordinates of (3,5) is in the first quadrant (I). A sample output message is given as: "P (3.00,5.00) is the Quadrant-I". Please make sure that if any of the r orycoordinatevalueisO then return the following message: V-aris 1o P(3,5) 10- 10 P (XX, YY) is not in any of the quadrants". In this message, XX and YY are the x andy coordinates, respectively. Test your function for these inputs (0, 0) -s IV -5.67). (3.45.-5.43), (3.45.0), (0.0.45), a 00. Q3: [25pts] Write a MATLAB program in a script file that asks the user to input a vector of arbitrary length. the number of even positive and negative elements. The program should display the results in sentence form, i.e., "The vector has xx element (s) Xx element (s) is/are positive and XX element (s) is/are negative. Positive XX and negative xx element (s) are even.", where XX stands for the corresponding number of elements. Please try your code for the following

Explanation / Answer

Q2. quadrant.m

x = input('Enter the value for x co-ordinate:'); % Get x coordinate value
y = input('Enter the value for y co-ordinate:'); % Get y coordinate value

if (x==0 && y==0) % condition for in origin
fprintf('P(%.2f,%.2f) is origin ',x,y);
else
if (x==0 || y==0) % condition for not in any coordinate
fprintf('P(%.2f,%.2f) is not in any the quadrants ',x,y);
else
if (x>0 && y>0) % Condition for Quardrant-I
fprintf('P(%.2f,%.2f) is in the first Quadrant(I) ',x,y);
else
if (x<0 && y>0) % Condition for Quardrant-II
fprintf('P(%.2f,%.2f) is in the second Quadrant(II) ',x,y);
else
if (x<0 && y<0) % Condition for Quardrant-III
fprintf('P(%.2f,%.2f) is in the third Quseadrant(III) ',x,y);
else
if (x>0 && y<0) % Condition for Quardrant-IV
fprintf('P(%.2f,%.2f) is in the fourth Quadrant(IV) ',x,y);   
end
end
end
end
end
end

Output

Enter the value for x co-ordinate:3
Enter the value for y co-ordinate:5
P(3.00,5.00) is in the first Quadrant(I)

Enter the value for x co-ordinate:-3
Enter the value for y co-ordinate:5.67
P(-3.00,5.67) is in the second Quadrant(II)

Enter the value for x co-ordinate:-3
Enter the value for y co-ordinate:-5.67

P(-3.00,-5.67) is in the third Quseadrant(III)

Enter the value for x co-ordinate:3.45
Enter the value for y co-ordinate:0
P(3.45,0.00) is not in any the quadrants

Enter the value for x co-ordinate:0

Enter the value for y co-ordinate:0.45
P(0.00,0.45) is not in any the quadrants

Enter the value for x co-ordinate:0
Enter the value for y co-ordinate:0
P(0.00,0.00) is origin

Q3. vectorcount.m

lear; %clear memory

clc; % clear command window

v=size(100);

n=input('Enter the number of Element:');

fprintf('Enter the Element of Vector: ');

for i=1:1:n

v(i) = input('Enter a value :');

end

% Initialize counter

Pcount = 0;

Ncount = 0;

PEcount= 0;

NEcount= 0;

for i=1:1:n

if v(i) < 0 % condition for negative number

Ncount=Ncount+1;

if (mod(v(i),2) == 0) % condition for even value

NEcount = NEcount + 1;

end

else   

%Positive number count

Pcount=Pcount+1;

if (mod(v(i),2) == 0)

PEcount = PEcount + 1;

end

end   

end

fprintf(' The vector has %d element(s): ',n);

%if Pcount == 1

% fprintf('%d element is positive ',Pcount);

%else

% fprintf('%d elements are positive ',Pcount);

%end

%if Ncount == 1

% fprintf('%d element is negative ',Ncount);

%else

% fprintf('%d elements are negative ',Ncount);

%end

fprintf('%d element(s) is/are positive ',Pcount);

fprintf('%d element(s) is/are negative ',Ncount);

fprintf('Positive %d and Negative %d element(s) are even ',PEcount,NEcount);

output

Enter the number of Element:6

Enter the Element of Vector:

Enter a value :1

Enter a value :3

Enter a value :4

Enter a value :-5

Enter a value :-6

Enter a value :-7

The vector has 6 element(s):

3 element(s) is/are positive

3 element(s) is/are negative

Positive 1 and Negative 1 element(s) are even