Skip to content

Instantly share code, notes, and snippets.

@natschil
Created May 23, 2018 11:42
Show Gist options
  • Save natschil/df58395c01c54c8a4c4a4dd1cd13d6b6 to your computer and use it in GitHub Desktop.
Save natschil/df58395c01c54c8a4c4a4dd1cd13d6b6 to your computer and use it in GitHub Desktop.
Implicit Euler Example
using DiffEqOperators
using OrdinaryDiffEq
A = -10*speye(3)
M = speye(3)
num_steps = 1
function update_A(A,u,p,t)
global num_steps+=1
A .= -10*speye(3)*t
end
L = DiffEqArrayOperator(A,1.0,update_A)
prob = ODEProblem(L, [1.0,1.0,1.0], (0.0,1.0),mass_matrix=M)
u = solve(prob ,ImplicitEuler(autodiff=false),
progress=true,dt=1e-1,adaptive=false)
num_steps
num_steps2=1
function update_A2(A2,u,p,t)
global num_steps2 +=1
end
L2 = DiffEqArrayOperator(A,1.0,update_A2)
prob2 = ODEProblem(L2, [1.0,1.0,1.0], (0.0,1.0),mass_matrix=M)
num_steps2
u = solve(prob2 ,ImplicitEuler(autodiff=false),
dt=1e-1,adaptive=false)
print("Took $num_steps for first run and $num_steps2 for second")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment