# Can't get the preconditioners to work for ode problem

**URL:** <https://discourse.julialang.org/t/cant-get-the-preconditioners-to-work-for-ode-problem/85782>\
**Category:** General Usage\
**Tags:** ode, differentialequation\
**Created:** [August 15, 2022, 2:42pm UTC](https://discourse.julialang.org/t/cant-get-the-preconditioners-to-work-for-ode-problem/85782 "2022-08-15T14:42:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shashank](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shashank/32/12323_2.png) [@Shashank](https://discourse.julialang.org/u/Shashank)\
**Post date:** [August 15, 2022, 2:42pm UTC](https://discourse.julialang.org/t/cant-get-the-preconditioners-to-work-for-ode-problem/85782/1 "2022-08-15T14:42:24Z")

</div>

I have been trying to learn how to use preconditioners while solving an ode but I get an error, and I don’t understand what I am doing wrong. I followed the tutorial on [Solving Large Stiff Equations · DifferentialEquations.jl](https://diffeq.sciml.ai/stable/tutorials/advanced_ode_example/) and tried to implement it in a minimal working example. The code is pasted below:

```julia

using DifferentialEquations
using LinearSolve
using LinearAlgebra
#using SparseArrays
using DelimitedFiles
using IncompleteLU
using Plots

function incompletelu(W,du,u,p,t,newW,Plprev,Prprev,solverdata)
  if newW === nothing || newW
    Pl = ilu(convert(AbstractMatrix,W), τ = 50.0)
  else
    Pl = Plprev
  end
  Pl,nothing
end

Base.eltype(::IncompleteLU.ILUFactorization{Tv,Ti}) where {Tv,Ti} = Tv

function eoms!(du,u,p,t)
    for i in 1:3
        du[i]=-p[i]*u[i]
    end
end
u0=ones(Float64,3)
tol=1e-8
reltolp=tol
abstolp=tol
tspan=(0,1)
p=[1,2,3]
prob=ODEProblem(eoms!,u0,tspan,p)
@time sol=solve(prob,KenCarp4(linsolve=KrylovJL_GMRES(),precs=incompletelu,concrete_jac=true),abstol=abstolp,reltol=reltolp,saveat=0.1)

#plot(sol,vars=(1))
#plot!(sol,vars=(2))
#plot!(sol,vars=(3))

```

However, when I run the code I get an error:

```julia
ERROR: LoadError: MethodError: no method matching ilu(::Matrix{Float64}; τ=50.0)
Closest candidates are:
  ilu(::SparseArrays.SparseMatrixCSC{ATv, Ti}; τ) where {ATv, Ti} at ~/.julia/packages/IncompleteLU/UBpTh/src/crout_ilu.jl:9

```

Has anyone who has encountered this problem or used preconditioners please help me?

---

<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:** [August 15, 2022, 6:32pm UTC](https://discourse.julialang.org/t/cant-get-the-preconditioners-to-work-for-ode-problem/85782/2 "2022-08-15T18:32:33Z")

</div>

> [@Shashank](#):
>
> ```julia
> ERROR: LoadError: MethodError: no method matching ilu(::Matrix{Float64}; τ=50.0)
> 
> ```

You cannot apply `iLU` to a dense Jacobian. Define a sparse Jacobian like is done in the tutorial.
