# Function defined as multidimensional integral

**URL:** <https://discourse.julialang.org/t/function-defined-as-multidimensional-integral/73535>\
**Category:** New to Julia\
**Tags:** question, integral\
**Created:** [December 23, 2021, 4:13pm UTC](https://discourse.julialang.org/t/function-defined-as-multidimensional-integral/73535 "2021-12-23T16:13:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Federico\_Compagnin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/federico_compagnin/32/32170_2.png) [@Federico\_Compagnin](https://discourse.julialang.org/u/Federico_Compagnin)\
**Post date:** [December 23, 2021, 4:13pm UTC](https://discourse.julialang.org/t/function-defined-as-multidimensional-integral/73535/1 "2021-12-23T16:13:30Z")

</div>

Hi, I’m trying to define a new function as follows:

![Screenshot 2021-12-23 at 17.11.46](https://global.discourse-cdn.com/julialang/original/3X/8/0/8064948a27d477079cc8d14bc0a029021f995235.png)

meaning, I’d like to integrate over x and y, leaving z as a variable. I thought maybe to integrate z over (0,z) and then differentiate the function with respect to z, but it seems to me quite intricate. Any ideas?

Thanks a lot

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 23, 2021, 4:26pm UTC](https://discourse.julialang.org/t/function-defined-as-multidimensional-integral/73535/2 "2021-12-23T16:26:29Z")

</div>

h(z) = hcubature((x,y)-\>f(x,y,z),…). It’s called a closure.

---

<div class="post-metadata">

**Author:** ![Federico\_Compagnin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/federico_compagnin/32/32170_2.png) [@Federico\_Compagnin](https://discourse.julialang.org/u/Federico_Compagnin)\
**Post date:** [December 23, 2021, 4:46pm UTC](https://discourse.julialang.org/t/function-defined-as-multidimensional-integral/73535/3 "2021-12-23T16:46:43Z")

</div>

That’s interesting! I’m still learning Julia, so this is something new for me.  
Trying to implement this closure, I got the following method matching error: how can it be? Those #9#10 aren’t so clear to me

 ![Screenshot 2021-12-23 at 17.45.09](https://global.discourse-cdn.com/julialang/original/3X/e/3/e3eae98c0c02cfffd7c9275c208cfc3362c4c8be.png)

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 23, 2021, 5:00pm UTC](https://discourse.julialang.org/t/function-defined-as-multidimensional-integral/73535/4 "2021-12-23T17:00:42Z")

</div>

Oh it’s giving you an SVector instead of two arguments, so it’s x[1] etc. You can write that all out, or use the simpler syntax h(z) = hcubature((x)-\>f(x…,z),…) to splat it

---

<div class="post-metadata">

**Author:** ![Federico\_Compagnin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/federico_compagnin/32/32170_2.png) [@Federico\_Compagnin](https://discourse.julialang.org/u/Federico_Compagnin)\
**Post date:** [December 23, 2021, 5:09pm UTC](https://discourse.julialang.org/t/function-defined-as-multidimensional-integral/73535/5 "2021-12-23T17:09:15Z")

</div>

I love this syntax!  
Thank you a lot

---

<div class="post-metadata">

**Author:** ![gustaphe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gustaphe/32/18174_2.png) [@gustaphe](https://discourse.julialang.org/u/gustaphe)\
**Post date:** [December 23, 2021, 6:31pm UTC](https://discourse.julialang.org/t/function-defined-as-multidimensional-integral/73535/6 "2021-12-23T18:31:26Z")

</div>

Welcome! For the future: please share code as text instead of images. Makes it easier to read, copy and run. You can use a triple backtick fence to get monospace font and syntax highlighting.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …
