数行のコードで苦労します。正しいコード行を見つけてMATLABでの分布を調べるのに苦労する
これはコンテキストです: 公正なコインを1000回投げ、Xを3つの連続したヘッドのパターンが現れる数 回にする実験を考えてみましょう。 のオーバーラップが許されているので、シーケンスがHHHHTT···TTの場合はX = 2となるようにしてください。 Xの確率質量関数を推定し、これを使ってXの平均と分散 を推定します。 ) 見積り。
これはテンプレートであり、追加する必要がある5行のコードとその手順が強調表示されています。
clear all
N=1000; %Number of Die Rolls
nreps=10000;
count=zeros(1,N+1); %count will be a vector of size N+1 such that, for i=0...N, c(i+1)/nreps=P(X=i)
for n=1:nreps
n_3H = 0; %count the number of occurrences of the pattern HHH
***%Add code to toss a coin N times***
for i=3:N
if ***%Add condition that the pattern HHH appears at position (i-2,i-1,i)***
n_3H = n_3H+1;
end
end
***%Add code to increment count(n_3H+1) by 1***
end
RelFreq = count/nreps;
meanX ***%Add code to estimate the mean of X***
varX ***%Add code to estimate the variance of X***
これまでのところ、これは私が持っているものですが、何も返されていないようで、私は何を続けるべきか分かりません。
clear all
N=1000; %Number of Die Rolls
nreps=100;
count=zeros(1,N+1);%count will be a vector of size N+1 such that, for i=0...N, c(i+1)/nreps=P(X=i)
for n=1:nreps
n_3H = 0; %count the number of occurrences of the pattern HHH
flipStates = randi([1, 2], 1, N) %Add code to toss a coin N times
for i=3:N
if strfind(flipStates, [1,1,1])%Add condition that the pattern HHH appears at position (i-2,i-1,i)
n_3H = n_3H+1;
end
end
%Add code to increment count(n_3H+1) by 1
end
RelFreq = count/nreps;
meanX %Add code to estimate the mean of X
varX %Add code to estimate the variance of X
助けてください!なぜなら全体トス系列全体でループして、個別に各サブシーケンスをチェックするの
あなたは、私はXの平均と分散を見つけるために使用する必要がありますどのようなコードの行を知っていますか?そして、私のn_3Hは、私の最初の繰り返しや100回の繰り返しの平均にHHHが現れる回数を表示しますか?ありがとう、私はあなたの最初の提案を試し、n_3Hは現在、実際に有効な答えを与える! –
@PaulDresner関数['mean'](https://es.mathworks.com/help/matlab/ref/mean.html)と[' var'](https://es.mathworks.com/help)を確認してください。 /matlab/ref/var.html) –
どのようなコードを置く必要がありますので、平均を計算するためにn_3Hで複数の回答がありますか? @LuisMendo –