simulating rolling 1 and 2 dice
I need to simulate rolling one dice 10 and 1000 times, and two dice 10 and 1000 times. I must add together the sums for the two dice. I then need to create a histogram with the PDF and CDF. I used a kernel density estimation to smooth the curves. I want to know if my code can be created into a loop to make things simpler. Here is what I have for the rolling 1 dice:
% Simulate 10 rolls, 1 die
roll_10 = randi([1, 6], 10, 1); %using the 1 because only rolling 1 die
mean_10=mean(roll_10);
std_10=std(roll_10);
figure;
histogram(roll_10)
% Plot the smooth PDF using a kernel density estimation
figure;
subplot(2, 1, 1);
ksdensity(roll_10); % Smooth PDF using kernel density estimation. each data point replaced with a wieghing function to estimate the pdf
title(‘Smooth PDF of Dice Rolls’);
xlabel(‘Dice Face Value’);
ylabel(‘Probability Density’);
xlim([0, 7]); % Limiting x-axis to dice face values
% Plot the smooth CDF using a kernel density estimation
subplot(2, 1, 2);
ksdensity(roll_10, ‘Cumulative’, true); % Smooth CDF
title(‘Smooth CDF of Dice Rolls’);
xlabel(‘Dice Face Value’);
ylabel(‘Cumulative Probability’);
xlim([0, 7]); % Limiting x-axis to dice face valuesI need to simulate rolling one dice 10 and 1000 times, and two dice 10 and 1000 times. I must add together the sums for the two dice. I then need to create a histogram with the PDF and CDF. I used a kernel density estimation to smooth the curves. I want to know if my code can be created into a loop to make things simpler. Here is what I have for the rolling 1 dice:
% Simulate 10 rolls, 1 die
roll_10 = randi([1, 6], 10, 1); %using the 1 because only rolling 1 die
mean_10=mean(roll_10);
std_10=std(roll_10);
figure;
histogram(roll_10)
% Plot the smooth PDF using a kernel density estimation
figure;
subplot(2, 1, 1);
ksdensity(roll_10); % Smooth PDF using kernel density estimation. each data point replaced with a wieghing function to estimate the pdf
title(‘Smooth PDF of Dice Rolls’);
xlabel(‘Dice Face Value’);
ylabel(‘Probability Density’);
xlim([0, 7]); % Limiting x-axis to dice face values
% Plot the smooth CDF using a kernel density estimation
subplot(2, 1, 2);
ksdensity(roll_10, ‘Cumulative’, true); % Smooth CDF
title(‘Smooth CDF of Dice Rolls’);
xlabel(‘Dice Face Value’);
ylabel(‘Cumulative Probability’);
xlim([0, 7]); % Limiting x-axis to dice face values I need to simulate rolling one dice 10 and 1000 times, and two dice 10 and 1000 times. I must add together the sums for the two dice. I then need to create a histogram with the PDF and CDF. I used a kernel density estimation to smooth the curves. I want to know if my code can be created into a loop to make things simpler. Here is what I have for the rolling 1 dice:
% Simulate 10 rolls, 1 die
roll_10 = randi([1, 6], 10, 1); %using the 1 because only rolling 1 die
mean_10=mean(roll_10);
std_10=std(roll_10);
figure;
histogram(roll_10)
% Plot the smooth PDF using a kernel density estimation
figure;
subplot(2, 1, 1);
ksdensity(roll_10); % Smooth PDF using kernel density estimation. each data point replaced with a wieghing function to estimate the pdf
title(‘Smooth PDF of Dice Rolls’);
xlabel(‘Dice Face Value’);
ylabel(‘Probability Density’);
xlim([0, 7]); % Limiting x-axis to dice face values
% Plot the smooth CDF using a kernel density estimation
subplot(2, 1, 2);
ksdensity(roll_10, ‘Cumulative’, true); % Smooth CDF
title(‘Smooth CDF of Dice Rolls’);
xlabel(‘Dice Face Value’);
ylabel(‘Cumulative Probability’);
xlim([0, 7]); % Limiting x-axis to dice face values random, mean, pdf MATLAB Answers — New Questions