Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Constants in Mathematica

  1. Jan 26, 2010 #1
    I have a function which depends on several physical constants, which I want to be able to vary each time I make a plot. What is the best way to do this?
  2. jcsd
  3. Jan 26, 2010 #2


    User Avatar
    Homework Helper

    Well, simply define their numerical values, plot the function, and repeat again. If this is what you're trying to do.
  4. Jan 27, 2010 #3
    Is this really the best way? I have at least 8 constants here. I've seen the command
    Plot[f[x] /.{a->1,b->2},{x,0,1}], but this is still annoying for 8 constants. Or defining constants as lists const={a->1,b->2}; but I can't work out how to call them when I plot the function.
  5. Jan 27, 2010 #4


    User Avatar
    Homework Helper

    Hm, I can't think of a more handy way, since in any case you'll have to define these constants explicitly.
  6. Jan 27, 2010 #5
    Can slider bars help?

    Code (Text):

    DynamicModule[{x = Random[]},
       Slider[Dynamic[x], ImageSize -> RandomReal[200]], {10}]]]
  7. Jan 29, 2010 #6


    Staff: Mentor

    I would look at using the "Manipulate" command. It will generate slider bars like Phrak suggested.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook