# Implementation of Optimality condition

**URL:** <https://community.freefem.org/t/implementation-of-optimality-condition/748>\
**Category:** General Discussion\
**Created:** [January 16, 2021, 12:43pm UTC](https://community.freefem.org/t/implementation-of-optimality-condition/748 "2021-01-16T12:43:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zese](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/zese/32/917_2.png) [@zese](https://community.freefem.org/u/zese)\
**Post date:** [January 16, 2021, 12:43pm UTC](https://community.freefem.org/t/implementation-of-optimality-condition/748/1 "2021-01-16T12:43:57Z")

</div>

Dear Sir/Madam

I have problem with implementation of an equation in the code. I have a relation as follow:  
∇𝒥=−(𝑑𝑢/𝑑𝑛)+𝛼𝐹 on inlet

where u is obtained in the former step and is known and F is known also. to reach the descent direction I need to calculate ∇𝒥 on inlet. I don’t know how to implement it in the code. I will be grateful if help me.

Best regards

---

<div class="post-metadata">

**Author:** ![denis.crete](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@denis.crete](https://community.freefem.org/u/denis.crete)\
**Post date:** [January 16, 2021, 9:12pm UTC](https://community.freefem.org/t/implementation-of-optimality-condition/748/2 "2021-01-16T21:12:08Z")

</div>

Hello,  
In the documentation, §3.13, it reads

macro dn(u) (N.x_dx(u)+N.y_dy(u) )

which shows you how to calculate the gradient of u and the vector normal to a boundary (in 2 dimensions).

HTH  
Denis

---

<div class="post-metadata">

**Author:** ![zese](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/zese/32/917_2.png) [@zese](https://community.freefem.org/u/zese)\
**Post date:** [January 17, 2021, 6:06am UTC](https://community.freefem.org/t/implementation-of-optimality-condition/748/3 "2021-01-17T06:06:47Z")

</div>

Dear Denis

Thanks very much. I already wrote the equation but my problem is that how I can say that it is for inlet boundary not the other domain. is any definition for that in the code?

Best regards
