Hello
So I have this function -
function late_time_value(slope, x_init::Float64, y_init::Float64, dx::Float64 = 0.01, tf::Float64 = 100)
N = floor(Integer, tf/dt)
sol_x = zeros(N)
sol_y = zeros(N)
sol_x[1] = x_init
sol_y[1] = y_init
for i in 1:N-1
sol_x[i+1] = sol_x[i] + dx
sol_y[i+1] = sol_y[i] + slope(sol_y[i]) * dx
end
return sol_x, sol_y
end
And for slope
I passed in a function slope
defined as slope(x) = sin(x)
. But Julia throws this error -
julia> late_time_value(slope, 0., 0.5)
MethodError: no method matching late_time_value(::typeof(slope), ::Float64, ::Float64, ::Float64, ::Int64)
Closest candidates are:
late_time_value(::Any, ::Float64, ::Float64, ::Float64) at In[5]:1
late_time_value(::Any, ::Float64, ::Float64, ::Float64, !Matched::Float64) at In[5]:1
late_time_value(::Any, ::Float64, ::Float64) at In[5]:1
Stacktrace:
[1] late_time_value(slope::Function, x_init::Float64, y_init::Float64)
@ Main ./In[5]:2
[2] top-level scope
@ In[8]:1
[3] eval
@ ./boot.jl:360 [inlined]
[4] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1090
However when I do something a bit more simple it works.
julia> function f(s)
return s()
end
f (generic function with 1 method)
julia> g() = 2
g (generic function with 1 method)
julia> f(g)
2
What’s going on here? I would appreciate any help