Advertisement
JerBear33

Linear Equation Details

Nov 24th, 2021
2,062
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 1.73 KB | None | 0 0
  1. clc
  2. clear
  3.  
  4. % Filename: Rivera13p2
  5. % Jeremy Rivera
  6. % EGR 120-001
  7. % User enters the coordinates of two points that are on a line, program calculates
  8. %      the equation of a line,what type of line it is, and the slope
  9.  
  10. % VARIABLE DECLARATION
  11. %      x1 (real) user input x coordinate of point 1
  12. %      y1 (real) user input y coordinate of point 1
  13. %      x2 (real) user input x coordinate of point 2
  14. %      y2 (real) user input y coordinate of point 2
  15. %      m  (real) slope of the line
  16. %      b  (real) constant of the line
  17. x1=input('Enter x coordinate of point 1: ');
  18. y1=input('Enter y coordinate of point 1: ');
  19. x2=input('Enter x coordinate of point 2: ');
  20. y2=input('Enter y coordinate of point 2: ');
  21. m=(y2-y1)/(x2-x1);
  22. b=y1-m*x1;
  23. if(x1==x2 && y1==y2)
  24. fprintf('Error; same coordinates (%d, %d) cannot be used twice\n',x1,y1);
  25. elseif
  26. fprintf('Your two points (%d, %d) and (%d, %d) form a line\n',x1,y1,x2,y2);
  27. elseif(b>=0)
  28. fprintf('The equation of your line is: y = %.3fx + %.3f\n',m,b);
  29. else
  30. fprintf('The equation of your line is: y = %.3fx %.3f\n',m,b);
  31. end
  32. if(m==0)
  33. fprintf('The equation of your line has a slope of 0\n',m);
  34. elseif(m==Inf)
  35. fprintf('The equation of your line has an undefined slope\n',m);
  36. elseif(m==-Inf)
  37. fprintf('The equation of your line has an undefined slope\n',m);
  38. elseif(m==(y2-y1)/(x2-x1))
  39. fprintf('The equation of your line has a slope of %.3f\n',m);
  40. end
  41. if(x1==x2 && y1==y2)
  42. fprintf('Same coordinates cannot produce a line in the xy-plane\n');
  43. elseif(y1==y2)
  44. fprintf('The equation of your line is horizontal at y = %.3f\n',y1);
  45. elseif(x1==x2)
  46. fprintf('The equation of your line is vertical at x = %.3f\n',x1);
  47. else
  48. fprintf('The equation of your line is not horizontal nor vertical\n');
  49. end
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement