How can I find the integral of normpdf(X,1,0) from -inf to inf?

How can I find the integral of normpdf(x,1,0) from -inf to inf?
The followings did not work:
F = @(x)normpdf(x, 0, 1);
Q = quad(F,-Inf,Inf);
---------
syms x;
int('normpdf(x,0,1)',-inf,inf)

Antworten (2)

Wayne King
Wayne King am 4 Jun. 2013
F = @(x)normpdf(x, 0, 1);
Q = integral(F,-Inf,Inf);

5 Kommentare

I got this error: Undefined function or method 'integral' for input arguments of type 'function_handle'.
what version of MATLAB are you using? Probably before integral() was introduced.
You can get 1 without integrating from -Inf to Inf with quad()
Q = quad(F,-1e4,1e4);
7.9.0 R2009b
What is the difference between integral and int?
F = @(x)normpdf(x, 0, 1);
Q = integral(F,-Inf,Inf);
This works nicely, but this:
F = @(x)normpdf(x, 350, 20);
Q = integral(F,-Inf,Inf);
gives
Q = 3.4540e-29
Seems likes it's not very robust.

Melden Sie sich an, um zu kommentieren.

Wayne King
Wayne King am 4 Jun. 2013
Bearbeitet: Wayne King am 4 Jun. 2013

0 Stimmen

integral() was introduced in R2012a. It is used to numerically evaluate an integral, not symbolically and integral() can be unused on unbounded sets like (-Inf,Inf)
Again, in your case you can use quad() far short of (-Inf,Inf) and get 1.

5 Kommentare

Actually i want to find the integral of product of some distributions, for example: normpdf(c,mu_0,sigma_0)*normcdf(c,mu_1,sigma_1)*normcdf(c,mu_2,sigma_2)
Do you think if I use e4 instead of Inf, the error for the answer would be small?
Wayne King
Wayne King am 4 Jun. 2013
Bearbeitet: Wayne King am 4 Jun. 2013
that will depend on the range of the means (the mu parameter) and the sigmas.
You can pretty much assume that for a normal density, the integral over an interval of the mean plus or minus 5 standard deviations will give you a value close to 1. If you're taking a product of several, then where at least one of the densities goes to zero, that will of course make the product very small. Keep that in mind.
Mike Hosea
Mike Hosea am 4 Jun. 2013
Bearbeitet: Mike Hosea am 4 Jun. 2013
Generally it is a bad idea to approximate an improper integral with a large finite interval. The reason is that for an improper integral to converge, it must decay, and if it decays, then over a large interval the integrator will see a function that looks like it is pretty much identically zero, and it may return zero in error. If the decay is rapid enough, it is important not to use an overly-large interval, rather just large enough. A better approach over large intervals is to transform the interval mathematically to a finite interval via substitution and then set the limits close to the finite endpoints. An easier approach is to integrate over shorter finite intervals and add them up.
Thank you all for your replies.
I upgraded my MATLAB to 2013, so now I can use "Integral"
Now I want to find the following integral:
F = @(x)(normpdf(x, 0, 1)*normcdf(x, 0.2, 1.5)*normcdf(x, 0.2, 0.5));
Q = integral(F,-Inf,Inf);
But I get the following error:
Error using *
Inner matrix dimensions must agree.
Do you know what should I do to fix it?
I think I fixed it
F = @(x)normpdf(x, 0, 1)
G= @(x)normcdf(x, 0.2,1.5)
H= @(x)normcdf(x, 0.2,0.5)
Q = integral(@(x)F(x).*G(x).*H(x),-Inf,Inf)

Melden Sie sich an, um zu kommentieren.

Produkte

Gefragt:

may
am 4 Jun. 2013

Kommentiert:

am 17 Mär. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by