Global or not?

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?

λ = −0.45     # The bifurcation Parameter
function ST(u, v)
    [v; u-u^2+λ*v+0.5*u*v]
#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))

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

1 Like

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

You should edit your post to put all the code within the triple backticks:
code here


Hi rafael
Thanks indeed for your help

and how to plot u versus v? please

Please check Plots tutorial here, it is the first thing explained.

1 Like