Of course, I recall that ODE45 has no capability to apply equality constraints at the end point, as that would make it a BVP solver, which it is not. So that you failed to gain a solution is not in the least surprising.

So, perhaps you mean that you tried to specify the boundary prediction from the ODE solver as a constraint in the optimization. Could this worK? Possibly, IF you coded it all correctly. Would it be any gain? Probably not, even if you managed to do it all right.

It probably won't work as well as just using the BVP solver as it is designed to work. It may make your optimization less stable. And because you are adding one or more NONLINEAR equality constraints to the optimization, it will certainly slow down the search process. This is because the optimizer needs to ride along a curved manifold in the solution space that represents the equality constraint. Yes, the locus of of parameters that satisfies the boundary constraint will almost certainly be some curved surface in the parameter space. And that takes extra work in the optimization. Probably more function evaluations. And since it will need to differentiate the constraint too, EXTRA ODE45 calls will be needed. On top of all that, making ODE45 into a BVP solver will introduce extra variables into the optimization problem, so the optimizer will be doing more work.

Sorry, but there is no such thing as a free lunch here.

## Best Answer