how to plot a method in matlab
情報
この質問は閉じられています。 編集または回答するには再度開いてください。
古いコメントを表示
I'm trying to plot a method i defined for calculating the probability of n people having different birthday which has the following code:
function y = d_birthday( n )
year = 365;
y=1;
for i=0:n-1
y = y*((year-i)/year);
end
end
and in the command line I'm defining a vector variable x to hold values from 1:100
x=1:100;
but when I try to plot my method using x using this statement
plot(x,d_birthday(x))
all my values exhibit the same value, how do I fix it so that each value of x has it own value
0 件のコメント
回答 (1 件)
Roger Stafford
2017 年 2 月 19 日
編集済み: Roger Stafford
2017 年 2 月 19 日
year = 365;
y=ones(year,1);
for i=2:year
y(i) = y(i-1)*((year-i+1)/year);
end
3 件のコメント
raed khader
2017 年 2 月 19 日
編集済み: raed khader
2017 年 2 月 19 日
Roger Stafford
2017 年 2 月 19 日
x = (1:year)';
plot(x,y,'y-')
or
x = 1:100
plot(x,y(1:100),'y-')
The vectors you plot must be of the same size.
Walter Roberson
2017 年 2 月 20 日
Or just plot(y, 'y-') . When the x are 1:length(y) then you can omit the x.
この質問は閉じられています。
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!