# How do I solve a boundary value ODE in MATLAB?

Specifically, ode15i. I have ode15i solving a system of 5 first order implicit odes in 5 variables with an initial condition (made consistent by decic). It's great for what I need, except I need to add a final condition as well. Is this possible? I think (but am not sure) ode15s works too.

Edit: -

Edit 2: I think I figured it out. I'm going to make dummy variables for all the derivatives, add in a bunch of extra equations, and that should make the equations "explicit" so I can use bvp4c.

• Just to clarify, you have $y(0)$ as the initial condition and you also need that $y(T)$ be the specified value from your application. – Daryl Jul 23 '13 at 21:04
• Would you mind providing more details – Paul Renton Jul 23 '13 at 21:26
• We are going to need more datails. Unless there are tunable parameters in your equations (or you initial conditions) the equations are over-determined. – Godric Seer Jul 23 '13 at 22:52
• What details do you need? The five variables are all functions of t, and I would like to set (only one or two) of them with a boundary condition at a set time t. – Samuel Reid Jul 23 '13 at 22:58
• Are you simply asking to stop the solver when/if $y(t)$ reaches a critical value, or are you saying that $y(t)$ must reach that critical value at a set time? The former isn't a boundary condition but rather a special termination condition (that can easily be handled with MATLAB's ODE solvers.) – Brian Borchers Jul 23 '13 at 22:59

The MATLAB routines starting with 'ode', like ode15i, are for solving initial value problems. If you want to solve a boundary value problem, use bvp4c or bvp5c.

• The problem is, bvp4c and bvp5c are only for explicit equations. My equations are all very much implicit. – Samuel Reid Jul 24 '13 at 16:54
• In order to make your question useful to others, could you please write down one of your BVPs? This will make it clear what you mean by "implicit". – David Ketcheson Jul 24 '13 at 23:15

I assume that you want to solve $$f(t,y',y)=0 \text{ on } (0,T)$$ with two-point boundary values $$y(0)=\alpha \text{ and } y(T)=\beta.$$

You cannot simply apply ODE solvers to this problen unless you take the heuristic approach of forward-backward iteration (see the list below).

There is no general approach to these boundary value problems. And I don't didn't know of any built-in function in Matlab that solves these boundary value problems even for the case with $y' = \tilde f (t,y)$.

[EDIT: There are matlab functions for solving these semi-explicit two point boundary value problems, see David Ketcheson's answer, that use finite differences and collocation. ]

To solve the problem you have the following options:

• Finite Differences: Discretize the interval $[0,T]$, if necessary do a collocation, and solve the resulting algebraic system
• (Multiple) Shooting: parametrize the boundary conditions and solve for the parameters
• Decoupling: split the variables so that there is one initial value problem, and one terminal value, i.e. backward in time initial value, problem. In the linear case this is commonly referred to as Riccati decoupling
• Fixed-point Iteration: this is the most heuristic approach. For example, you can try to guess the missing intial values, integrate forward in time, set the part of the terminal value to the given values, integrate backward in time, and so on...

The standard reference for these problems is the book by Ascher, Mattheij, & Russell: Numerical solution of boundary value problems for ordinary differential equations. However, implicit problems are not considered there.

• Hello, thank you for the answer! I've actually heard of all of these methods. I know finite differences is horrible for accuracy, and shooting isn't good if the system is unstable (which mine is). It's also a system of five implicit odes, and I'm having a lot of trouble finding resources on this kind of question. Any idea where I could? I'm guessing my question has all the annoying words in it, "multiple equations", "implicit", "boundary conditions" etc. and that's why it's so difficult. – Samuel Reid Jul 24 '13 at 16:34
• @SamuelReid: Perhaps you could state the system of ODEs and boundary conditions you'd like to impose in an edit to the question so that people can be more helpful. – Bill Barth Jul 24 '13 at 17:05
• @BillBarth: Sure. – Samuel Reid Jul 24 '13 at 17:09