1
$\begingroup$

When I plot this function

collisionProb[distA_, velA_, radA_, velP_, radP_] := 
 With[{\[Sigma] = (velA * distA)/(2 * velP), l = radA + radP}, 
  Probability[-l <= x <= l, x \[Distributed] NormalDistribution[0, \[Sigma]]]]

with the command

Plot[collisionProb[10, x, 0.2, 10, 0.1], {x, 0, 11}]

I get this...

enter image description here

which seems strange to me. For example,

collisionProb[10, 1, 0.2, 10, 0.1]

evaluates to 0.451494.

What's wrong with that plot command?

$\endgroup$

1 Answer 1

3
$\begingroup$

You have a collision of variables in that x is used two ways (as the variable in the probability function and as the iterator in the Plot). Variables in Mathematica are global. Plot using:

Plot[collisionProb[10, z, 0.2, 10, 0.1], {z, 0, 11}]
$\endgroup$
1
  • $\begingroup$ The reason for this variable collision is the fact (stated under Details and Options in the documentation), that Plot treats x as a local variable, effectively using Block. Therefore the global x inside Probability becomes the same local x as the second argument of collisionProb. $\endgroup$
    – Karsten7
    Commented Aug 7, 2015 at 23:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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