フィルターのクリア

can anyone help me ...Write a MATLAB m-file function (dice.m) which simulates one or more dice with each die giving values from 1 to 6

2 ビュー (過去 30 日間)
The program takes a single argument which is the number of dice.
The output should contain the values of the dice and also the probability for this combination of dice to occur. The probability is expressed as a decimal value between 0 and 1 with five decimal points
  1 件のコメント
James Tursa
James Tursa 2016 年 12 月 21 日
What have you done so far? Please post your code and ask specific questions about it. Then we can offer suggestions and corrections.

サインインしてコメントする。

回答 (1 件)

Antonio Aguirre
Antonio Aguirre 2016 年 12 月 21 日
編集済み: Walter Roberson 2016 年 12 月 21 日
function [prob varargout] = diceSim(numDice)
% Generates random numbers from 1 to 6
% Store them in a matrix of size [numDice,1]
diceVal = randi(6,numDice,1);
% Determines the probabilty of rolling a particular combo, for a six
% sided die an individual probability is (1/6), thus having 'n' number
% of independent probability die then for 'n' number of die the
% combined probability is simply (1/6)^n
prob = (1/6)^numDice;
% Pre-allocates a cell for the variable sized output argument
% 'varargout', just for speed
varargout = cell(numDice,1);
% Loop over all the dice values and set the value for each dice into
% the output cell
for i=1:numDice
varargout{i} = diceVal(i,1);
end
% Example use of this in a main.m file would be
% numDice = 3;
% [prob d1 d2 d3] = diceSim(numDice);
end

カテゴリ

Help Center および File ExchangeAdding custom doc についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by