These are chat archives for JuliaLang/Interact.jl

22nd
Feb 2018
jsschlosser
@jsschlosser
Feb 22 2018 02:06
``````using Interact
using DifferentialEquations
using Latexify
using Plots
gr()

"""
A function which simulates and plots an ODE.

The system is first equilibrated for an input value of 1.
The plotted dynamics is the relaxation of the system after the input is changed to 10.
"""
function plotODE(ode::AbstractParameterizedFunction, parameters, plotvars)
set_param_values!(ode, parameters)
ode.input = 1.
u0 = fill(1., length(ode.syms))
u0 = solve(ssprob).u

tspan = (0.,10.)
ode.input = 10.
prob = ODEProblem(ode, u0, tspan)
sol = solve(prob, solver=Rosenbrock23())

plot(sol, vars=plotvars, xlabel="Time", ylabel="Concentration", ylims=[0.,-Inf])
end

"""
Automatically generate sliders for all the ODE's parameters and map the results
to the plotODE function.
"""
function interactivePlot(ode::AbstractParameterizedFunction)
display(latexalign(ode))
params = [slider(-2:0.1:2, label=latexify("\$p"), value=log10(getfield(ode, p)))
for p in ode.params]
plotvars = selection(ode.syms, multi=true)

display(hbox(vbox(params[2:end]...), plotvars))

map((x...)->plotODE(ode, 10. .^collect(x[1:end-1]), x[end]),
signal.(params)..., signal(plotvars))
end

"""
Define some ODEs
"""

input=1.0
r_x=>1.0
e_x=>1.0
r_y=>1.0
e_y=>1.0

ode1 = @ode_def negativeFeedback begin
dx = r_x * (e_x * input * y - x)
dy = r_y * (e_y / x - y)
end

ode2 = @ode_def incoherentFeedForward begin
dx = r_x * (e_x * input - x)
dy = r_y * (e_y * input / x - y)
end``````
``interactivePlot(ode2)``
I have tried this code and I get:
``````UndefVarError: set_param_values! not defined

Stacktrace:
[1] plotODE at .\In[13]:14 [inlined]
[2] (::##46#49{incoherentFeedForward})(::Array{Any,1}, ::Vararg{Array{Any,1},N} where N) at .\In[13]:40
[3] map(::Function, ::Reactive.Signal{Array{Any,1}}) at C:\Users\Joseph\.julia\v0.6\Reactive\src\operators.jl:32
[4] interactivePlot(::incoherentFeedForward) at .\In[13]:40