Message Boards Message Boards

0
|
3209 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

Plotting the pressure vs number of particles in a box

Posted 11 years ago
So I believe my code is pretty straight forwards and is working fine, that is everything but the histogram part.  What am I doing wrong?
 numberOfExperiments = 5000;
 
 numberOfParticles = 3;
 
 numberOfLevels = 3;
 
 maximumPressure = numberOfParticles * numberOfLevels^2;
 
 listOfPressures =

  Map[Total[

     Map[#^2 &,

      Map[RandomInteger[{1, numberOfLevels}] &,

       Range[1, numberOfParticles]]]] &, Range[numberOfExperiments]];

histogramPressurePlot =

  Histogram[listOfPressures, {1, 2, 3}, numberOfLevels,
   numberOfParticles , Frame -> True,                        

   FrameLabel -> {"Number of particles \!\(\*SubscriptBox[\(n\), \

\(x\)]\)", "Pressure"},

   PlotRangePadding -> 0,

   PlotLabel ->

    SequenceForm["Number of particles = ", numberOfExperiments],

   PlotRange -> {{0, 100}, Automatic}, ChartStyle -> Orange];
POSTED BY: Megan Vineyard
What is the issue you are seeing in the code? Please let us know so that I know I am properly addressing the issue you want help with.

For now I am assuming you mean the error message about histogram that you get when you run this code. After removing the optional arguments the code for Histogram is:
Histogram[listOfPressures, {1, 2, 3}, numberOfLevels, numberOfParticles]
The error says: "Histogram::nonopt: Options expected (instead of 3) beyond position 3 ..."

What this means is that you have given 4 arguments to Histogram. Histogram takes 3 arguments. Please see the documentation for Histogram under "Details and Options" for information about how hspec and bspec can be used to adjust the bins of the histogram and the heights of the histogram. If you have any questions about this, please let us know how you would like to modify or control the binning and the height of your histogram.
POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract