# Define a variable point by point

**URL:** https://community.freefem.org/t/define-a-variable-point-by-point/764
**Category:** General Discussion
**Created:** [January 26, 2021, 7:52pm UTC](https://community.freefem.org/t/define-a-variable-point-by-point/764 "2021-01-26T19:52:09Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![yongxing](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/yongxing/32/3632_2.png) [@yongxing](https://community.freefem.org/u/yongxing)
#### Post date: [January 26, 2021, 7:52pm UTC](https://community.freefem.org/t/define-a-variable-point-by-point/764/1 "2021-01-26T19:52:09Z")

</div>

Hi,

Can someone please help me figure this out:  
say

fespace Vh(th,P1);  
Vh f=0;

Can I define f at given vertices, such as (x0, y0) which is the coordinate of a vertex.  
I tried f(x0,y0)=2\*x0+y0, which was illegal.  
It seems I can do f[][i] = … but how I could know the index i ?

Thank you in advance.

---

<div class="post-metadata">

### Author: ![prj](https://avatars.discourse-cdn.com/v4/letter/p/ecae2f/32.png) [@prj](https://community.freefem.org/u/prj)
#### Post date: [January 26, 2021, 7:57pm UTC](https://community.freefem.org/t/define-a-variable-point-by-point/764/2 "2021-01-26T19:57:37Z")

</div>

`Vh f = 2*x+y; // post must be at least 20 characters, so here is a random comment`

Or did you mean the following?

```auto
fespace Wh(th, [P1, P1]);
Wh [u, v] = [x, y];

```

---

<div class="post-metadata">

### Author: ![yongxing](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/yongxing/32/3632_2.png) [@yongxing](https://community.freefem.org/u/yongxing)
#### Post date: [January 26, 2021, 8:03pm UTC](https://community.freefem.org/t/define-a-variable-point-by-point/764/3 "2021-01-26T20:03:47Z")

</div>

Thank you P, but this is not what I intended to do.

I try to define a force **f** , which is linearly distributed from point (x0, y0) to (x1, y1) – both points are moving.

**f** is perpendicular to the line determined by these two points., and the magnitude of **f** = 0 at (x1, y1) and 1 at (x0, y0).

I know the coordinates of vertices between (x0, y0) and (x1, y1), so I try to do this point by point. Do you have a better idea?

Best,  
Yongxing.

---

<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: [January 29, 2021, 5:51pm UTC](https://community.freefem.org/t/define-a-variable-point-by-point/764/4 "2021-01-29T17:51:45Z")

</div>

To day the simple way, is a little tricky, because it integration on meshL of 2d finite element function buggius. so the idea is to build a 2d mesh such that one border is your line.

a example where the segment move on a square …

[moveline.edp](https://community.freefem.org/uploads/short-url/hNy3nHYxiaEMVzver6Zzc5g0P1M.edp) (746 Bytes)

remark I do not defined f points to points

but you can do :  
f=0;  
for(int i=0, i\<f[].n; ++n)  
f[][i] =i;

to see the numbering for example.

---

<div class="post-metadata">

### Author: ![yongxing](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/yongxing/32/3632_2.png) [@yongxing](https://community.freefem.org/u/yongxing)
#### Post date: [January 30, 2021, 10:40pm UTC](https://community.freefem.org/t/define-a-variable-point-by-point/764/5 "2021-01-30T22:40:27Z")

</div>

Thank you very much! This is really helpful.  
YX.
