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

댓글 수: 1

Jurgen
Jurgen 2014년 9월 23일
편집: Jurgen 2014년 9월 23일
maybe the problem is to integrate a piecewise function, because I do the following, and not get the result.
>> fun=@(x)piecewise_eval(x,[0.4 0.500],{0 10 0})
>> int(fun(x),x,0.4,1)
Error using symengine (line 58) Unable to prove 'x < 2/5' literally. To test the statement mathematically, use isAlways.
Error in sym/subsindex (line 1554) X = find(mupadmex('symobj::logical',A.s,9)) - 1;
Error in sym>privformat (line 2357) x = subsindex(x)+1;
Error in sym/subsref (line 1578) [inds{k},refs{k}] = privformat(inds{k});
Error in piecewise_eval (line 75) z(k)=feval(funs{1},x(k));
Error in @(x)piecewise_eval(x,[0.4,0.500],{0,10,0})

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

답변 (2개)

Star Strider
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

that would be a different problem, since x be uniformly distributed between 0 and 1, and I want to distribute uniformly between 0.4 and 0.5
If you do:
f1 = @(x) unifpdf(x)
syms x
int(f1(x),x,0.4,0.5)
the result is:
ans =
1/10
It is a different problem. What you raise is uniformly distributed between 0 and 1, so the integral between 0.4 and 0.5 would be 1/10. Howeber, in my problem x is uniformly distributed between 0.4 and 0.5, so the integral between 0.4 and 0.5 must be 1. In fact if I do int(f1(x), x, 0.4,0.5) the result is 1. The error occurs when calculating int(f1(x), x, 0,1) (which also should be 1), but Matlab says it is 10.
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.
Jurgen
Jurgen 2014년 9월 22일
편집: Jurgen 2014년 9월 22일
It is perfectly reasonable that if distribution is defined in a subinterval of an interval greater, the probability that this in the interval and subinterval must be the same. Indeed Maple gives me the result I'm saying, but I'm having trouble using mudpad. Is any way to integrate Matlab R2013a with Maple 17?
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
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

Thank you.
Jurgen
Jurgen 2014년 9월 22일
편집: Jurgen 2014년 9월 23일
Yes, I think you're right, but the problem is that I need to define fun = @ (Y) int (f1 (x), x, y, 1). The integration interval is variable and the number Y could be a greater or smaller than the interval distrubution limits (0.4 and 0.5). Really do not understand why when I use int, Matlab assume always the 10 value, thats weird because if I evaluated f1(0.6), for example, says that it is zero (thats it's right answer)

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

카테고리

질문:

2014년 9월 22일

편집:

2014년 9월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by