# How to analyze sensitivity w.r.t. the initial values?

**URL:** <https://discourse.julialang.org/t/how-to-analyze-sensitivity-w-r-t-the-initial-values/107580>\
**Category:** Numerics\
**Tags:** diffeq, sciml, differentialequation\
**Created:** [December 13, 2023, 7:35pm UTC](https://discourse.julialang.org/t/how-to-analyze-sensitivity-w-r-t-the-initial-values/107580 "2023-12-13T19:35:06Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![contradict](https://avatars.discourse-cdn.com/v4/letter/c/ac91a4/32.png) [@contradict](https://discourse.julialang.org/u/contradict)\
**Post date:** [December 13, 2023, 8:51pm UTC](https://discourse.julialang.org/t/how-to-analyze-sensitivity-w-r-t-the-initial-values/107580/2 "2023-12-13T20:51:12Z")

</div>

The problem seems to be that the Float64 variable `loss` defined inside the function `loss` is overwriting the function. So at line 34, when preparing the optimization problem to calculate the loss, `loss` refers to the value of the loss, not the function to compute it. Placing the definition of the function `loss` in at the top level instead of inside the function `get_iv`, marking that value as an explicit local

```julia
     local loss
     loss = sum(abs2, sol.u[end] - target)
     return loss, sol

```

or renaming the Float64 value to something else (for example `lss = sum(abs2, sol.u[end] - target)`) all restore the behavior you hoped for.

---

_[View the full topic](https://discourse.julialang.org/t/how-to-analyze-sensitivity-w-r-t-the-initial-values/107580)._
