Calculating iterated integral using Sagemath

867 Views Asked by At

I would like to calculate the integral over the following domain (with order $x,y,z$) using Sagemath $$0 \le z \le 3, \max\{ 0,\frac{z-1}{2}\} \le y \le 1, \max \{y,z-2y\} \le x \le 1. \tag{1} \label{1}$$ This is equivalent to finding the integral (with order $z,y,x$) $$\int_{0}^{1} \int_{0}^{x}\int_{0}^{x+2y} \mathrm dz\,\mathrm dy\,\mathrm dx=2/3.$$ However, when I tried to write this onto Sagemath as follow

integrate(integrate(integrate(1,x,max(z-2*y,y),1),y,max(0,(z-1)/2),1),z,0,3)

I obtained a wrong answer of $3/2$.

I tried to break $\eqref{1}$ down into smaller domain (see here), I then got the correct answer.

var("x y z")
X=integrate(integrate(integrate(1,x,z-2*y,1),y,0,z/3),z,0,1)
Y=integrate(integrate(integrate(1,x,y,1),y,z/3,1),z,0,1)
Z=integrate(integrate(integrate(1,x,y,1),y,z/3,1),z,1,3)
W=integrate(integrate(integrate(1,x,z-2*y,1),y,(z-1)/2,z/3),z,1,3)
C=X+Y+Z+W

I would like to ask why is it so? How does Sagemath deal with $\max$ function in this case?

1

There are 1 best solutions below

0
On BEST ANSWER

This is a problem on max function when working with variables, instead you should use max_symbolic, (see);

With the changes the code is:

integrate(integrate(integrate(1,x,max_symbolic(z-2*y,y),1),y,max_symbolic(0,(z-1)/2),1),z,0,3)