Info
This question is closed. Reopen it to edit or answer.
Hi, I am doing an assignment and need some help. How can I do vertical part lines (from ex. y=1 to y=3x+2), for x=1:1:10). Also, I do not know how to calculate the distance of such part-lines. How can I do this?
1 view (last 30 days)
Show older comments
x=[1 2 3 4 5 6 7 8 9 10];
y=[17 7 15 13 17 34 35 30 46 31];
%% generating scatter plot for the above data sets
scatter(x,y)
title('Linear Regression Graph, (R=0.8264)');
ylabel('y-axis')
xlabel('x-axis')
hold on
X=[0 10];
Y= 3.37576*X + 5.93333;
plot(X,Y)
hold on
***(here is where I need help)***
for i=1:length(x)
%%xline(i);
plot([x(i) x(i)],[y(i) y(3.37576*i + 5.93333)])
(The line must touch the scatter points and touch the closest point on the line Y= 3.37576*X + 5.93333)
end
0 Comments
Answers (2)
Shubhankar Poundrik
on 9 Jun 2020
Hi Gabriel,
I understand that you need to find the minimum distance between two line segments. I am assuming that by part lines you mean line segments. The following steps will work:
Let this required distance be d.
For all the end points of the line segments (2 for each line segment, 4 total) find the distance to the other line segment. Let's call them d1,d2,d3 and d4.
To find these, for each end point (pi), find the distance between that point and the line of which the other line segment is a part (and let it be di) , and also the point at which the tangent from the point intersects the line. If the point of intersection is not on the line segment (does not meet constraints) then find the minimum of the distances between the point and the 2 end points of the other line segment and let it be di.
Then, d = min{d1,d2,d3,d4}
Regards,
Shubhankar
0 Comments
darova
on 13 Jun 2020
here is a start
solve system of equations to find (coordinates of lines intersection)
0 Comments
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!