4

I am playing around with the Julia ODE module. I solve a simple Newtonian mechanics equation, involving an inclined plane. For convenience (because I did so when I solved it analytically) I rotate my axes so that ex follows the plane, and ey is normal to it. When displaying the solution, though, I'd like to rotate it back so that ey coincides with the direction of gravity.

Now, pulling out my position vectors from the solution object is not a problem (although my method might not be very idiomatic), nor is plotting them. But doing so, I lose the nice magic that comes with plotting the solution directly. Is there a way to apply my rotation directly to the solution object, so it still behaves like a functor with ready to roll interpolation and the like?

Passing my functions definitions, I run this:

prob = ODEProblem(pfm!, u0, tspan, (g, alpha))
cb = ContinuousCallback(condition, affect!)
sol = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8, callback=cb)

When plotting sol:

Nice interpolation

When getting the position vector out before hand with

pos = hcat(sol.u...)[[1, 2], :]

I get

No interpolation

And the not-much-more existing solution after manual rotation with

pos = rot_mat * hcat(sol.u...)[[1, 2], :]

produces

No interpolation, rotated

Aubergine
  • 368
  • 3
  • 12
  • 2
    You want to interpolate the solution before applying something to its values because it did not require very many steps to actually solve the system. – Chris Rackauckas Aug 28 '21 at 12:44

0 Answers0