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] *)
  • 7
    $\begingroup$ dist is only defined to take two arguments, so when you give it four it remains undefined. Try dist[{2, 3}, {2, 1}] instead. $\endgroup$ – Chris K Jan 3 at 20:37

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.

  • $\begingroup$ Thanks. Norm worked but my dist still didn't with the braces as above. I copied that exactly from a professor's notes, but maybe he got it wrong. I'll just write my own for practice. BTW, can I include notes with a function that will show up in screen help, as you can in Python? $\endgroup$ – cybervigilante Jan 3 at 20:53
  • $\begingroup$ Found out how to put in comments, but alas, they don't show up in popup help. $\endgroup$ – cybervigilante Jan 3 at 21:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.