# Time Series sensitivity analysis for multiple outputs

**URL:** <https://discourse.julialang.org/t/time-series-sensitivity-analysis-for-multiple-outputs/80631>\
**Category:** Modelling & Simulations\
**Created:** [May 6, 2022, 5:36pm UTC](https://discourse.julialang.org/t/time-series-sensitivity-analysis-for-multiple-outputs/80631 "2022-05-06T17:36:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xztt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xztt/32/33843_2.png) [@xztt](https://discourse.julialang.org/u/xztt)\
**Post date:** [May 6, 2022, 5:36pm UTC](https://discourse.julialang.org/t/time-series-sensitivity-analysis-for-multiple-outputs/80631/1 "2022-05-06T17:36:43Z")

</div>

Hi,

```julia
function circ_local_time(x)
    _prob = remake(prob,u0=x[1:3],p=x[4:end])
    sol = solve(_prob,Tsit5(), reltol=1e-6, abstol=1e-6,saveat=savetime)
    sol[LV.p]
end

St = ForwardDiff.jacobian(circ_local_time,[u0;p])
x = LinRange(0,1,100)
plot(x,St[:,12])

```

When I run the above code I can see how the sensitivity of the parameter changes during a cycle. However, when I add another output eg

```julia
function circ_local_time(x)
    _prob = remake(prob,u0=x[1:3],p=x[4:end])
    sol = solve(_prob,Tsit5(), reltol=1e-6, abstol=1e-6,saveat=savetime)
    [sol[LV.p], **sol[LV.V]]**
end

St = ForwardDiff.jacobian(circ_local_time,[u0;p])
x = LinRange(0,1,100)
plot(x,St[:,12])

```

the output St is  
`2×12 Matrix{Vector{ForwardDiff.Dual{ForwardDiff.Tag{typeof(circ_local_time), Float64}, Float64, 12}}}`

Which I am not sure I fully understand what this is saying to me.

Any help appreciated 🙂

Cheers,  
Harry

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [May 6, 2022, 7:54pm UTC](https://discourse.julialang.org/t/time-series-sensitivity-analysis-for-multiple-outputs/80631/2 "2022-05-06T19:54:43Z")

</div>

> [@xztt](#):
>
> `[sol[LV.p], sol[LV.V]]`

The issue is that this is a matrix of vectors, which ForwardDiff doesn’t know how to easily handle. So it just gives you that matrix of vectors of duals (I’m surprised it didn’t error). `[sol[LV.p]; sol[LV.V]]` is a vector, and that should give a standard matrix Jacobian that would then resize.

For reference:

```julia
julia> a = [1.0,2.0]
2-element Vector{Float64}:
 1.0
 2.0

julia> b = [3.0,4.0]
2-element Vector{Float64}:
 3.0
 4.0

julia> [a,b]
2-element Vector{Vector{Float64}}:
 [1.0, 2.0]
 [3.0, 4.0]

julia> [a;b]
4-element Vector{Float64}:
 1.0
 2.0
 3.0
 4.0

julia> [a b]
2×2 Matrix{Float64}:
 1.0 3.0
 2.0 4.0

```
