How I can integrate symbolically a function of probability?

4 Ansichten (letzte 30 Tage)
Jurgen
Jurgen am 22 Sep. 2014
Bearbeitet: Jurgen am 23 Sep. 2014
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 Kommentar
Jurgen
Jurgen am 23 Sep. 2014
Bearbeitet: Jurgen am 23 Sep. 2014
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})

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Star Strider
Star Strider am 22 Sep. 2014
Bearbeitet: Star Strider am 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 Kommentare
Jurgen
Jurgen am 22 Sep. 2014
Bearbeitet: Jurgen am 22 Sep. 2014
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?
Star Strider
Star Strider am 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.

Melden Sie sich an, um zu kommentieren.


Roger Stafford
Roger Stafford am 22 Sep. 2014
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 Kommentare
Jurgen
Jurgen am 22 Sep. 2014
Bearbeitet: Jurgen am 23 Sep. 2014
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)

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by