Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Simple_Differential_Equation.ipynb #92

Merged
merged 1 commit into from Sep 2, 2016

Conversation

jpfairbanks
Copy link
Contributor

Avoid using start as a variable in example

Avoid using `start` as a variable
@jpfairbanks
Copy link
Contributor Author

I went through this example and got this error if we avoid the variable start it shouldn't happen.

julia> ode45(f, start, trange)
ERROR: MethodError: `/` has no method matching /(::Function, ::Float64)
Closest candidates are:
  /(::Float64, ::Float64)
  /(::Complex{T<:Real}, ::Real)
  /(::BigFloat, ::Union{Float16,Float32,Float64})
  ...
 in make_consistent_types at /home/james/.julia/v0.4/ODE/src/ODE.jl:124
 in oderk_fixed at /home/james/.julia/v0.4/ODE/src/runge_kutta.jl:180
 in oderk_fixed at /home/james/.julia/v0.4/ODE/src/runge_kutta.jl:168
 in ode45 at /home/james/.julia/v0.4/ODE/src/runge_kutta.jl:163

@acroy
Copy link
Contributor

acroy commented Mar 12, 2016

Using start as a variable shouldn't cause problems. Did you try to restart julia?

In any case it is good practice to post a complete example (possibly including the versions of Julia and ODE), which shows the error. If I do the following in Julia v0.4 and ODE v0.2.1:

using ODE

function f(t, y)
           # Extract the components of the y vector
           (x, v) = y

           # Our system of differential equations
           x_prime = v
           v_prime = -x

           # Return the derivatives as a vector
           [x_prime; v_prime]
end

const start = [0.0; 0.1]
time = 0:0.1:4*pi

t, y = ode45(f, start, time);

There is no problem:

julia> y[end]
2-element Array{Float64,1}:
 -0.00663187
  0.0997793 
julia> t[end]
12.5

@pjpmarques
Copy link
Contributor

Hi. Any conclusion on this? start shouldn't be the cause of the problem.

@ChrisRackauckas
Copy link
Member

start may not be the cause of the problem due to ODE, but having a variable named start can easily cause problems in other cases. @jpfairbanks probably had a problem due to something defining an array interface (which is why the error is due to a function).

Because these are so common, it's a good idea to not have start as a variable in an example since it has a common other use and is thus begging for trouble. Changing the name to starty is harmless but gets rid of any possibility of this overlap. I'll wait for a second opinion but vote to merge.

@pwl @acroy @mauro3 ?

@ChrisRackauckas
Copy link
Member

Given the +1's and that it's pretty harmless, I'm merging.

@ChrisRackauckas ChrisRackauckas merged commit 0d1a3d1 into SciML:master Sep 2, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants