# Problem with stiff ODE solved by Julia

There’s an ODE to be solved. It’s a chemical reaction system. There is 863 reactions and 230 species. The system is quite stiff and large. So I ues some algorithms advised by Solving Large Stiff Equations · DifferentialEquations.jl. I tried every algorithms, but the values never change at each step. In another word, the ODE solver cannot catch the small change.

So I wanna to know how I can sovle such ODE system. I just want to make the values change, so the time efficiency can be considered later.

Thanks.

This almost ceratinly means you coded your function incorrectly. if I had to guess, it would be that you used the in place form of `f(du, u, p, t)` but didn’t update `du`, but it’s hard to say for sure without seeing the code.

Here is the code. It seems du will update. Whatever algorithm I try, the value will not change.

``````function crnn(du,c,k,t)
c = reshape(c,(230,1))
k = reshape(k,(863,1))
log_r = w_in * @.log(clamp(c,1e-35,1e15))
log_r = log_r +  @.log(clamp(k,1e-35,1e15))
r = @.exp(log_r);
du = w_out' * r;
return du;
end

using Symbolics
tspan = [0,1]
du0 = copy(conc[1,:])
jac_sparsity = Symbolics.jacobian_sparsity((du,u)-> crnn(du,u,k[1,:],0.0),du0,conc[1,:])
f = ODEFunction(crnn;jac_prototype=float.(jac_sparsity))
prob = ODEProblem(f, conc[1,:], tspan, k[1,:])
sol = solve(prob,KenCarp47(linsolve=KrylovJL_GMRES()))
for i in 1:230
println(sol.u[i] - sol.u[i])
end``````
1 Like

Yeah. My guess was correct. You need `du .= w_out' * r;` Julia uses “pass by sharing” so when you say `du = ...` you aren’t changing `du` you’re just making a new `du`. Also the `return `du` isn’t doing anything here since you’re using the in-place formulation.

4 Likes