# Derivative for a set of ... points

**URL:** <https://discourse.julialang.org/t/derivative-for-a-set-of-points/57286>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [March 16, 2021, 9:45am UTC](https://discourse.julialang.org/t/derivative-for-a-set-of-points/57286 "2021-03-16T09:45:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frederic\_Gilt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frederic_gilt/32/13807_2.png) [@Frederic\_Gilt](https://discourse.julialang.org/u/Frederic_Gilt)\
**Post date:** [March 16, 2021, 9:45am UTC](https://discourse.julialang.org/t/derivative-for-a-set-of-points/57286/1 "2021-03-16T09:45:55Z")

</div>

Dear all,  
I am successfully playing with

```julia
sol = solve(ensembleprob,SRIW1(),EnsembleThreads(),trajectories=ϕ,saveat=δt);

```

which generates a nice set of values. Among those values `sol[1,:,:];` is a position, `sol[2,:,:];` a velocity.  
unfortunately, I need an acceleration…  
how can I nicely proceed ?  
thx !  
Frédéric

---

<div class="post-metadata">

**Author:** ![Frederic\_Gilt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frederic_gilt/32/13807_2.png) [@Frederic\_Gilt](https://discourse.julialang.org/u/Frederic_Gilt)\
**Post date:** [March 16, 2021, 2:26pm UTC](https://discourse.julialang.org/t/derivative-for-a-set-of-points/57286/2 "2021-03-16T14:26:28Z")

</div>

auto-reply 🙂  
here is my idea :

```julia
kt = sol[9,:,16]

```

60001-element Array{Float64,1}:

with \delta t = 0.01 then

```julia
lmnt = length(kt)
kt_t = Vector{Float64}(undef,lmnt);
for i in 1:lmnt kt_t[i] = (i-1)*δt end;
@time kt_acc = ForwardDiff.gradient(kt, kt_t)

```

MethodError: objects of type Array{Float64,1} are not callable  
Use square brackets for indexing an Array.

where am I wrong ??  
Thx !  
Frédéric

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [March 16, 2021, 2:36pm UTC](https://discourse.julialang.org/t/derivative-for-a-set-of-points/57286/3 "2021-03-16T14:36:15Z")

</div>

@Frederic_Gilt, you may want to take a look at this [discourse thread](https://discourse.julialang.org/t/best-way-to-take-derivatives-of-unevenly-spaced-data-with-interpolations-discrete-derivatives/54097).

---

<div class="post-metadata">

**Author:** ![Frederic\_Gilt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frederic_gilt/32/13807_2.png) [@Frederic\_Gilt](https://discourse.julialang.org/u/Frederic_Gilt)\
**Post date:** [March 16, 2021, 3:06pm UTC](https://discourse.julialang.org/t/derivative-for-a-set-of-points/57286/4 "2021-03-16T15:06:33Z")

</div>

thx for the link, but `kt` is solution of SDE (white noise forcing term) so I want to avoid interpolation then derivation.  
I was hoping ForwardDiff to be able to help me on this

---

<div class="post-metadata">

**Author:** ![Frederic\_Gilt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frederic_gilt/32/13807_2.png) [@Frederic\_Gilt](https://discourse.julialang.org/u/Frederic_Gilt)\
**Post date:** [March 16, 2021, 3:45pm UTC](https://discourse.julialang.org/t/derivative-for-a-set-of-points/57286/5 "2021-03-16T15:45:34Z")

</div>

(re)auto-reply  
`kt` is not a function (callable I guess ?) so not suitable for ForwardDiff… my bad ! 🤔

now shifting to FiniteDifferences package… but once again exemples are for functions (!) 🤨  
anyone with a simple exemple of FiniteDifferences use with data only (data = kt, time = kt\_t)  
Thx a lot !

---

<div class="post-metadata">

**Author:** ![Frederic\_Gilt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frederic_gilt/32/13807_2.png) [@Frederic\_Gilt](https://discourse.julialang.org/u/Frederic_Gilt)\
**Post date:** [March 16, 2021, 5:17pm UTC](https://discourse.julialang.org/t/derivative-for-a-set-of-points/57286/6 "2021-03-16T17:17:33Z")

</div>

sadly ended with a five-point stencil scheme :

```julia
for i in 3:(lmnt-2) 
    kt_a[i] = (-kt[i+2]+8*kt[i+1]-8*kt[i-1]+kt[i-2])/(12*δt)
end;

```

🙄
