Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc
- clear
- % Filename: Rivera13p2
- % Jeremy Rivera
- % EGR 120-001
- % User enters the coordinates of two points that are on a line, program calculates
- % the equation of a line,what type of line it is, and the slope
- % VARIABLE DECLARATION
- % x1 (real) user input x coordinate of point 1
- % y1 (real) user input y coordinate of point 1
- % x2 (real) user input x coordinate of point 2
- % y2 (real) user input y coordinate of point 2
- % m (real) slope of the line
- % b (real) constant of the line
- x1=input('Enter x coordinate of point 1: ');
- y1=input('Enter y coordinate of point 1: ');
- x2=input('Enter x coordinate of point 2: ');
- y2=input('Enter y coordinate of point 2: ');
- m=(y2-y1)/(x2-x1);
- b=y1-m*x1;
- if(x1==x2 && y1==y2)
- fprintf('Error; same coordinates (%d, %d) cannot be used twice\n',x1,y1);
- elseif
- fprintf('Your two points (%d, %d) and (%d, %d) form a line\n',x1,y1,x2,y2);
- elseif(b>=0)
- fprintf('The equation of your line is: y = %.3fx + %.3f\n',m,b);
- else
- fprintf('The equation of your line is: y = %.3fx %.3f\n',m,b);
- end
- if(m==0)
- fprintf('The equation of your line has a slope of 0\n',m);
- elseif(m==Inf)
- fprintf('The equation of your line has an undefined slope\n',m);
- elseif(m==-Inf)
- fprintf('The equation of your line has an undefined slope\n',m);
- elseif(m==(y2-y1)/(x2-x1))
- fprintf('The equation of your line has a slope of %.3f\n',m);
- end
- if(x1==x2 && y1==y2)
- fprintf('Same coordinates cannot produce a line in the xy-plane\n');
- elseif(y1==y2)
- fprintf('The equation of your line is horizontal at y = %.3f\n',y1);
- elseif(x1==x2)
- fprintf('The equation of your line is vertical at x = %.3f\n',x1);
- else
- fprintf('The equation of your line is not horizontal nor vertical\n');
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement