# No method matching getindex

**URL:** <https://discourse.julialang.org/t/no-method-matching-getindex/57622>\
**Category:** General Usage\
**Tags:** question, loops\
**Created:** [March 20, 2021, 7:41pm UTC](https://discourse.julialang.org/t/no-method-matching-getindex/57622 "2021-03-20T19:41:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![SUMAN\_SHEKHAR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suman_shekhar/32/23124_2.png) [@SUMAN\_SHEKHAR](https://discourse.julialang.org/u/SUMAN_SHEKHAR)\
**Post date:** [March 20, 2021, 7:41pm UTC](https://discourse.julialang.org/t/no-method-matching-getindex/57622/1 "2021-03-20T19:41:34Z")

</div>

Greeting to all, I am new user to Julia and I was writing my code in Julia for the first time. I wanted to implement a Gaussian Heat surface over a circular radius and outside that radius I want to set the value to zero to that heat function. Here is the piece of my code-

```julia

#Center horizontal coordinates so that (x,y)=(0,0) correspond to the 
#centre of the domain 
xc= grid.xC.-mean(grid.xC) #grid.xC contain an array of discrete cordinates 0:1/256:4
yc= grid.yC.-mean(grid.yC) # similar to grid.yC but in y direction
#Radius of Gausian
R=xc.*xc + yc.*yc
#Cutt off radius r
r=1
Q(x,y,z,t) = 9e-5.*exp(-0.5.*(R))
Q[findall(R.>r)].=0

```

After running this part I am getting this-  
` ERROR: MethodError: no method matching getindex(::typeof(Q), ::Array{Int64,1})`

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [March 20, 2021, 7:49pm UTC](https://discourse.julialang.org/t/no-method-matching-getindex/57622/2 "2021-03-20T19:49:13Z")

</div>

First of all, welcome to our community! 🎊

Parenthesis are for functions, and brackets for vectors/arrays. It is not clear what of the two you want. In `Q(x,y,z,t) = 9e-5.*exp(-0.5.*(R))` you are declaring a function with 4 parameters (none of them is used inside the function), and in the sequence you try to index it as it was a vector. Can you provide a little more context? I am not aware of a language that would work that way.

---

<div class="post-metadata">

**Author:** ![SUMAN\_SHEKHAR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suman_shekhar/32/23124_2.png) [@SUMAN\_SHEKHAR](https://discourse.julialang.org/u/SUMAN_SHEKHAR)\
**Post date:** [March 20, 2021, 7:54pm UTC](https://discourse.julialang.org/t/no-method-matching-getindex/57622/3 "2021-03-20T19:54:06Z")

</div>

Thank you for your reply sir, It is for heat flux boundary condition at the surface. I think I am confused how to write the function as I want the Heat flux i.e. Q to be a Gaussian Function only inside R \< r and for R \> r Q=0. Now I am very confused how to do that.

---

<div class="post-metadata">

**Author:** ![SUMAN\_SHEKHAR](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/suman_shekhar/32/23124_2.png) [@SUMAN\_SHEKHAR](https://discourse.julialang.org/u/SUMAN_SHEKHAR)\
**Post date:** [March 20, 2021, 7:57pm UTC](https://discourse.julialang.org/t/no-method-matching-getindex/57622/4 "2021-03-20T19:57:17Z")

</div>

Meanwhile I am using Oceananigans Solver which uses Julia and in that a function for boundary condition is written in that fashion Q(x,y,z,t).

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [March 20, 2021, 8:34pm UTC](https://discourse.julialang.org/t/no-method-matching-getindex/57622/5 "2021-03-20T20:34:50Z")

</div>

> [@SUMAN\_SHEKHAR](#):
>
> Oceananigans

Is [this](https://github.com/CliMA/Oceananigans.jl) the package you use? Can you point to an example in which it does something similar to what are you trying?

> [@SUMAN\_SHEKHAR](#):
>
> Q to be a Gaussian Function only inside R \< r and for R \> r Q=0.

Your function does not take `R` nor `r` both are global variables. This mean the equation inside will give the same value does not matter what values you pass to it. You code is nonsensical on pure Julia, maybe the package your mentioned add some macros/DSL that allows for such constructs but then you need to point me to them.
