Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8860945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:22:47+00:00 2026-06-14T15:22:47+00:00

My function called DicePlot, simulates rolling 10 dice 5000 times. In the function, it

  • 0

My function called DicePlot, simulates rolling 10 dice 5000 times. In the function, it calculates the sum of values of the 10 dice of each roll, which will be a 1 × 5000 vector, and plot relative frequency histogram with edges of bins being selected in the same manner where each bin in the histogram should represent a possible value of for the sum of the dice.

The mean and standard deviation are computed of the 1 × 5000 sums of dice values and the probability density function of normal distribution (with the mean and standard deviation that is computed) on top of the relative frequency histogram is plotted.

I have everything done, but i’m confused on how to plot the probability density function. any help is appreciated. thanks!

for reference the graph is supposed to look like!enter image description here

function DicePlot ( throw_num, die_num )

throw_num=5000
die_num= 10

  throws = rand ( throw_num, die_num );

  throws = ceil ( 6 * throws );

  for i = die_num : die_num*6
    j = find ( score == i );
    y(i-die_num+1) = length ( j ) / throw_num;
  end 

  bar ( x, y )

  xlabel ( 'Score' )
  ylabel ( 'Estimated Probability' )


  score_ave = sum ( score(1:throw_num) ) / throw_num;
  score_var = var ( score );



  return
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:22:49+00:00Added an answer on June 14, 2026 at 3:22 pm

    I’ve added to the code from my answer to your previous question to plot a scaled Gaussian pdf over the top of your histogram. The two key additions are as follows: 1) Use hold on and hold off to get the histogram and plot on the same figure. 2) Scale the output of normpdf to the appropriate size so it is on the same scale as the histogram.

    One other thing, I can’t help but notice you haven’t incorporated the suggestions from my previous answer into your function yet. Any particular reason for this? I certainly will not +1 your question unless I can see evidence that you’ve incorporated the suggestions you’ve had in the past into your work! And now you’ve gone and made me sound like one of my high-school teachers! 🙂

    %#Define the parameters
    NumDice = 2;
    NumFace = 6;
    NumRoll = 500;
    
    %#Generate the rolls and obtain the sum of the rolls
    AllRoll = randi(NumFace, NumRoll, NumDice);
    SumRoll = sum(AllRoll, 2);
    
    %#Determine the bins for the histogram
    Bins = (NumDice:NumFace * NumDice)';
    
    %#Build the histogram
    hist(SumRoll, Bins);
    title(sprintf('Histogram generated from %d rolls of %d %d-sided dice', NumRoll, NumDice, NumFace));
    xlabel(sprintf('Sum of %d dice', NumDice));
    ylabel('Count');
    hold on
    
    %#Obtain the mean and standard deviation of the data
    Mu = mean(SumRoll);
    Sigma = sqrt(var(SumRoll));
    
    %#Obtain the Gaussian function using 4 standard deviations on either side of Mu
    LB = Mu - 4 * Sigma; UB = Mu + 4 * Sigma;
    Partition = (LB:(UB - LB) / 100:UB)';
    GaussianData = normpdf(Partition, Mu, Sigma);
    
    %#Scale the Gaussian data so the size matches that of the histogram
    GaussianData = NumRoll * GaussianData;
    
    %Plot the Gaussian data
    plot(Partition, GaussianData, '-r');
    hold off
    

    ps, if you didn’t know a priori that the histogram should be Gaussian (because of a central limit theorem), then you could also use ksdensity from the statistics toolbox to get the empirical density using a kernel function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function called bodyStyle() which accepts 5 values: bodyStyle(textCol, backCol, heading1Col, headingsCol,
My function called RollDice simulates the rolling of a given number of six sided
I have a function called: showModal(data); which when called, will create a modal with
I have a function called PreProcessSource, which allocates a boost::wave::context and does some preprocessing;
Heres my custom function called doIt which as im sure you can see simply
I have a function called listelements() , which outputs text like <li>text1</li><li>text2</li> . I
I have a function called processXML on the timeline (yes, I know now...) which
I have a function called GetIP which I call on startup and when the
I have a function called show which shows a dialog with the message. I
I have a jQuery function called bindServingSizes which I call like this $(servingsizes).bindServingSizes(ingredientid); Where

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.