how to plot a method in matlab
Información
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
Mostrar comentarios más antiguos
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
Respuestas (1)
Roger Stafford
el 19 de Feb. de 2017
Editada: Roger Stafford
el 19 de Feb. de 2017
year = 365;
y=ones(year,1);
for i=2:year
y(i) = y(i-1)*((year-i+1)/year);
end
3 comentarios
raed khader
el 19 de Feb. de 2017
Editada: raed khader
el 19 de Feb. de 2017
Roger Stafford
el 19 de Feb. de 2017
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
el 20 de Feb. de 2017
Or just plot(y, 'y-') . When the x are 1:length(y) then you can omit the x.
La pregunta está cerrada.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!