# Contours with equal area changing system

**URL:** https://discourse.julialang.org/t/contours-with-equal-area-changing-system/40644
**Category:** Optimization (Mathematical)
**Tags:** question, package
**Created:** [June 3, 2020, 5:35am UTC](https://discourse.julialang.org/t/contours-with-equal-area-changing-system/40644 "2020-06-03T05:35:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Tamuzd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamuzd/32/8803_2.png) [@Tamuzd](https://discourse.julialang.org/u/Tamuzd)
#### Post date: [June 3, 2020, 5:35am UTC](https://discourse.julialang.org/t/contours-with-equal-area-changing-system/40644/1 "2020-06-03T05:35:03Z")

</div>

Let’s say I have a system with 3 particles in 2d system a,b,c with the following positions

```julia
a = [0.1,0.0]
b = [-0.1,0.0]
c = [0.0,0.1]

```

each particle is described by Gaussian function, therefore the system function is as followed:

```julia
σ = 0.08
f(x,y) = exp(-((x-a[1])^2+(y-a[2])^2)/(2(σ^2)))+exp(-((x-b[1])^2+(y-b[2])^2)/(2(σ^2)))+exp(-((x-c[1])^2+(y-c[2])^2)/(2(σ^2)))

```

I draw the initial system shape

```julia
x = range(-0.5,stop=0.5,length=50)
y = range(-0.5,stop=0.5,length=50)
contour(x,y,f,levels=[1.0],aspect_ratio=:equal)

```

![InitialShapeStackOverFlowQuestion](https://global.discourse-cdn.com/julialang/original/3X/9/d/9d5f5d0f94c3a89bbc3fba4892b15e5aea41bed9.png)  
using Plots package. After a while the particles move to other positions,for instance:

```julia
a = [0.1,-0.05]
b = [-0.1,0.0]
c = [0.05,0.1]

```

which changes the shape of the contour according to the same f(x,y) function (with the same sigma). I need to produce a closed contour that **keep the same area** for the new particle positions. How do I do that? or How can I find the “level” to reach the same area? This was an example, in fact I have many particles in my function. The Domain Astro/Space might also able to contribute

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [June 3, 2020, 6:42am UTC](https://discourse.julialang.org/t/contours-with-equal-area-changing-system/40644/2 "2020-06-03T06:42:33Z")

</div>

Please cross-reference your posts if you’re also asking on StackOverflow, this question appears [here](https://stackoverflow.com/questions/62153804/contours-with-equal-area-changing-system-in-julia).

I saw your question on SO but couldn’t work out what you’re actually trying to achieve. What is the “level”? Can you provide an example of what your desired output looks like?

---

<div class="post-metadata">

### Author: ![tomerarnon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomerarnon/32/3170_2.png) [@tomerarnon](https://discourse.julialang.org/u/tomerarnon)
#### Post date: [June 3, 2020, 8:04am UTC](https://discourse.julialang.org/t/contours-with-equal-area-changing-system/40644/3 "2020-06-03T08:04:12Z")

</div>

I don’t think this is particularly easy to do. I guess what you want to find is something like a level set b such that A = \int \{f(x,y) ≤ b\} dxdy. I gave it some thought, figuring that since f was a sum of gaussians, the integral of it can be found analytically, but ultimately didn’t come up with anything too helpful. That’s not to say that it can’t be done…

Edit:  
You can also maybe pose it as an optimization problem over the variable b and try to approach it that way.

---

<div class="post-metadata">

### Author: ![Tamuzd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamuzd/32/8803_2.png) [@Tamuzd](https://discourse.julialang.org/u/Tamuzd)
#### Post date: [June 3, 2020, 9:03am UTC](https://discourse.julialang.org/t/contours-with-equal-area-changing-system/40644/4 "2020-06-03T09:03:39Z")

</div>

in “level” I mean to `levels=[1.0]` inside the `contour` command. In this example, initially it would be 1.0, what would be the next value after the system evolvement?
