Page 298 - Applied Numerical Methods Using MATLAB
P. 298

BOUNDARY VALUE PROBLEM (BVP)  287

             %nm654.m
             % to solve a stiff differential eqn called Van der Pol equation
             global mu
             mu=25, t0=0; tf = 100; tspan = [t0 tf]; xo = [2 0];
             [tH1,xH1] = ode_Ham(’df_van’,tspan,x0,8700);
             subplot(221), plot(tH1,xH1)
             tic,[tH2,xH2] = ode_Ham(’df_van’,tspan,x0,9000); time_Ham = toc
             tic,[t45,x45] = ode45(’df_van’,tspan,x0); time_o45 = toc
             subplot(222), plot(tH2,xH2), subplot(223), plot(t45,x45)
             mu = 200; tf = 200; tspan = [t0 tf];
             tic,[t45,x45] = ode45(’df_van’,tspan,x0); time(1) = toc;
             tic,[t23,x23] = ode23(’df_van’,tspan,x0); time(2) = toc;
             tic,[t15s,x15s] = ode15s(’df_van’,tspan,x0); time(3) = toc;
             tic,[t23s,x23s] = ode23s(’df_van’,tspan,x0); time(4) = toc;
             tic,[t23t,x23t] = ode23t(’df_van’,tspan,x0); time(5) = toc;
             tic,[t23tb,x23tb] = ode23tb(’df_van’,tspan,x0); time(6) = toc;
             plot(t45,x45, t23,x23, t15s,x15s, t23s,x23s, t23t,x23t, t23tb,x23tb)
             disp(’ ode23  ode15s  ode23s  ode23t  ode23tb’)
             time
             function dx = df_van(t,x)
             %Van der Pol differential equation (6.5.27)
             global mu
             dx=zeros(size(x));
             dx(1) = x(2); dx(2) = mu*(1-x(1).^2).*x(2) - x(1);



            6.6  BOUNDARY VALUE PROBLEM (BVP)

            A boundary value problem (BVP) is an Nth-order differential equation with some
            of the values of dependent variable x(t) and its derivative specified at the initial
            time t 0 and others specified at the final time t f .

                                                        (2)

                     [BVP] N :   x (N) (t) = f(t, x(t),x (t), x (t), ...,x (N−1) (t))

             with the boundary values x(t 1 ) = x 10 ,x (t 2 ) = x 21 ,..., x (N−1)  (t N ) = x N,N−1
                                                                         (6.6.1)
            In some cases, some relations between the initial values and the final values may
            be given as a mixed-boundary condition instead of the initial/final values spec-
            ified. This section covers the shooting method and the finite difference method
            that can be used to solve a second-order BVP as



               [BVP] 2 : x (t) = f(t, x(t), x (t))  with x(t 0 ) = x 0 ,x(t f ) = x f  (6.6.2)
            6.6.1 Shooting Method

            The idea of this method is to assume the value of x (t 0 ), then solve the differential
            equation (IVP) with the initial condition [x(t 0 )x (t 0 )] and keep adjusting the value
   293   294   295   296   297   298   299   300   301   302   303