Reputation: 17131
Is this the right way to write a spring mass damper system in julia using DifferentialEquations.jl?
function smd(du, u, p, t)
c, k, m = p
du[1] = dx = u[2]
du[2] = dv = -(c/m)*u[2] - (k/m)*u[1]
end
tspan = (0.0, 1.0);
u0 = [0; 0];
p = [10, 1, 10]
prob = ODEProblem(smd, u0, tspan, p)
sol = solve(prob, Tsit5(), tstops=[1.0])
plot(sol.t, vecvec_to_mat(sol)[:, 1])
Upvotes: 0
Views: 42
Reputation: 6398
dx
and dv
are never used, but other than that, this looks fine.
Upvotes: 0