Clear Filters
Clear Filters

What does it represent the second vector in solinit?

4 views (last 30 days)
Elia Paini
Elia Paini on 28 Apr 2021
Answered: Shubham on 22 May 2024 at 8:22
Hi, I solved a system of ODEs second order with BCs with bvp4c.
I have 8 variables (4 are the functions I'm interested, y(x), the others are the 4 derivatives dy/dx).
After defining the vector xmesh, I have to insert the second vector, which should be represent the initial guess.
solinit = bvpinit(xmesh,[0,0,0,0,1,1,1,1]);
However, I don't know how the second vector should be inserted to obtain a good solution. It seems that its values poorly change the final solution, but I don't understand their meanings.
I've already read the guide, but I haven't found the answer.
Thak you all!

Answers (1)

Shubham
Shubham on 22 May 2024 at 8:22
Hi Elia,
In MATLAB, when solving Boundary Value Problems (BVPs) for Ordinary Differential Equations (ODEs) using bvp4c, the initial guess plays a crucial role in guiding the solver towards a solution. The function bvpinit is used to specify this initial guess. Understanding how to set up this guess effectively can be pivotal in obtaining accurate and reliable solutions, especially for complex systems with multiple variables.
Understanding bvpinit
The bvpinit function initializes the solution structure for bvp4c. Its syntax is:
solinit = bvpinit(xmesh, init_guess);
  • xmesh: This is a vector of points where you want the solution to be estimated. For a start, this doesn't have to be very dense, as bvp4c will adaptively refine this mesh to meet the solution tolerance requirements. However, it should span the entire interval over which you are solving the BVP.
  • init_guess: This is a vector (or a function handle returning a vector) providing an initial guess for the values of the solution at the points in xmesh. For a system of equations, this vector should include guesses for each of the variables in the system, including the derivatives if they are part of the system being solved.
Setting Up the Initial Guess
For a system with 4 functions and their 4 derivatives (making it 8 variables in total), your initial guess vector will have 8 elements. Each element corresponds to an initial guess for one of the variables at each point in xmesh.
  • The first 4 elements should be your initial guesses for the functions (y(x)) you're interested in.
  • The next 4 elements are for the derivatives of these functions, .
The choice of initial guess can indeed affect the solver’s ability to find a solution, especially in nonlinear problems or problems with multiple solutions. Here's how to think about setting the initial guess:
  1. Physical Insight: Any knowledge about the physical system or phenomenon being modeled can guide what a reasonable guess might be. For instance, if you know the functions should be positive or have certain symmetries, you can incorporate this into your guess.
  2. Simplicity: Start with simple functions or constants that satisfy the boundary conditions if possible. For example, if you know the boundary values of your functions, using these as constant guesses or linear interpolations between boundary values can be a good start.
  3. Function Handle for Varying Guesses: If a constant initial guess is insufficient, you can use a function handle that returns varying initial guesses across the domain. This is particularly useful if you expect the solution to vary significantly across the domain.
init_guess = @(x) [f1(x); f2(x); f3(x); f4(x); df1(x); df2(x); df3(x); df4(x)];
solinit = bvpinit(xmesh, init_guess);
  1. Here, f1(x) to f4(x) could be your guesses for the functions, and df1(x) to df4(x) for their derivatives. These don't have to be accurate solutions; rough approximations that capture the expected behavior can significantly help the solver.
  2. Iterative Refinement: If the first attempt doesn't yield a satisfactory solution, refine your initial guess based on the output. Sometimes, examining the solver's attempt can provide insights into how to adjust your guess.
  3. Solver Options: Beyond the initial guess, tweaking solver options like tolerances (AbsTol, RelTol) can also help achieve convergence.
I hope this helps!

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!