Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
integrating the symbolic normcdf

Subject: integrating the symbolic normcdf

From: Angie

Date: 25 Jun, 2010 22:24:05

Message: 1 of 6

Hi,

Is there a way to solve the following definite integral? My integrand is symbolic:

myintegrand = @(x) x*normcdf(x,1,0);
int(myintegrand,x,0,1)

Matlab says:
Warning: Explicit integral could not be found.
ans =
int(x*normcdf(x, 1, 0), x = 0..1)

Basically, it does not give me an answer. I also tried "erfc" with no luck.

Thank you,

A.

Subject: integrating the symbolic normcdf

From: Angie

Date: 25 Jun, 2010 23:14:05

Message: 2 of 6

"Angie" wrote in message <i03aa5$t52$1@fred.mathworks.com>...
> Hi,
>
> Is there a way to solve the following definite integral? My integrand is symbolic:
>
> myintegrand = @(x) x*normcdf(x,1,0);
> int(myintegrand,x,0,1)
>
> Matlab says:
> Warning: Explicit integral could not be found.
> ans =
> int(x*normcdf(x, 1, 0), x = 0..1)
>
> Basically, it does not give me an answer. I also tried "erfc" with no luck.
>
> Thank you,
>
> A.

First: In the above post, I should have normcdf(x,0,1) not normcdf(x,1,0)

Second: I tried this approach in another post, yet I am not sure if this is correct. Can anyone tell me if this is correct?

fun1 = @(x) x;
fun2 = @(x) normcdf(x,0,1);
myintegrand = @(x) fun1(x).*fun2(x);
quad(myintegrand,0,1)

ans =
    0.3710

Subject: integrating the symbolic normcdf

From: Roger Stafford

Date: 26 Jun, 2010 00:19:07

Message: 3 of 6

"Angie" <angie11tr@yahoo.com> wrote in message <i03d7t$3tu$1@fred.mathworks.com>...
> First: In the above post, I should have normcdf(x,0,1) not normcdf(x,1,0)
>
> Second: I tried this approach in another post, yet I am not sure if this is correct. Can anyone tell me if this is correct?
>
> fun1 = @(x) x;
> fun2 = @(x) normcdf(x,0,1);
> myintegrand = @(x) fun1(x).*fun2(x);
> quad(myintegrand,0,1)
>
> ans =
> 0.3710
- - - - - - - - -
 Yes, that agrees with the answer I got using integration by parts with old-fashioned pen and paper, namely:

 1/4 + 1/2/sqrt(2*pi*exp(1)) = 0.370985362

  I would have thought the symbolic toolbox could also solve this.

Roger Stafford

Subject: integrating the symbolic normcdf

From: Angie

Date: 26 Jun, 2010 20:36:05

Message: 4 of 6

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i03h1r$m51$1@fred.mathworks.com>...
> "Angie" wrote in message <i03d7t$3tu$1@fred.mathworks.com>...
> > First: In the above post, I should have normcdf(x,0,1) not normcdf(x,1,0)
> >
> > Second: I tried this approach in another post, yet I am not sure if this is correct. Can anyone tell me if this is correct?
> >
> > fun1 = @(x) x;
> > fun2 = @(x) normcdf(x,0,1);
> > myintegrand = @(x) fun1(x).*fun2(x);
> > quad(myintegrand,0,1)
> >
> > ans =
> > 0.3710
> - - - - - - - - -
> Yes, that agrees with the answer I got using integration by parts with old-fashioned pen and paper, namely:
>
> 1/4 + 1/2/sqrt(2*pi*exp(1)) = 0.370985362
>
> I would have thought the symbolic toolbox could also solve this.
>
> Roger Stafford

Thank you. Yes, I thought symbolic integration could be possible, but it was not. I also checked it using Riemann sum, it seems to be correct. Thanks again for confirming it.

Subject: integrating the symbolic normcdf

From: Roger Stafford

Date: 27 Jun, 2010 01:00:20

Message: 5 of 6

"Angie" <angie11tr@yahoo.com> wrote in message <i05obl$2pf$1@fred.mathworks.com>...
> Thank you. Yes, I thought symbolic integration could be possible, but it was not. I also checked it using Riemann sum, it seems to be correct. Thanks again for confirming it.
- - - - - - - - - - - -
  With a Riemann sum or any of matlab's numerical quadrature routines you can only get an approximate value for your integral. However, as I mentioned earlier, using the integration by parts technique this iterated integral can be reduced to the exact expression

 1/4 + 1/2/sqrt(2*pi*exp(1))

Below is a very brief sketch of the reasoning involved in case it is of interest to you.

  We start with your expression

 int(x*int(k*exp(-y^2/2),'y',-inf,x),'x',0,1)

where k = 1/sqrt(2*pi). Using integration by parts, integrate x which gives x^2/2 and differentiate

 int(k*exp(-y^2/2),'y',-inf,x)

which gives

 k*exp(-x^2/2).

Their product can be written

 (x/2)*(k*x*exp(-x^2/2)),

and next differentiate the x/2 which gives 1/2 and integrate the

 k*x*exp(-x^2/2)

 which gives

 -k*exp(-x^2/2).

After all the smoke clears away and everything possible is simplified, the above exact expression remains. At one point we make use of the fact that

 int(k*exp(-x^2/2),'x',-inf,0) = 1/2

Roger Stafford

Subject: integrating the symbolic normcdf

From: Steven Lord

Date: 28 Jun, 2010 02:39:53

Message: 6 of 6


"Angie" <angie11tr@yahoo.com> wrote in message
news:i03aa5$t52$1@fred.mathworks.com...
> Hi,
>
> Is there a way to solve the following definite integral? My integrand is
> symbolic:
>
> myintegrand = @(x) x*normcdf(x,1,0);
> int(myintegrand,x,0,1)
>
> Matlab says:
> Warning: Explicit integral could not be found. ans =
> int(x*normcdf(x, 1, 0), x = 0..1)
>
> Basically, it does not give me an answer. I also tried "erfc" with no
> luck.

NORMCDF is a function from Statistics Toolbox that's defined for _numeric_
inputs, not symbolic.

Using the expression from the documentation for NORMCDF, you can find the
value of your integral:

syms x t
integralBody = exp(-t^2/2);
symbolicNormcdf = (1/sqrt(2*sym(pi)))*int(integralBody, -Inf, x);
myintegrand = int(x*symbolicNormcdf, 0, 1)

VPA this expression to obtain a numeric representation of the result.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us