MATLAB Answers


Using MATLAB, what is the best way to find the integral of a bounded range of a CDF?

Asked by Aaron
on 7 Jun 2013

Using MATLAB, what is the best way to find the integral of a bounded range of a CDF. I've heard of trapz, cumtrapz, etc. but I do not know the best way to proceed for integrating CDFs. Please refer to the following code:

u = 1;
s = 1;
X = random('Normal',u,s,1,10000);
pd = makedist('Normal','mu',u,'sigma',s);
xAxis = min(X):.0001:max(X);
c_pd = cdf(pd,xAxis);
r = icdf(pd,[.3,.6]);

Basically, I am trying to integrate c_pd between the corresponding X values for .3 and .6 (found by using icdf). However, c_pd is a vector and not the actual cdf function. Does anyone have ideas on the best way to find the integral of this regardless of the distribution type (i.e. Normal, Rician, etc.)? Please advise. Thank you.



No products are associated with this question.

1 Answer

Answer by Mike Hosea
on 7 Jun 2013
 Accepted answer

Well, you have the function as well, not just the vector. If I understand you correctly,



Mike Hosea
on 11 Jun 2013

Aaron, are you all set now? Anonymous functions serve two purposes. One is to fix variables in a function definition, and the other is to provide a quick way of defining functions (versus writing a .m file). Here CDF is formally a function of two variables, pd and x, and we want a function of one variable, x. In general, if we have a function of two variables f(x,y), the anonymous function g = @(x)f(x,y) defines a function g(x) based on value of y at the moment that we created g. So g = @(x)cdf(pd,x) creates a function g(x) that is based on the value of pd at the moment we created g. Note that changing pd doesn't change g. You have to re-define g via g = @(x)cdf(pd,x) to pick up the new value of pd. -- Mike

on 12 Jun 2013

Yes, thank you very much. And, I appreciate the clarification on needed to re-define g if pd changes. I would not have known!

on 12 Jun 2013

And thank you to everyone for the help!

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today