# Initial Guess for Bvp4c

12 views (last 30 days)
Joao Graca on 16 Jul 2014
Edited: Mark Brandon on 22 Dec 2018
Hello!
I´m trying to solve a BVP, but i don´t know how to use an array of points as an initial guess. Let me explain: I have 4 1st order diff equation. If i use something like
init = bvpint([0 1],[0 0 0 0])
Matlab acepts, but of course do not converse. But i have 2 vectors, one for the mesh (800x1) and one for the initial guess (800x4). Let me call the mesh X, and the initial guess V. If i try
init = bvpint(X,[0 0 0 0])
it´s ok. But if i try
init = bvpint(X,V)
it gives an error: "THE GUESS FOR THE SOLUTION MUST RETURN A VECTOR".
I already tried a lot of combinations, but till now i have been unable to load an 800x4 vector as my initial guess. Can somebody helps me???
Thx!

Mark Brandon on 22 Dec 2018
Edited: Mark Brandon on 22 Dec 2018
This is an old question (2014), but it represents an issue that probably continues to puzzle others (including me today).
The documentation is missing an important clue, in that bvp functions need to be able to remeshing the independent variable x. Thus, one cannot use indexing to relate x to the deriative of the dependent variable, (y, dy, d2y, etc.). This rule holds for the initial guess, and for the ode function (containing the system of differential equations) and the residual function (containing the boundary conditions) as well.
That said, one can use anonymous functions to allow for general relationships between x and the y derivatives (see the bvpinit documentation for details). Let me illustrate with an example:
init = bvpint(X,V),
try:
%row vector xV0, and matrix V0 with column vectors for each element of xV0
init = bvpint(X, @(x) interp1(xV0, V0, x))
@(x) indicates that this is anonymous function. interp1 will provide interpolates for the column vector of derivatives at the specified x.
Similar arrangements are needed for handling calculations involving x in the ode and and residual functions.