# How to make a vector of observables in GLMakie

**URL:** https://discourse.julialang.org/t/how-to-make-a-vector-of-observables-in-glmakie/111012
**Category:** Modelling & Simulations
**Tags:** question
**Created:** [March 1, 2024, 1:06pm UTC](https://discourse.julialang.org/t/how-to-make-a-vector-of-observables-in-glmakie/111012 "2024-03-01T13:06:37Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)
#### Post date: [March 1, 2024, 1:06pm UTC](https://discourse.julialang.org/t/how-to-make-a-vector-of-observables-in-glmakie/111012/1 "2024-03-01T13:06:38Z")

</div>

I am trying to make an interactive plot of a SIV model using GLMakie. I have created the parameters as observable. I now need to make the parameters to pass to the solver. One is `u0` that stores the initial values of the variables. I used to instantiate u0 as a vector/array with vcat. How do I do the same with an observable? I tried with @lift but I got an error:

```julia
julia> s0 = 1e5 # default starting amount of naive bacteria
100000.0

julia> i0 = 0 # default starting amount of infected bacteria
0

julia> v0 = 1e5 # default starting amount of phages
100000.0

julia> S0 = Observable(s0)
Observable(100000.0)

julia> I0 = Observable(i0)
Observable(0)

julia> V0 = Observable(v0)
Observable(100000.0)

julia> u0 = vcat(S0, I0, V0)
3-element Vector{Observable}:
 Observable(100000.0)
 Observable(0)
 Observable(100000.0)

julia> U0 = @lift(vcat(S0, I0, V0))
ERROR: Did not find any interpolated observables. Use '$(observable)' to interpolate it into the macro.
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:35
  [2] var"@lift"( __source__ ::LineNumberNode, __module__ ::Module, exp::Any)
    @ Makie ~/.julia/packages/Makie/VRavR/src/interaction/liftmacro.jl:77
  [3] eval
    @ ./boot.jl:385 [inlined]
  [4] eval
    @ ./Base.jl:88 [inlined]
  [5] repleval(m::Module, code::Expr, ::String)
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.73.2/scripts/packages/VSCodeServer/src/repl.jl:229
  [6] (::VSCodeServer.var"#110#112"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.73.2/scripts/packages/VSCodeServer/src/repl.jl:192
  [7] with_logstate(f::Function, logstate::Any)
    @ Base.CoreLogging ./logging.jl:515
  [8] with_logger
    @ ./logging.jl:627 [inlined]
  [9] (::VSCodeServer.var"#109#111"{Module, Expr, REPL.LineEditREPL, REPL.LineEdit.Prompt})()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.73.2/scripts/packages/VSCodeServer/src/repl.jl:193
 [10] #invokelatest#2
    @ ./essentials.jl:892 [inlined]
 [11] invokelatest(::Any)
    @ Base ./essentials.jl:889
 [12] (::VSCodeServer.var"#62#63")()
    @ VSCodeServer ~/.vscode/extensions/julialang.language-julia-1.73.2/scripts/packages/VSCodeServer/src/eval.jl:34

julia> U0 = $(vcat(S0, I0, V0))
ERROR: syntax: "$" expression outside quote around REPL[23]:1
Stacktrace:
 [1] top-level scope
   @ REPL[23]:1

julia> U0 = '$(vcat(S0, I0, V0))'
ERROR: ParseError:
# Error @ REPL[24]:1:7
U0 = '$(vcat(S0, I0, V0))'
# └─────────────────┘ ── character literal contains multiple characters
Stacktrace:
 [1] top-level scope
   @ none:1

```

How can I set vectors of observables for ODE solved with `DifferentialEquations`?

---

<div class="post-metadata">

### Author: ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)
#### Post date: [March 1, 2024, 1:21pm UTC](https://discourse.julialang.org/t/how-to-make-a-vector-of-observables-in-glmakie/111012/2 "2024-03-01T13:21:25Z")

</div>

I don’t think you can directly use a vector of `Observable`’s as states in `DifferentialEquations` but you can use an `Observable` of a vector with `lift`.

> [@Luigi\_Marongiu](#):
>
> ```julia
> julia> U0 = @lift(vcat(S0, I0, V0))
> ERROR: Did not find any interpolated observables. Use '$(observable)' to interpolate it into the macro.
> 
> ```

Error also explains what the solution might be. Interpolation in this context means a `julia` syntactical sugar for replacing by value in `julia` expression ref: [Metaprogramming · The Julia Language](https://docs.julialang.org/en/v1/manual/metaprogramming/#man-expression-interpolation)

```julia
julia> U0 = @lift(vcat($S0, $I0, $V0))
Observable([100000.0, 0.0, 100000.0])

```

For using in conjunction with `DifferentialEquations`, you can look at ref: [Observables & Interaction · Makie](https://docs.makie.org/stable/explanations/nodes/#chaining_observables_with_lift)

---

<div class="post-metadata">

### Author: ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)
#### Post date: [March 1, 2024, 2:22pm UTC](https://discourse.julialang.org/t/how-to-make-a-vector-of-observables-in-glmakie/111012/3 "2024-03-01T14:22:00Z")

</div>

> [@tomaklutfu](#):
>
> `U0 = @lift(vcat($S0, $I0, $V0))`

Thanks!
