필터 지우기
필터 지우기

qfunc() division

조회 수: 1 (최근 30일)
Heshani
Heshani 2011년 8월 30일
x = randn(1000000,1);
[fx,xi]=ksdensity(x);
plot(xi,fx);
a1 = qfunc(1.5);
a2= qfunc(2);
P = a2/a1;
a1
a2
P
When I run this code, the values I get for a1 & a2 are exactly the value I get from analysis (a1 = 0.0668 & a2 = 0.0228) . But the division a2/a1 gives 0.3405 in matlab, where as the actual value of division should be 0.3413. Why does this happen?
The above code is solution to question below.
{Use the MATLAB randn function to generate a large number of samples according to a Gaussian distribution. Let A be the event A = {the sample is greater than 1.5}. Of those samples that are members of the event A, what proportion (relative frequency) is greater than 2? By computing this proportion you will have estimated the conditional probability
Pr( X > 2|X > 1. 5).
Calculate the exact conditional probability analytically and compare it with the numerical results obtained through MATLAB. }

채택된 답변

Lucas García
Lucas García 2011년 8월 30일
Notice that you are dividing the outputs from qfunc using only 4 decimal points to verify your analytic result. Actually, MATLAB is showing a short visualization format when you type a1, a2 and P.
If you type format long and show the values for a1 and a2 you will notice that you are getting different results because you are truncating a1 and a2 to 4 decimal points when verifying your results:
0.0228/0.0668 = 0.3413
but actually, the correct result is:
>> P = a2/a1
P =
0.340534126802047
since a1 and a2 have many more decimal places...
  댓글 수: 1
Heshani
Heshani 2011년 9월 10일
Thanks, you made it very clear. :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by