Write a MATLAB function (line_eq) that takes coordinates of two points as inputs
ID: 3839930 • Letter: W
Question
Write a MATLAB function (line_eq) that takes coordinates of two points as inputs and returns m and b such that y = mx + b represents the equation of the line passing through these points. This function should be able to handle row or column vector entries. [m, b] = line_eq (PA, PB) Write a MATLAB function (line_int) that takes coordinates of four points as inputs and returns the coordinates o intersection of line passing through points 1 and 2 and the line passing through points 3 and 4. This function should be able to handle row or column vector entries. This function can call function line_eq if needed. P = limw_int(P1, P2, P3, P4) Check your function to find the intersection of two lines: Line 1: passing through points (-1, 0) and (3, 6) Line 2: passing through points (-2, 6) and (7, -3)Explanation / Answer
function [m, c] = line_eq(PA, PB)
m = (PB(2) - PA(2)) ./ (PB(1) - PA(1));
c = PA(2) - m.*PA(1);
end
function P = line_int(P1, P2, P3, P4)
[m1 b1] = line_eq(P1, P2);
[m2 b2] = line_eq(P3, P4);
P = [-m1 1 ; -m2 1]^-1 * [b1 ; b2];
end
p1 = [-1; 0];
p2 = [3; 6];
p3 = [-2; 6];
p4 = [7; -3];
line_int(p1,p2,p3,p4)
Output:
ans =
1.0000
3.0000
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.