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

Write a MATLAB program to prompt the user to enter a value of x and y correspond

ID: 2323880 • Letter: W

Question

Write a MATLAB program to prompt the user to enter a value of x and y corresponding to the (x, y) coordinates of a point in the Cartesian coordinate system. The program should then display one of the following prompts: The point is on the x-axis The point is on the y-axis The point is in the first quadrant The point is in the second quadrant The point is in the third quadrant The point is in the fourth quadrant. Test the program for all 6 cases. Turn in a printout of the program and a printout showing the 6 test cases. Include plenty of comments in your program.

Explanation / Answer

clear

A = input('Enter x-coordinate: ');

B = Input('Enter y-coordinate: ');

If A==0

'The point is on Y-Axis'
% if the abscissae value is 0, the number lies on the y-axis

                Else

                If B==0
% if the ordinate value is 0, the number lies on the x-axis

                'The point is on X-axis'

                                Else

                                If A>0 & B>0
% If both the x-coordinate (abscissae) and y-coordinate(ordinate) both are positive , it lies in the first quadrant as first quadrant encompasses all the +ve x and y-coordinate values.

                                'The number lies in 1st Quadrant'

                                                Else

                                                If A<0 & B>0
% If the x-coordinate (abscissae) is negative and y-coordinate(ordinate) is positive , it lies in the second quadrant as second quadrant encompasses all the - ve x and +ve y-coordinate values.

                                                'The number lies in 2nd Quadrant'

                                                                Else

                                                                If A<0 & B<0
% If both the x-coordinate (abscissae) and y-coordinate(ordinate) both are negative , it lies in third quadrant as third quadrant encompasses all the –ve x and y-coordinate values.

                                                                'The number lies in 3rd Quadrant'

                                                                                Else

                                                                                If A>0 & B<0
% If the x-coordinate (abscissae) is positive and y-coordinate(ordinate) is negative , it lies in the fourth quadrant as fourth quadrant encompasses all the + ve x and -ve y-coordinate values.

                                                                                'The number lies in 4th Quadrant'

                                                                                                Else

                                                                                                'The number is on Origin'

% if both x and y coordinates have value of 0.

                                                                                End

                                                                End

                                                End

                                End

                End

End

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote