63 097
Assignments Done
99%
Successfully Done
In July 2018

Answer to Question #62024 in MatLAB | Mathematica | MathCAD | Maple for Linda

Question #62024
Distance between two points (x1, y1) and (x2, y2) is defined by:
distance = sqrt((x1-x2)^2+(y1-y2)^2)
Write a matlab function computeDistance that computes the distance between two points, with the
following signature.
function d = computeDistance(p1, p2)
Inputs:
p1 - coordinates of the first point as a vector with coordinates [x1 y1]
p2 - coordinates of the second point as a vector with coordinates [x2 y2]
Output:
d - the distance between the two points

Expert's answer
function d = computeDistance(p1, p2)
d = sqrt((p1(1)-p2(1))^2+(p1(2)-p2(2))^2);

Apply function:
computeDistance([1 1],[0 0])

ans =
1.4142

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions