# Global or not?

**URL:** https://discourse.julialang.org/t/global-or-not/89807
**Category:** New to Julia
**Created:** [November 5, 2022, 10:58am UTC](https://discourse.julialang.org/t/global-or-not/89807 "2022-11-05T10:58:21Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![hoseini](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hoseini/32/31993_2.png) [@hoseini](https://discourse.julialang.org/u/hoseini)
#### Post date: [November 5, 2022, 10:58am UTC](https://discourse.julialang.org/t/global-or-not/89807/1 "2022-11-05T10:58:21Z")

</div>

Hi  
I am new in Julia. I intend to produce two vectors u and v via a for loop as below. Unfortunately, the vectors are not recognizable outside of the loop, why?

```julia
λ = −0.45 # The bifurcation Parameter
function ST(u, v)
    [v; u-u^2+λ*v+0.5*u*v]
end
#function count()

a = 0.001; b = 0.0008 # Initial Condition
Τ=12 # Final Time
Δ = 0.01 # The Time Discretization
for n in 1:Τ/Δ

    K1 = ST(a, b)
    K2 = ST(a+Δ*K1[1]/2, b+Δ*K1[2]/2)
    K3 = ST(a+Δ*K2[1]/2, b+Δ*K2[2]/2)
    K4 = ST(a+Δ*K3[1] , b+Δ*K3[2])

    global (a, b) = [a; b]+Δ*(K1+2*K2+2*K3+K4)/6
    global (u(n), v(n)) = (a, b)
      println("n=", n, "--a=", u(n), "-- b=", v(n))
   end  

```

And at the program I am going to plot the points of u versus v. How is sort out?

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [November 5, 2022, 11:36am UTC](https://discourse.julialang.org/t/global-or-not/89807/2 "2022-11-05T11:36:14Z")

</div>

Hello and welcome.  
Some comments:

- `λv` should be `λ*v`
- `u(n)` should be `u[n]`
- initialize `u` and `v` vectors, ex: `u = Vector{Float64}(undef, Nmax)`, with `Nmax = round(Int, Τ/Δ)`
- better to write also: `for i in 1:Nmax`
- no need to use `global`

_ **NB:** _  
_You should edit your post to put all the code within the triple backticks:_  
```julia  
`code here`  
```

---

<div class="post-metadata">

### Author: ![hoseini](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hoseini/32/31993_2.png) [@hoseini](https://discourse.julialang.org/u/hoseini)
#### Post date: [November 5, 2022, 1:09pm UTC](https://discourse.julialang.org/t/global-or-not/89807/3 "2022-11-05T13:09:07Z")

</div>

> [@rafael.guerra](#):
>
> - ``
> - initialize `u` and `v` vectors, ex: `u = Vector{Float64}(undef, `

Hi rafael  
Thanks indeed for your help

---

<div class="post-metadata">

### Author: ![hoseini](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hoseini/32/31993_2.png) [@hoseini](https://discourse.julialang.org/u/hoseini)
#### Post date: [November 5, 2022, 1:13pm UTC](https://discourse.julialang.org/t/global-or-not/89807/4 "2022-11-05T13:13:43Z")

</div>

and how to plot u versus v? please

---

<div class="post-metadata">

### Author: ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)
#### Post date: [November 5, 2022, 1:59pm UTC](https://discourse.julialang.org/t/global-or-not/89807/5 "2022-11-05T13:59:13Z")

</div>

Please check [Plots tutorial here](https://docs.juliaplots.org/latest/tutorial/), it is the first thing explained.
