# Volume integral in Julia?

**URL:** <https://discourse.julialang.org/t/volume-integral-in-julia/98085>\
**Category:** General Usage\
**Tags:** integral\
**Created:** [April 29, 2023, 1:21pm UTC](https://discourse.julialang.org/t/volume-integral-in-julia/98085 "2023-04-29T13:21:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [April 29, 2023, 1:21pm UTC](https://discourse.julialang.org/t/volume-integral-in-julia/98085/1 "2023-04-29T13:21:05Z")

</div>

Hello!

Is something like this possible in Julia, here an example from Matlab:

> **[Numerically evaluate triple integral - MATLAB integral3
- MathWorks Nordic](https://se.mathworks.com/help/matlab/ref/integral3.html)**
>
> This MATLAB function approximates the integral of the function z = fun(x,y,z) over the region xmin ≤ x ≤ xmax, ymin(x) ≤ y ≤ ymax(x) and zmin(x,y) ≤ z ≤ zmax(x,y).

 ![image](https://global.discourse-cdn.com/julialang/original/3X/c/7/c7c91265957ccd1ac9ecabaadd6a04c91b44e4e4.png)

Where it is possible to perform a volume integral using non-constant values in the limits?

EDIT: Just to make it a bit easier I pasted in the Matlab code:

```matlab
fun = @(x,y,z) x.*cos(y) + x.^2.*cos(z)

xmin = -1;
xmax = 1;
ymin = @(x)-sqrt(1 - x.^2);
ymax = @(x) sqrt(1 - x.^2);
zmin = @(x,y)-sqrt(1 - x.^2 - y.^2);
zmax = @(x,y) sqrt(1 - x.^2 - y.^2);

q = integral3(fun,xmin,xmax,ymin,ymax,zmin,zmax,'Method','tiled')

```

Kind regards

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [April 29, 2023, 1:27pm UTC](https://discourse.julialang.org/t/volume-integral-in-julia/98085/2 "2023-04-29T13:27:12Z")

</div>

> [@Ahmed\_Salih](#):
>
> Where it is possible to perform a volume integral using non-constant values in the limits?

For example, you can just use HCubature.jl with a change of variables to map the domain to a box. For example, see: [2D integration over non-rectangular domain using cubature - #7 by stevengj](https://discourse.julialang.org/t/2d-integration-over-non-rectangular-domain-using-cubature/2991/7)

(You could also do nested calls to a 1d quadrature routine like `quadgk`, though this requires some care for the tolerance of the inner integrals.)

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [April 29, 2023, 1:37pm UTC](https://discourse.julialang.org/t/volume-integral-in-julia/98085/3 "2023-04-29T13:37:12Z")

</div>

Okay, this might be easy for some, but for me right now, I am not able to do this change of variable easily. What I want to calculate is the volume of a cylinder intersected by a plane as shown in this youtube video:

[![](https://global.discourse-cdn.com/julialang/original/3X/5/f/5fc6c77c88943af6471ec2f191d633a749d088b2.jpeg "Video 3224.6 - Triple Integrals Volume, Cyclinder, Plane - Part 1/2") ](https://www.youtube.com/watch?v=w5QTBIn8HNo&t=311s)

With the equation of the plane:

2x + z = 4

And the equation for the cylinder:

x^2 + y^2 = 9

Could you teach me/guide me on how do I decompose this triple integral into a final 1d integral?

Kind regards

---

<div class="post-metadata">

**Author:** ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)\
**Post date:** [April 29, 2023, 2:21pm UTC](https://discourse.julialang.org/t/volume-integral-in-julia/98085/4 "2023-04-29T14:21:14Z")

</div>

You can find some examples, though not this specific one, here: [Calculus with Julia - 59&nbsp; Multi-dimensional integrals](https://jverzani.github.io/CalculusWithJuliaNotes.jl/integral_vector_calculus/double_triple_integrals.html#a-fubini-function)
