# Instability diffeq

**URL:** <https://discourse.julialang.org/t/instability-diffeq/69062>\
**Category:** General Usage\
**Tags:** diffeq\
**Created:** [October 1, 2021, 5:16pm UTC](https://discourse.julialang.org/t/instability-diffeq/69062 "2021-10-01T17:16:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jorge\_Silva](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jorge_silva/32/14976_2.png) [@Jorge\_Silva](https://discourse.julialang.org/u/Jorge_Silva)\
**Post date:** [October 1, 2021, 5:16pm UTC](https://discourse.julialang.org/t/instability-diffeq/69062/1 "2021-10-01T17:16:26Z")

</div>

I have a system with a dependent mass matrix. It always return me some mensage of instability. Is it an intrisic characteristic of the system?  
Any thing I can do about?

```julia
using DifferentialEquations
 
    alpha=0.105
    N0 = 5
    Ar=2

    Eeq=(1.0+N0)/(2.0*N0)+((9.0+6.0*N0+9.0*N0^2.0)^0.5/6.0/N0)

    function update_func(A,u,p,t)
        
        E = (9*N0-(u[1]+u[2]+u[3]))/(9*N0-3*(u[1]+u[2]+u[3]))
        
        De = 0.1 
        
        A[1,1] = De*u[5]
        A[1,2] = 0
        A[1,3] = 0
        A[1,4] = 0
        A[1,5] = -2*De*u[1]
        A[1,6] = 0

        A[2,1] = 0
        A[2,2] = De*u[5]
        A[2,3] = 0
        A[2,4] = -2*De*u[1]*u[5]/u[4]
        A[2,5] = 0
        A[2,6] = 0

        A[3,1] = 0
        A[3,2] = 0
        A[3,3] = De*u[5]
        A[3,4] = 0
        A[3,5] = 0
        A[3,6] = -2*De*u[3]*u[5]/u[6]

        A[4,1] = 0
        A[4,2] = 0    
        A[4,3] = 0    
        A[4,4] = 1.
        A[4,5] = 0    
        A[4,6] = 0  
        
        A[5,1] = 0
        A[5,2] = 0
        A[5,3] = 0
        A[5,4] = 1/u[4]
        A[5,5] = 1/u[5]
        A[5,6] = 1/u[6]

        A[6,1] = 1/(u[1]-u[3]) + 2*N0/E/(3*N0-u[1]-u[2]-u[3])^2
        A[6,2] = 2*N0/E/(3*N0-u[1]-u[2]-u[3])^2
        A[6,3] = -1/(u[1]-u[3]) + 2*N0/E/(3*N0-u[1]-u[2]-u[3])^2
        A[6,4] = 1/u[4]
        A[6,5] = 0    
        A[6,6] = 1/u[6]

    end

    function casting(du,u,p,t)

        E = (9*N0-(u[1]+u[2]+u[3]))/(9*N0-3*(u[1]+u[2]+u[3]))

        kx = ((1.0-alpha)+alpha*E*u[1])*(1-E*u[1])
        ky = ((1.0-alpha)+alpha*E*u[2])*(1-E*u[2])
        kz = ((1.0-alpha)+alpha*E*u[3])*(1-E*u[3])

        du[1] = kx
        du[2] = ky
        du[3] = kz
        du[4] = -Ar*((u[2]-u[3])/(u[1]-u[3]))^(1/2)
        du[5] = 0
        du[6] = 0

        nothing    

    end
    
    
    guess = 2

    uu0 = [guess; 1/Eeq; 1/Eeq; 1.0; 1.0; 1.0]
    

    M = DiffEqArrayOperator(ones(6,6),update_func=update_func)
    tspan = (0, 1.0)
    prob = ODEProblem(ODEFunction(casting, mass_matrix=M), uu0, tspan)
    sol = solve(prob,Rodas5())

```

```julia
┌ Warning: Instability detected. Aborting
└ @ SciMLBase C:\Users\jorgem63\.julia\packages\SciMLBase\n3U0M\src\integrator_interface.jl:351
retcode: Unstable
Interpolation: 3rd order Hermite
t: 1-element Vector{Float64}:
 0.0
u: 1-element Vector{Vector{Float64}}:
 [2.0, 0.8759615953640396, 0.8759615953640396, 1.0, 1.0, 1.0]

```

---

<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:** [October 1, 2021, 6:09pm UTC](https://discourse.julialang.org/t/instability-diffeq/69062/2 "2021-10-01T18:09:26Z")

</div>

Do you do everything mentioned 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…

Note dependent mass matrices are less stably handled by Rosenbrock methods, so did you try DAEProblem with IDA?
