Mathematics Previous page   Next Page

Solving BVP Problems

This section describes:

Example: Mathieu's Equation

This example determines the fourth eigenvalue of Mathieu's Equation. It illustrates how to write second-order differential equations as a system of two first-order ODEs and how to use bvp4c to determine an unknown parameter lambda.

The task is to compute the fourth (q = 5) eigenvalue lambda of Mathieu's equation

Because the unknown parameter lambda is present, this second-order differential equation is subject to three boundary conditions

  1. Rewrite the problem as a first-order system. To use bvp4c, you must rewrite the equations as an equivalent system of first-order differential equations. Using a substitution y sub 1 = y and y sub 2 = y prime, the differential equation is written as a system of two first-order equations
  1. Note that the differential equations depend on the unknown parameter lambda. The boundary conditions become

  1. Code the system of first-order ODEs. Once you represent the equation as a first-order system, you can code it as a function that bvp4c can use. Because there is an unknown parameter, the function must be of the form
  1. The following code represents the system in the function, mat4ode. Variable q is shared with the outer function:

    See Finding Unknown Parameters for more information about using unknown parameters with bvp4c.

  1. Code the boundary conditions function. You must also code the boundary conditions in a function. Because there is an unknown parameter, the function must be of the form
  1. The code below represents the boundary conditions in the function, mat4bc.

  1. Create an initial guess. To form the guess structure solinit with bvpinit, you need to provide initial guesses for both the solution and the unknown parameter.
  1. The function mat4init provides an initial guess for the solution. mat4init uses y = cosine 4 x because this function satisfies the boundary conditions and has the correct qualitative behavior (the correct number of sign changes).

    In the call to bvpinit, the third argument, lambda, provides an initial guess for the unknown parameter lambda.

    This example uses @ to pass mat4init as a function handle to bvpinit.

  1. Apply the BVP solver. The mat4bvp example calls bvp4c with the functions mat4ode and mat4bc and the structure solinit created with bvpinit.
  2. View the results. Complete the example by displaying the results:
    1. Print the value of the unknown parameter lambda found by bvp4c.
      •     fprintf('The fourth eigenvalue is approximately %7.3f.\n',...
                    sol.parameters)
        
    2. Use deval to evaluate the numerical solution at 100 equally spaced points in the interval [0, pi], and plot its first component. This component approximates y(x).
      •     xint = linspace(0,pi);
            Sxint = deval(sol,xint);
            plot(xint,Sxint(1,:))
            axis([0 pi -1 1.1])
            title('Eigenfunction of Mathieu''s equation.') 
            xlabel('x')
            ylabel('solution y')
        

Finding Unknown Parameters

The bvp4c solver can find unknown parameters p for problems of the form

You must provide bvp4c an initial guess for any unknown parameters in the vector solinit.parameters. When you call bvpinit to create the structure solinit, specify the initial guess as a vector in the additional argument parameters.

The bvp4c function arguments odefun and bcfun must each have a third argument.

While solving the differential equations, bvp4c adjusts the value of unknown parameters to satisfy the boundary conditions. The solver returns the final values of these unknown parameters in sol.parameters. See Example: Mathieu's Equation.

Evaluating the Solution at Specific Points

The collocation method implemented in bvp4c produces a C1-continuous solution over the whole interval of integration . You can evaluate the approximate solution, , at any point in using the helper function deval and the structure sol returned by bvp4c.

The deval function is vectorized. For a vector xint, the ith column of Sxint approximates the solution .


Previous page  Boundary Value Problem Solver Using Continuation to Make a Good Initial Guess Next page

© 1994-2005 The MathWorks, Inc.