Differentiating a cumulative distribution function

조회 수: 5 (최근 30일)
Carter
Carter 2012년 9월 17일
I am trying to numerically evaluate the integral of the normal density function of x with respect to the cumulative distribution of (x+y-m).
I am currently attempting to solve this by trying to integrate the derivative of the cdf times the pdf with respect to x.
Here is my code so far:
k=100;
m=20;
y=0;
syms x;
f=normpdf(x);
g=diff(normcdf(y-x+m);
D=simple(int(f*g,0,(k-m)))
Q=double(D);
E=normcdf(y+2*m-k)-D
Any suggestions? The error message is Error using NaN Trailing string input must be 'single' or 'double'.
Error in normcdf (line 60)
p = NaN(size(z),class(z));

채택된 답변

Tom Lane
Tom Lane 2012년 9월 17일
The Statistics Toolbox functions normpdf and normcdf don't accept symbolic inputs. You might be able to use functions like erf, which do operate on symbolic variables, to accomplish what you want to do. Here's a little example where I compute normcdf on a numeric vector, then I use Symbolic Toolbox functions to get the same result:
>> x = [.5 .7 .9];
>> normcdf(x)
ans =
0.6915 0.7580 0.8159
>> syms s;
>> p = erfc(-s/sqrt(2))/2;
>> double(subs(p,'s',x))
ans =
0.6915 0.7580 0.8159
  댓글 수: 1
Carter
Carter 2012년 9월 27일
Thanks, as I've stated below, this works, however it is through trial and error not the way I am wanting to go about this.

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

추가 답변 (2개)

Carter
Carter 2012년 9월 27일
Thanks! You've really helped me out there. However, I've realized I need to go about this same thing differently. Learning from what you've shown,
syms x mu sigma
f=1/(sigma.*sqrt(2.*pi)).*int(exp(-(x-mu)^2)./(2.*(sigma^2)),-inf,x);
subs(f,{x mu sigma},{3.75 3.75 1}) % Should be equal to below
normcdf(3.75,3.75,1) % normcdf
I however do not get the same answer (should be .5 in this example). What did I do wrong?

Tom Lane
Tom Lane 2012년 9월 27일
You just need to fix your parentheses. Change this
int(exp(-(x-mu)^2)./(2.*(sigma^2))
to this
int(exp(-(1/2)*((x-mu)/sigma)^2)

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by