Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the XY plane, we start walking from point P1 to point P2 on a straight line,

ID: 2291675 • Letter: I

Question

In the XY plane, we start walking from point P1 to point P2 on a straight line, then go to point Ps and continue our trip until we reach point P. The coordinates of these n points are saved in order in matrix P.Write a MATLAB script to calculate the summation of the length of straight lines connecting these points in order. Therefore the summation L will be the total distance of our trip P,?P, Pn-1-P P is a 2 x n matrix, whose ith column contains x and y for point P. Start with L-0 and then use a for loop to calculate the distance between 2 consecutive points and add it to L. Note that there are n 1 lines between these n points. Inside the loop, find the coordinates of two points of interest in matrix P and then calculate the distance between them using the following simple equation: Check your code for the following matrix P and see if it returns the correct answer (L-16.7823) P [-12315 57 2-11

Explanation / Answer

matlab code for required question and its result on given matrix)

function L=lengthsum(P);
p=P;
for n=1:(length(p)-1)
l(n)=sqrt(((p(1,n+1)-p(1,n))^2)+((p(2,n+1)-p(2,n))^2));
end
L=sum(l);

result)

>> p=[-1 2 3 1 5;5 7 2 -1 1]

p =

-1 2 3 1 5
5 7 2 -1 1

>> lengthsum(p)

ans =

16.7823

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote