필터 지우기
필터 지우기

Integral of a product between a function and a Cumulative Normal Distribution

조회 수: 2 (최근 30일)
Hi.
I need to compute an integral of a function that consist in the product between a Cumulative distribution of a Normal, and another term.
I tried using the command int, but in that case I was not able to execute the normcdf command.
Matlab said: CNaux2=normcdf(aux5) Error using NaN Trailing string input must be 'single' or 'double'.
Instead, i tried using the quad command. In that case, the normcdf could be defined as a function handle, but then i coul not excute the quad command. In this case matlab said
Error using * Inner matrix dimensions must agree.
And i don´t understand why, because i don´t have any matrix here, i have only a product of functions of one variable.
Could you please help me?
Thanks! Javier
  댓글 수: 2
Javier
Javier 2013년 3월 27일
What i have to do is to compute a definite integral for the function:
N(a(t))*b(t)*C(d(t)) dt
Where N(a(t)) is a normal probability function valued at the value a, which is in fact a function that depends on t. C(d(t)) is a cumulative normal probability function valued d, which is also a function that depends on t. And b(t) is another function of t.
I have tried to define first the functions a(t) b(t) and c(t) as function handles. Then i used the commandsnormcdf and normpdf to compute the normal cumulative and probability function on this function (i think this way i obtain also a function handle that depends on t, but i am not sure if this is ok. For example, CNaux1 = @(t)normcdf((K*(T-t))/sigma/sqrt(T-t)) )
Later, i define another function handle integrand= N(a(t)).*b(t).*C(d(t)) and i use the quad (integrand, 0, T) (T previously defined)
I thinh i probably made more than one mistake, i am quite a bit lost...
Thank you very much!
Tom Lane
Tom Lane 2013년 3월 27일
This works:
K = 1; T = 1; sigma = 2; f = @(t)normcdf((K*(T-t))/sigma./sqrt(T-t));
quad(f,0,1)
If you tried something else that does not work, you should say what you tried.

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

채택된 답변

Tom Lane
Tom Lane 2013년 3월 27일
You didn't really explain what you tried. Here's an example that works:
quad(@(x) x.*normcdf(x),-1,1)
If I use matrix multiplication "*" instead of elementwise multiplication ".*" I get the same error you report. So if your integrand is something like this, maybe you need to switch to elementwise multiplication.
  댓글 수: 1
Javier
Javier 2013년 3월 27일
Thanks, i did not know that. However, i still can´t solve the integral (now the error message is Undefined function 'times' for input arguments of type 'function_handle)
What i have to do is to compute a definite integral for the function:
N(a(t))*b(t)*C(d(t)) dt
Where N(a(t)) is a normal probability function valued at the value a, which is in fact a function that depends on t. C(d(t)) is a cumulative normal probability function valued d, which is also a function that depends on t. And b(t) is another function of t.
I have tried to define first the functions a(t) b(t) and c(t) as function handles. Then i used the commandsnormcdf and normpdf to compute the normal cumulative and probability function on this function (i think this way i obtain also a function handle that depends on t, but i am not sure if this is ok. For example, CNaux1 = @(t)normcdf((K*(T-t))/sigma/sqrt(T-t)) )
Later, i define another function handle integrand= N(a(t)).*b(t).*C(d(t)) and i use the quad (integrand, 0, T) (T previously defined)
I thinh i probably made more than one mistake, i am quite a bit lost...
Thank you very much!

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

추가 답변 (1개)

Youssef  Khmou
Youssef Khmou 2013년 3월 27일
편집: Youssef Khmou 2013년 3월 27일
hi,
I am no sure about the error you get, but try this version :
m=0;
s=1;
x=0:0.1:10;
C=normcdf(x,m,s);
PHI=2*exp(j*2*pi*x); % Consider it as wave function
N=abs(PHI).^2; % consider it as the probability of existence .
b=exp(-(x-2).^2);; % the thrid function as you consider
II=C.*b.*N;
figure, plot(x,II);
F=trapz(x,II);
So the integral is evaluated using the function "trapz" along the X axis ,
I hope this helps

카테고리

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