How I can integrate symbolically a function of probability?
이전 댓글 표시
Hello,
I need to integrate the following:
f1=@(x)unifpdf(x,0.4,0.5)
syms x;
int(f1(x),x,0,1)
ans =
10
This result is wrong because f1 is 10 only in [0.4,0.5] and 0 otherwise. By declaring 'syms x', f1 (x) = 10.
I know I can calculate this integral using:
integral (f1,0,1)
ans =
1.0000
However, I need to calculate it via symbolic integration, since after I need to calculate the derivative with respect to tau of int(f1 (x), x, 0, tau), which could not make out if the integral was numerical.
Thanks in advance
답변 (2개)
Star Strider
2014년 9월 22일
편집: Star Strider
2014년 9월 22일
You defined:
f1=@(x)unifpdf(x,0.4,0.5)
If you define:
f1 = @(x) unifpdf(x)
syms x
int(f1(x),x,0,1)
you get:
ans =
1
댓글 수: 6
Jurgen
2014년 9월 22일
Star Strider
2014년 9월 22일
If you do:
f1 = @(x) unifpdf(x)
syms x
int(f1(x),x,0.4,0.5)
the result is:
ans =
1/10
Jurgen
2014년 9월 22일
Star Strider
2014년 9월 22일
It is not an error. You cannot define the integral of your distribution to be equal to 1 on a subinterval and expect it to be also equal to 1 on a larger interval, at least with the same function. The way you defined it, the Symbolic Math Toolbox does not ‘know’ your function ‘f1’ is a uniform distribution. It considers it a function like any other function.
You have to get into MuPAD to have access to the symbolic uniform cumulative distribution, but I doubt it would give you the same value on a sub-interval and the larger interval either. If it did, I would suspect the result.
Star Strider
2014년 9월 22일
MATLAB used the Maple engine up until about 2010, then switched to MuPAD. I also bought Maple for a while, and if I remember correctly Maple can generate MATLAB code. I don’t know if you could integrate Maple in place of MuPAD, though. I suggest you ask Maple to see if that is possible.
Roger Stafford
2014년 9월 22일
0 개 추천
To get the proper answer you need to extend the range of x over which f1(x) is defined. When you run int(f1(x),x,0,1), the 'int' function doesn't know how f1(x) is supposed to be defined outside the range [.4,.5] so it apparently chooses 10 for the lack of anything else to select. Why should it necessarily choose zero unless you specify that.
댓글 수: 2
Star Strider
2014년 9월 22일
Thank you.
카테고리
도움말 센터 및 File Exchange에서 Assumptions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!