How can I make 1 by length x array of random numbers from -pi to pi ??
Ältere Kommentare anzeigen
How can I make 1 by length x array of random numbers from -pi to pi ??
Akzeptierte Antwort
Weitere Antworten (1)
M.MUSBA Elhadid
am 31 Okt. 2021
Bearbeitet: M.MUSBA Elhadid
am 31 Okt. 2021
0 Stimmen
x = ones(1,100); a = [rand(1,length(x))-0.5]+linspace(-pi+0.5,pi-0.5,length(x));
2 Kommentare
John D'Errico
am 1 Nov. 2021
Bearbeitet: John D'Errico
am 1 Nov. 2021
I'm sorry, but do you realize this solution does not generate uniformly distributed random numbers? Worse, it requires far more effort than the true solution.
Does it work? Is it even remotely close? Perhaps they only way to prove it is to do a large simulation.
a = zeros(1000,100);
for i = 1:1000
x = ones(1,100); a(i,:) = [rand(1,length(x))-0.5]+linspace(-pi+0.5,pi-0.5,length(x));
end
hist(a(:),1000)
Does that look even remotely uniformly distributed? See the answer by Jan for a far better solution. And even worse, you are trying to do what is surely someone's homework assignment. We do not do homework assignments for students on this site.
M.MUSBA Elhadid
am 1 Nov. 2021
thank you for the advice. I will check next times.
Kategorien
Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
