Mathematics Previous page   Next Page

Solving PDE Problems

This section describes:

Example: A Single PDE

This example illustrates the straightforward formulation, solution, and plotting of the solution of a single PDE

This equation holds on an interval 0 less than or equal x less thanor equal 1 for times t greater than or equal to 0. At t = 0, the solution satisfies the initial condition

At x = 0 and x = 1, the solution satisfies the boundary conditions

  1. Rewrite the PDE. Write the PDE in the form
  1. This is the form shown in Equation 5-3 and expected by pdepe. See Introduction to PDE Problems for more information. For this example, the resulting equation is

  1. with parameter m = 0 and the terms

  1. Code the PDE. Once you rewrite the PDE in the form shown above (Equation 5-3) and identify the terms, you can code the PDE in a function that pdepe can use. The function must be of the form
  1. where c, f, and s correspond to the c, f, and s terms. The code below computes c, f, and s for the example problem.

  1. Code the initial conditions function. You must code the initial conditions in a function of the form
  1. The code below represents the initial conditions in the function pdex1ic.

  1. Code the boundary conditions function. You must also code the boundary conditions in a function of the form
  1. The boundary conditions, written in the same form as Equation 5-5, are

  1. and

  1. The code below evaluates the components p(x, t ,u) and q(x, t) of the boundary conditions in the function pdex1bc.

    In the function pdex1bc, pl and ql correspond to the left boundary conditions (x = 0), and pr and qr correspond to the right boundary condition (x = 1).

  1. Select mesh points for the solution. Before you use the MATLAB PDE solver, you need to specify the mesh points (t, x) at which you want pdepe to evaluate the solution. Specify the points as vectors t and x.
  1. The vectors t and x play different roles in the solver (see MATLAB Partial Differential Equation Solver). In particular, the cost and the accuracy of the solution depend strongly on the length of the vector x. However, the computation is much less sensitive to the values in the vector t.

    This example requests the solution on the mesh produced by 20 equally spaced points from the spatial interval [0,1] and five values of t from the time interval [0,2].

  1. Apply the PDE solver. The example calls pdepe with m = 0, the functions pdex1pde, pdex1ic, and pdex1bc, and the mesh defined by x and t at which pdepe is to evaluate the solution. The pdepe function returns the numerical solution in a three-dimensional array sol, where sol(i,j,k) approximates the kth component of the solution, u sub k, evaluated at t(i) and x(j).
  1. This example uses @ to pass pdex1pde, pdex1ic, and pdex1bc as function handles to pdepe.

  1. View the results. Complete the example by displaying the results:
    1. Extract and display the first solution component. In this example, the solution u has only one component, but for illustrative purposes, the example "extracts" it from the three-dimensional array. The surface plot shows the behavior of the solution.
      •     u = sol(:,:,1);
            
            surf(x,t,u)    
            title('Numerical solution computed with 20 mesh points')
            xlabel('Distance x')
            ylabel('Time t')
        

        plot of numerical solution computed with 20 mesh points

    2. Display a solution profile at t sub f, the final value of t. In this example, t sub f 
    3. 2. See Evaluating the Solution at Specific Points for more information.
      •     figure
            plot(x,u(end,:))
            title('Solution at t = 2')
            xlabel('Distance x')
            ylabel('u(x,2)')
        

        plot of solution at t = 2


Previous page  MATLAB Partial Differential Equation Solver Evaluating the Solution at Specific Points Next page

© 1994-2005 The MathWorks, Inc.