JuliaMath / Calculus.jl

Calculus functions in Julia
Other
278 stars 76 forks source link

Error while determining the derivative at end points #126

Closed mstiitb closed 6 years ago

mstiitb commented 6 years ago

I am new to Julia and so please pardon if the following is too trivial. I am solving an ODE and I am interested in the derivative and second derivative of the solution. In my problem, I need the derivatives as they go into the RHS of a second ODE. There is one way coupling between the two sets of ODEs.

I tried using Calculus.derivative(u,x) etc in the second ODE, where x is a vector and u is the solution from the first ODE. I get the error:"Solution interpolation cannot extrapolate before the first timepoint. Either start solving earlier or use the local extrapolation from the integrator interface.".

I am guessing that the derivative is being calculated at the first point using central differences and hence the problem (we do not know the solution for x<x0 for x-range from x0 to xf). Is there a way of extrapolating the derivative calculated at points close to x0 (and a similar procedure at the end point) while the derivative at rest of the points are determined using central differences? The error message is suggesting a way using the "integrator interface" but I do not understand this very well.

I just checked with a similar function in MATLAB and it appears that the "gradient" function there calculates the central difference numerical derivative, except at the edges or ends, where it calculates a one-sided derivative. Is this an issue here?

PS: I have raised the same issue under JuliaMath/DifferentialEquations.jl. I am not sure which of the two places is the right one for this question.

mstiitb commented 6 years ago

ChrisRackauckas just informed me that there is an elegant way of doing this: sol(t,Val{i}) Details are on: http://docs.juliadiffeq.org/latest/basics/solution.html#Interpolations-1