Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

How do you store values in an array to use for Standard Devation?

조회 수: 1 (최근 30일)
Richar Aguilar
Richar Aguilar 2013년 4월 25일
마감: MATLAB Answer Bot 2021년 8월 20일
So, I'm taking a computational physics course using the MATLAB software and in one of my assignments I have to approximate pi using a Monte Carlo integration an then get the standard deviation form those values.
My professor said I had to use an array or something so that I can use the standard deviation function of MATLAB. Thing is...I have no idea how to go about doing it. Any ideas? This is my code so far...
function MC_circle = MC_circle(N_points)
count = 0;
r = 1;
for i=1:N_points;
x = rand(1);
y = rand(1);
if (sqrt(x^2 + y^2) < 1);
count = count + 1;
end
end
Pi = (4*count)/(N_points)
  댓글 수: 2
Walter Roberson
Walter Roberson 2013년 4월 26일
You have not set your function return value MC_circle .
The standard deviation of what is to be calculated ? My guess is that you are intended to run this loop a number of times and calculate the standard deviation of all of the various Pi that result. Is that the case?
Richar Aguilar
Richar Aguilar 2013년 4월 26일
Yes, indeed! I want to calculate the standard deviation of all the Pi values that result.

답변 (1개)

Steve
Steve 2013년 4월 26일
function MC_circle = MC_circle(N_points)
count = 0;
r = 1;
for i=1:N_points;
x = rand(1);
y = rand(1);
if (sqrt(x^2 + y^2) < 1);
count = count + 1;
end
end
Pi = (4*count)/(N_points)
We'll you could make x or y an array with x{i} and y{i}.
  댓글 수: 1
Walter Roberson
Walter Roberson 2013년 4월 26일
I doubt the intent is to check the standard deviation of the random numbers.

이 질문은 마감되었습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by