# How to model this as a function of p(x) in Julia? (easy)

**URL:** <https://discourse.julialang.org/t/how-to-model-this-as-a-function-of-p-x-in-julia-easy/23758>\
**Category:** New to Julia\
**Created:** [May 2, 2019, 1:34am UTC](https://discourse.julialang.org/t/how-to-model-this-as-a-function-of-p-x-in-julia-easy/23758 "2019-05-02T01:34:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Engineer43](https://avatars.discourse-cdn.com/v4/letter/e/2acd7d/32.png) [@Engineer43](https://discourse.julialang.org/u/Engineer43)\
**Post date:** [May 2, 2019, 1:34am UTC](https://discourse.julialang.org/t/how-to-model-this-as-a-function-of-p-x-in-julia-easy/23758/1 "2019-05-02T01:34:59Z")

</div>

![39%20PM](https://global.discourse-cdn.com/julialang/original/3X/5/e/5eecc1a89bad65f94205feeba9143313ea919a5d.png)

Where i is the number of iterations and g(x) is a vector of 2 inequality constraints.

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [May 2, 2019, 5:08am UTC](https://discourse.julialang.org/t/how-to-model-this-as-a-function-of-p-x-in-julia-easy/23758/2 "2019-05-02T05:08:07Z")

</div>

Hi!, What optimization package are you using?

---

<div class="post-metadata">

**Author:** ![Engineer43](https://avatars.discourse-cdn.com/v4/letter/e/2acd7d/32.png) [@Engineer43](https://discourse.julialang.org/u/Engineer43)\
**Post date:** [May 2, 2019, 6:06am UTC](https://discourse.julialang.org/t/how-to-model-this-as-a-function-of-p-x-in-julia-easy/23758/3 "2019-05-02T06:06:01Z")

</div>

I am trying to put this equation into a penalty\_method function:

function penalty\_method(f, x, c, k\_max; ρ=1, γ=2) #ρ=1 (initial penalty), γ=2 (penalty modifier)  
for k in 1 : k\_max  
xr=x  
p(x) = sum(c(x).\> 0)  
# p(x) = sum(max(c(x), 0).^2)  
x = covariance\_matrix\_adaptation(x → f(x)+ ρ\*p(x), x, 300; σ = 1.0, m=100, m\_elite=50)  
if p(x)==0  
return x  
end  
end  
return x  
end

---

<div class="post-metadata">

**Author:** ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)\
**Post date:** [May 2, 2019, 6:09am UTC](https://discourse.julialang.org/t/how-to-model-this-as-a-function-of-p-x-in-julia-easy/23758/4 "2019-05-02T06:09:22Z")

</div>

i’m using NLopt right now, and it have and augmented lagrangian solver with an implementation of a penalty method for constraints on the function, maybe you can check on that
