Definiing two functions (mathematica)

  1. Feb 25, 2012 #1
    I need to define two functions for a molecule with speed s.
    a)it has a horizontal velocity between -s and s
    b) v , the vertical velocity between +Sqrt[s^2-u^2] and -Sqrt[s^2-u^2]

    This is what I have done
    for a)
    Code (Text):
    for b)
    Code (Text):
    now , If I enter f[2] I get u, so I have s and u from first code. How do I use these values in the second code (without manually inputting them)?

    Thanks a bunch
  2. jcsd
  3. Feb 25, 2012 #2
    You mean just

    g[s,f] ?
  4. Feb 25, 2012 #3

    Yes ,thats what I want ..But how do I put into mathematica ?

    If just insert what you have written I get

    RandomReal::unifr: "The endpoints specified the uniform distribution range are not real valued

    I also Tried,

    Code (Text):
    g[s_] := RandomReal[{-Sqrt[s^2 - f[s]^2], +Sqrt[s^2 - f[s]^2]}]
    However , what it does in this case is , finds f for -Sqrt[s^2 - f^2] and +Sqrt[s^2 - f^2] seperately , so I get different f in that case..

    Any ideas?
  5. Feb 25, 2012 #4
    I believe that's because the arguments to RandomReal have to be real. But for example if I entered:


    the argument passed to Sqrt results in a complex number. Either need to make sure s^2-u^2 is real or either use RandomComplex.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?