You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.
function f(t,v,p):
(x,y) = v
dx_dt = p[1]_x - x_y
dy_dt = p[2]_x_y -y
return [dx_dt,dy_dt]
end
But ode45 does not accept my function f (as it needs to get another argument p)
If I define f without p, then how can I pass p to the function?
I need to run ode45 many times, each time with different values for p.
I've tried doing something like this:
function run_ode(f,t,v,pars)
p = pars
(times,data) = ode45(f,t,v) #here f is defined with only 2 arguments f(t,v)
return data
end
but p does not change and it keeps running with the same values.
I've also tried setting
f1(t,v) = f(t,v,p) and then running ode45(f1,t,v) but it didn't work either
(this was following the suggestion in SciML/Sundials.jl#3)
Can you please suggest how to pass the arguments in p?
The text was updated successfully, but these errors were encountered:
For now, it's probably easiest to use closures like @mauro3 mentioned. That will have good performance and will work right now. Just to repeat:
g = (t,v) ->f(t,v,p)
will take a function with parameters f and give you g which doesn't have them, and then you can use that g with odexx. That's the and accepted answer for now and will work. I will close this since this issue is answered.
Probably should just give the full response if you're curious. This got an extensive answer in SciML/Roadmap#2. You could also use call overloading like:
type TestFunc
a::Float64
b::Float64end
f =TestFunc(0.0,0.0) # Parameters are specified here, can make a new function with the same constructor
(p::TestFunc)(t,v) =begin
(x,y) = v
dx_dt = p.a*x - x*y
dy_dt = p.b*x*y -y
return [dx_dt,dy_dt]
end
Specifying a function in this form is made easier with ParameterizedFunctions.jl. However, the one that ParameterizedFunctions.jl specifies requires a slightly different function API (an in-place update, will be more performant) which will be introduced when #49 is merged (i.e. it won't work with ODE.jl right now, but it will when ODE.jl updates). Note that this extra functionality will not necessarily be needed for ODE.jl, but will be compatible with it.
Hi,
My intergration is over the function:
function f(t,v,p):
(x,y) = v
dx_dt = p[1]_x - x_y
dy_dt = p[2]_x_y -y
return [dx_dt,dy_dt]
end
But ode45 does not accept my function f (as it needs to get another argument p)
If I define f without p, then how can I pass p to the function?
I need to run ode45 many times, each time with different values for p.
I've tried doing something like this:
function run_ode(f,t,v,pars)
p = pars
(times,data) = ode45(f,t,v) #here f is defined with only 2 arguments f(t,v)
return data
end
but p does not change and it keeps running with the same values.
I've also tried setting
f1(t,v) = f(t,v,p) and then running ode45(f1,t,v) but it didn't work either
(this was following the suggestion in SciML/Sundials.jl#3)
Can you please suggest how to pass the arguments in p?
The text was updated successfully, but these errors were encountered: