# Spatial Co-ordinate of Maximum Value of Variable

**URL:** https://community.freefem.org/t/spatial-co-ordinate-of-maximum-value-of-variable/1364
**Category:** General Discussion
**Created:** [December 3, 2021, 9:02am UTC](https://community.freefem.org/t/spatial-co-ordinate-of-maximum-value-of-variable/1364 "2021-12-03T09:02:23Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![D\_N\_Sarkar](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@D\_N\_Sarkar](https://community.freefem.org/u/D_N_Sarkar)
#### Post date: [December 3, 2021, 9:02am UTC](https://community.freefem.org/t/spatial-co-ordinate-of-maximum-value-of-variable/1364/1 "2021-12-03T09:02:23Z")

</div>

Say I have the following code:

int nn = 50;  
mesh Th = square(nn, nn);  
fespace Vh(Th, P1);  
Vh u;  
u = sin(x);

I can get the maximum value of ‘u’ by:  
real maxValueU = u[].max;

How do I get the values of x and y coordinates where maximum value of ‘u’ occurs?

---

<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: [December 4, 2021, 2:57pm UTC](https://community.freefem.org/t/spatial-co-ordinate-of-maximum-value-of-variable/1364/2 "2021-12-04T14:57:53Z")

</div>

yes but be careful because the max could be not unique.unc

the method imax give the dof number

int dofmaxValueU = u[].imax;

Now for P1 finite element the dof are vertices with same numbering so

Th(dofmaxValueU).x  
Th(dofmaxValueU).y

given the coordinate.
