Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README example should use interpolation instead of indexing #107

Open
ErikQQY opened this issue Sep 3, 2023 · 5 comments · May be fixed by #208
Open

README example should use interpolation instead of indexing #107

ErikQQY opened this issue Sep 3, 2023 · 5 comments · May be fixed by #208

Comments

@ErikQQY
Copy link
Member

ErikQQY commented Sep 3, 2023

While trying MIRK solvers and Shooting solvers with example problem in README, the two kinds of solvers gave two different solutions:

using BoundaryValueDiffEq, OrdinaryDiffEq
function simplependulum!(du, u, p, t)
    θ = u[1]
    dθ = u[2]
    du[1] = dθ
    du[2] = -9.81 * sin(θ)
end
function bc!(residual, u, p, t)
    residual[1] = u[end ÷ 2][1] + pi / 2
    residual[2] = u[end][1] - pi / 2
end
tspan = (0.0, pi / 2)
prob = BVProblem(simplependulum!, bc!, [pi / 2, pi / 2], tspan)
mirk_sol = solve(prob, MIRK4(), dt = 0.05)
shooting_sol = solve(prob, Shooting(Tsit5()), dt=0.05)

Solution from MIRK(Correct):

mirk_sol

Solution from Shooting(Wrong):

shooting_sol

@ChrisRackauckas
Copy link
Member

The issue is more that the model is a bit nonsense and you're not testing what the model is actually saying. You're testing that the value in the middle has a value, i.e.:

function bc!(residual, u, p, t)
    residual[1] = u(0.75)[1] + pi / 2
    residual[2] = u[end][1] - pi / 2
end

But that's not the model. The model is that the middle of the solve array is pi / 2. But the solver time steps are adaptive, so there's no guarantee that u(0.75) == u[end ÷ 2], nor should one ever expect that to be true. We should just change this example to use interpolation.

@ErikQQY
Copy link
Member Author

ErikQQY commented Sep 3, 2023

The issue is more that the model is a bit nonsense and you're not testing what the model is actually saying.

Yeah, we should not expect the value in the middle to be the same since the adaptive time steppings, but the two solutions from different solvers are quite different, I think there is something wrong about this, especially the shooting method.

@ChrisRackauckas
Copy link
Member

There's nothing wrong about the solutions. The bc! is just not a good definition. Change the bc!.

@ErikQQY
Copy link
Member Author

ErikQQY commented Sep 3, 2023

Oh I see, I will propose a better example for the detailed usage of BVP solvers.

We should just change this example to use interpolation.

I remembered OrdinaryDiffEq.jl can use interpolations, is there some text we can refer to add this feature to MIRK solvers?

@ErikQQY ErikQQY closed this as completed Sep 3, 2023
@ChrisRackauckas
Copy link
Member

No, this is a good example, it's just that every multi-point example should use interpolation.

is there some text we can refer to add this feature to MIRK solvers?

The MIRK solvers already define the interpolation for the residual calculation.

@ChrisRackauckas ChrisRackauckas changed the title Shooting method gives wrong result for the example in README README example should use interpolation instead of indexing Sep 3, 2023
@ErikQQY ErikQQY linked a pull request Aug 19, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants