How I can integrate symbolically a function of probability?
Show older comments
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
1 Comment
Answers (2)
Star Strider
on 22 Sep 2014
Edited: Star Strider
on 22 Sep 2014
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 Comments
Jurgen
on 22 Sep 2014
Star Strider
on 22 Sep 2014
If you do:
f1 = @(x) unifpdf(x)
syms x
int(f1(x),x,0.4,0.5)
the result is:
ans =
1/10
Jurgen
on 22 Sep 2014
Star Strider
on 22 Sep 2014
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
on 22 Sep 2014
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
on 22 Sep 2014
0 votes
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 Comments
Star Strider
on 22 Sep 2014
Thank you.
Categories
Find more on Assumptions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!