Hi. I have this code I am trying to make for graphing the trajectory of a thrown baton. The script involves a mass matrix (of the baton) being multiplied by dydt to show its trajectory.
My problem comes from the use of the name of the mass matrix, ‘M’ and the name of the solution, ‘sol’. Every time I close and re-open Julia it suddenly doesn’t recognise ‘M’ or ‘sol.t’ or ‘sol.u’ but once I figure it out it doesn’t have a problem identifying them.
Here is the code:
P = Dict(:m1 => 0.1, :m2 => 0.1, :L => 1, :g => 9.81)
params = (0.1, 0.1, 1.0, 9.81)
function dydt(du,u,p,t)
m1, m2, L, g = p
du[1] = u[2]
du[2] = m2*L*u[6]^2*cos(u[5])
du[3] = u[4]
du[4] = m2*L*u[6]^2*sin(u[5])-(m1 + m2)*g
du[5] = u[6]
du[6] = -g*L*cos(u[5])
nothing # This is to specify the default jacobian
end
function mass(t, u, P)
M = [1.0 0 0 0 0 0;
0 P[:m1] + P[:m2] 0 0 0 -P[:m2]*P[:L]*sin(sol.u[1][5]);
0 0 1 0 0 0;
0 0 0 P[:m1]+P[:m2] 0 P[:m2]*P[:L]*cos(sol.u[1][5]);
0 0 0 0 1 0;
0 -P[:L]*sin(u[1][5]) 0 P[:L]*cos(u[1][5]) 0 P[:L]^2]
return M
end
Smotion = ODEFunction(dydt,mass_matrix=M)
prob_mm = ODEProblem(Smotion,[6.0,0.0,0.0,0.0,0.0,0.0],(0,35),(0.04,3e7,1))
sol = solve(prob_mm,Rodas5(),reltol=1e-28,abstol=1e-8)