In: Mechanical Engineering
Use MuPAD to find the point on the line y = 2 – x/3 that is closest to the point x = -3, y = 1.
The distance between two points (x1, y1) and (x2, y2) is given by the formula
d = √{(x1, x2)2 + (y1, y2)2}
A co-ordinate on the line can be obtained in terms of y. That point can be used to find the distance between the point on the line and (-3, 1). Finally, the function obtained can be differentiated and solved to find the root and minimum distance.
Now, our line is:
y = 2 – x/3
3y + x – 6 = 0
Therefore, point on the line is (6 – 3y, y).
The distance is
d = √{(6 – 3y + 3)2 + (y – 1)2}
We need to minimize the above function in MATLAB
The MATLAB code is given below:
Input:
syms y
d = (6-3*y+3)^2 + (y-1)^2;
dif = diff(d)
solve(dif)
Output:
Therefore,
y = 14/5
x = 6 – 3y
x = 6 – 42/5 = -2.4
Therefore,
y = 14/5
x = 6 – 3y
x = 6 – 42/5 = -2.4