# Switching lines makes results different

**URL:** https://discourse.julialang.org/t/switching-lines-makes-results-different/71468
**Category:** New to Julia
**Tags:** question
**Created:** [November 14, 2021, 10:11pm UTC](https://discourse.julialang.org/t/switching-lines-makes-results-different/71468 "2021-11-14T22:11:50Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![lumaca](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@lumaca](https://discourse.julialang.org/u/lumaca)
#### Post date: [November 14, 2021, 10:11pm UTC](https://discourse.julialang.org/t/switching-lines-makes-results-different/71468/1 "2021-11-14T22:11:50Z")

</div>

Hi, newbie here.

I have found a strange behaviour of the function below, particularly in the two bolded lines. It seems like the two vectors’ elements assume the last computed value at each i iteration, namely l[k].g\_vel[i]

```julia
function Interpolate_Fields!(l::Vector{Layer}, number_of_layers, number_of_nodes, number_of_particles)
    for k in 2:number_of_layers + 1
        for i in 1:number_of_nodes
            velocity = Float64(0)
            thickness = Float64(0)
            correction = Float64(0)
            for j in 1:number_of_particles
                radius =l[k].g_pos[i] - l[k].p_pos[j]
                if (norm(radius) <= TWO * l[k].g_smooth_length[i] )
                    kernel_eval = W(radius, l[k].g_smooth_length[i])
                    thickness = +(thickness, l[k].p_weight[j] * l[k].p_thickness[j] * kernel_eval)
                    velocity = +(velocity, l[k].p_weight[j] * l[k].p_vel[j] * kernel_eval)
                    correction = +(correction, l[k].p_weight[j] * kernel_eval )
                end
            end
            **l[k].g_thickness[i] = thickness / correction**
**l[k].g_vel[i] = velocity / correction**
        end
    end
    println(l[2].g_vel)
    println(l[2].g_thickness)
end

```

For example l[k].g\_thickness[1] is supposed to be equal to 1.2 and l[k].g\_vel[1] equal to 600, but actually 600 is returned for both of them in this case:

```julia
            l[k].g_thickness[1] = thickness / correction 
            l[k].g_vel[1] = velocity / correction 

```

and 1.2 is returned for both in this other case:

```julia
            l[k].g_vel[1] = velocity / correction 
            l[k].g_thickness[1] = thickness / correction 

```

Am I missing something?

Thanks  
Luca

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [November 14, 2021, 10:17pm UTC](https://discourse.julialang.org/t/switching-lines-makes-results-different/71468/2 "2021-11-14T22:17:01Z")

</div>

You are probably assigning both labels to the same array. Use `copy` when you initialize them.
