# Make a variable as a global variable within a function

**URL:** <https://discourse.julialang.org/t/make-a-variable-as-a-global-variable-within-a-function/63067>\
**Category:** New to Julia\
**Tags:** macros\
**Created:** [June 17, 2021, 6:29am UTC](https://discourse.julialang.org/t/make-a-variable-as-a-global-variable-within-a-function/63067 "2021-06-17T06:29:58Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

**Author:** ![jonniedie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonniedie/32/12842_2.png) [@jonniedie](https://discourse.julialang.org/u/jonniedie)\
**Post date:** [June 17, 2021, 2:23pm UTC](https://discourse.julialang.org/t/make-a-variable-as-a-global-variable-within-a-function/63067/14 "2021-06-17T14:23:09Z")

</div>

From here:

> [@PSA: How to help yourself debug differential equation solving issues](https://discourse.julialang.org/t/psa-how-to-help-yourself-debug-differential-equation-solving-issues/62489):
>
> Debugging differential equation solver issues almost always boils down to doing the same thing, so this is a summary to help you out. For more information on specific issues, check out the FAQ section of the DifferentialEquations.jl documentation which highlights common issues and questions: [https://diffeq.sciml.ai/dev/basics/faq/](https://diffeq.sciml.ai/dev/basics/faq/)How do I debug why the differential equation solver is diverging? dt \<= dtmin. Aborting. There is either an error in your model specification or the true solution i…

> - Double check if you’re doing anything that violates assumptions of being an ODE. As an ODE, the right-hand side `f` function should always give you the same result: `u' = f(u,p,t)` needs to be uniquely defined. These issues are just fundamental to the mathematics: if you do these things in `f` , then `f` no longer defines an ODE so of course it cannot be solved!
> - If you put randomness into `f` , then the adaptivity will think your ODE is being solved at a high error because the derivative keeps changing, and therefore it will fail and hit `dtmin` trying to reduce the randomness to zero (if you do need randomness, use an SDE or RODE solver).
> - If your `f` function is modifying `u` , then calling `f` with different stepsizes is not deterministic and the solver is likely to fail. If you need to do this, you should be using a callback.
> - If your `f` function is caching values from a previous step, just think about what this means. If you change `dt` , then you’re changing `f` . In that sense, `u'` is no longer defined since it’s now dependent on how it’s being solved! Even worse, adaptive ODE solvers do not always move forwards in time: sometimes they try `t + dt1` before trying `t + dt2` and choosing what to do. So if you’re assuming that the cached values are from the last step, that’s not actually the case: those values can be coming from a fake (too incorrect according to error estimates) future!

---

_[View the full topic](https://discourse.julialang.org/t/make-a-variable-as-a-global-variable-within-a-function/63067)._
