There are things that seem simple but rapidly turn into a nightmare.
Here is an example: what I want is to the expression given at equation (4) in the attached file.
Using Int gives a wrong result.
Using int gives a right one but not of the desired form (some double integrals are nested while others are not).
I've been stuck on this problem for hours, can you please help me to fix it?
TIA
> |
use Statistics in
# For more generality defina an abstract probability distribution.
AbstractDistribution := proc(N)
Distribution(
PDF = (x -> varphi(seq(x[n], n=1..N)))
)
end proc:
# Define two random variables pf AbstractDistribution type.
X__1 := RandomVariable(AbstractDistribution(2)):
X__2 := RandomVariable(AbstractDistribution(2)):
end use;
|

|
(1) |
> |
F := (U1, U2) -> U1/(U1+U2);
T := mtaylor(F(X__1, X__2), [X__1=1, X__2=1], 2):
|

|
(2) |
Error: x[2] is droped out of the double integral in the rightmost term
> |
use IntegrationTools in
J := eval([op(expand(T))], [seq(X__||i=x[i], i=1..2)]);
L := add(
map(
j ->
if j::numeric then
j
else
(Expand@CollapseNested)(
Int(
j * Statistics:-PDF(X__1, x)
, seq(x[i]=-infinity..+infinity, i=1..2)
)
)
end if
, J
)
):
ET := %
end use;
|
![1/2+(1/4)*(Int(x[1]*varphi(x[1], x[2]), [x[1] = -infinity .. infinity, x[2] = -infinity .. infinity]))-(1/4)*x[2]*(Int(varphi(x[1], x[2]), [x[1] = -infinity .. infinity, x[2] = -infinity .. infinity]))](/view.aspx?sf=237612_question/afa650d3d26f2366ae3d22bcb804beeb.gif)
|
(3) |
I want this
> |
'ET' = 1/2
+
(1/4)*(Int(Int(x[1]*varphi(x[1], x[2]), x[1] = -infinity .. infinity), x[2] = -infinity .. infinity))
-(1/4)*(Int(Int(x[2]*varphi(x[1], x[2]), x[1] = -infinity .. infinity), x[2] = -infinity .. infinity))
|
![ET = 1/2+(1/4)*(Int(Int(x[1]*varphi(x[1], x[2]), x[1] = -infinity .. infinity), x[2] = -infinity .. infinity))-(1/4)*(Int(Int(x[2]*varphi(x[1], x[2]), x[1] = -infinity .. infinity), x[2] = -infinity .. infinity))](/view.aspx?sf=237612_question/c37a9079bb90f1d5cd9f178a5dd6c2d3.gif)
|
(4) |
With int instead of Int one integral is double the other is double-nested
> |
L := add(
map(
j ->
if j::numeric then
j
else
int(
j * Statistics:-PDF(X__1, x)
, seq(x[i]=-infinity..+infinity, i=1..2)
)
end if
, J
)
):
ET := %
|
![1/2+int(int((1/4)*x[1]*varphi(x[1], x[2]), x[1] = -infinity .. infinity), x[2] = -infinity .. infinity)+int(-(1/4)*x[2]*(int(varphi(x[1], x[2]), x[1] = -infinity .. infinity)), x[2] = -infinity .. infinity)](/view.aspx?sf=237612_question/d00424f7318504ae86340f88e53c1a2f.gif)
|
(5) |
As the expression of ET is now correct, I tried to use IntegrationTools to get the
form I want (equation (4)).
But as soon as I replace int by Int x[2] is again droped out.
So it's not even worth thinking about using CollapseNested!
> |
use IntegrationTools in
eval(ET, int=Int);
end use;
|
![1/2+Int(Int((1/4)*x[1]*varphi(x[1], x[2]), x[1] = -infinity .. infinity), x[2] = -infinity .. infinity)+Int(-(1/4)*x[2]*(Int(varphi(x[1], x[2]), x[1] = -infinity .. infinity)), x[2] = -infinity .. infinity)](/view.aspx?sf=237612_question/33ab49a907329b9f82ae8213b5180f78.gif)
|
(6) |
|
Download Int_int.mw