# Define a complicated function

**URL:** <https://community.freefem.org/t/define-a-complicated-function/1053>\
**Category:** General Discussion\
**Created:** [June 22, 2021, 6:57pm UTC](https://community.freefem.org/t/define-a-complicated-function/1053 "2021-06-22T18:57:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aicha](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aicha](https://community.freefem.org/u/Aicha)\
**Post date:** [June 22, 2021, 6:57pm UTC](https://community.freefem.org/t/define-a-complicated-function/1053/1 "2021-06-22T18:57:48Z")

</div>

Hi,  
how we define the following function with FF++  
f(x,y,0)= 0.5 \* v0 \* (1+tanh(500 \* (R-r(x,y)))), r(x,y) \<= R , 0 if r(x,y)\>R  
where r(x,y)=sqrt{(x-x\_0)^2+(y-y\_0)^2} and R=\sqrt{x\_0/pi}

v0, x\_0 and y\_0 are real data

Thank you in advance

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [June 23, 2021, 7:56am UTC](https://community.freefem.org/t/define-a-complicated-function/1053/2 "2021-06-23T07:56:41Z")

</div>

No difficulty

just see :

[testfunc.edp](https://community.freefem.org/uploads/short-url/aTNOC3IxleETk2sCJBhs44oUiqH.edp) (185 Bytes)

---

<div class="post-metadata">

**Author:** ![Aicha](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Aicha](https://community.freefem.org/u/Aicha)\
**Post date:** [June 23, 2021, 9:14am UTC](https://community.freefem.org/t/define-a-complicated-function/1053/3 "2021-06-23T09:14:47Z")

</div>

Thank you so much!  
Another question please. If we have

```auto
mesh Th = square(N,N,[L*x,H*y]);
fespace Vh(Th,P1);

```

then we must interpolate the function f with

`Vh f;`  
?

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [June 23, 2021, 11:46am UTC](https://community.freefem.org/t/define-a-complicated-function/1053/4 "2021-06-23T11:46:39Z")

</div>

Just write

```
 f= sin(x)*cos(y); 

```

where f is the interpolation of function f : ( x,y) → sin(x)\*cos(y)
