This should give the answer of 2, but all it does is repeat the input. What is wrong?
dist[P_, Q_] := Sqrt[(P[[1]] - Q[[1]])^2 + (P[[2]] - Q[[2]])^2]
dist[2, 3, 2, 1]
(* Out: dist[2, 3, 2, 1] *)
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityThis should give the answer of 2, but all it does is repeat the input. What is wrong?
dist[P_, Q_] := Sqrt[(P[[1]] - Q[[1]])^2 + (P[[2]] - Q[[2]])^2]
dist[2, 3, 2, 1]
(* Out: dist[2, 3, 2, 1] *)
Please try
Norm[{2, 3} - {2, 1}]
this results in 2.
Please note: Wolfram Language has an enormous amount of prebuild functions which are available.
You can also use
dist[{2, 3}, {2, 1}]
Hope this helps.
dist
is only defined to take two arguments, so when you give it four it remains undefined. Trydist[{2, 3}, {2, 1}]
instead. $\endgroup$ – Chris K Jan 3 at 20:37