function slide = odedemo
%ODEDEMO  Slideshow file for use with playshow.m and makeshow.m
%   To see it run, type 'playshow odedemo', 

%   Copyright 1984-2000 The MathWorks, Inc. 
%   $Revision: 1.14 $

if nargout<1,
  playshow odedemo
else
  
  %========== Slide 1 ==========

  slide(1).code = {
      'xptext('''','''','''','''',''Solving Differential Equations in MATLAB'')';
  }; 
  slide(1).text={
      '',
      '',
      ' Initial Value Problems',
      '',
      ' Boundary Value Problems',
      '',
      ' Partial Differential Equations '
  };
  
  %========== Slide 2 ==========

  slide(2).code={
      ['xptext('''',''Initial Value Problem for ODEs '', '...
       ' '''',''van der Pol equation with a parameter \mu = Mu'', '...
       ' '''',''          {y}\prime\prime - \mu(1-y^{2}){y}\prime + y = 0 '', '...
       ' '''',''Initial conditions:    y(0)=2,  y\prime{(0)}=0 '')']};
  slide(2).text={
   '',
   '',
   ['The equation, written as a system of two first order ODEs, is evaluated '...
    'in functions vdp1 for Mu = 1 and vdp1000 for Mu = 1000. '],
   '',
   'To examine vdp1, use the command',
   '',
   '>> type vdp1;'};

  %========== Slide 3 ==========

  slide(3).code={   
      ['xptext('''','' function dydt = vdp1(t,y) '', '...
       ' '' %VDP1  Evaluate van der Pol ODEs, Mu = 1'', '...       
       ' '''','' dydt = [           y(2) '', '...
       ' ''           (1-y(1)\^2)*y(2)-y(1) ]; '') ']};
  slide(3).text={
   '',
   ['For Mu = 1, the van der Pol equation can be solved efficiently with '...
    'any of the MATLAB ODE solvers. We use ode45 to solve this problem on '...
    'the interval [0 20]'],
   '',
   '>>  tspan = [0, 20];',
   '>>  y0 = [2; 0];',
   '>>  [t,y] = ode45(@vdp1, tspan, y0);'};

  %========== Slide 4 ==========

  slide(4).code={   
   '  tspan = [0, 20];',
   '  y0 = [2; 0];',
   '  [t,y] = ode45(@vdp1,tspan,y0);',
   '  plot(t,y(:,1));',
   '  xlabel(''t'')',
   '  ylabel(''solution y'')',
   '  title(''van der Pol Equation, \mu = 1'')'	};
  slide(4).text={
   '',
   '',
   'The solution is plotted with',
   '',
   '>>  plot(t,y(:,1))',
   '>>  xlabel(''t'')',
   '>>  ylabel(''solution y'')',
   '>>  title(''van der Pol Equation, \mu = 1'')'};

  %========== Slide 5 ==========

  slide(5).code={
   'tspan = [0, 3000];',
   'y0 = [2; 0];',
   '[t,y] = ode15s(@vdp1000,tspan,y0);',
   'plot(t,y(:,1))',
   'title(''van der Pol Equation, \mu = 1000'')',
   'axis([0 3000 -3 3])',
   'xlabel(''t'')',
   'ylabel(''solution y'')'};
  slide(5).text={
   ['As the parameter increases, the problem becomes stiff and special '...
    'numerical methods are required. Among the MATLAB ODE solvers, ode15s, '...
    'ode23s, ode23t, and ode23tb can solve stiff problems efficiently. '],
    '',
    'We use ode15s to solve the van der Pol equation for Mu = 1000 and plot as before',
    ''
    '>>  [t,y] = ode15s(@vdp1000, [0 3000], [2; 0]);'};
  
  %========== Slide 6 ==========

  slide(6).code={
      ['xptext('''','' Boundary Value Problem for ODEs '', '...
       ' '''','' The differential equation '', '...
       ' '''',''          {y}\prime\prime + |y| = 0 '', '...
       ' '''','' Boundary conditions:  y(0) = 0, y(4) = -2 '')']};
  slide(6).text={
   '',
   '',
   ['The differential equation, written as a system of two first order '...
    'ODEs, is evaluated in the function twoode. The residual in the boundary '...
    'conditions is evaluated in twobc.'],
   '',
   'To examine twoode, use the command',
   '',
   '>>  type twoode;'};

  %========== Slide 7 ==========

  slide(7).code={
      ['xptext('''','' Boundary Value Problem for ODEs '', '...
       ' '''','' The differential equation '', '...
       ' '''',''          {y}\prime\prime + |y| = 0 '', '...
       ' '''','' Boundary conditions:   y(0)=0,  y(4)=-2 '')']};
  slide(7).text={   
   ['We have to provide a guess for the solution we want and a mesh '...
    'that shows roughly how the solution behaves. The solver then '...
    'adapts the mesh as it computes a solution near the guess.'],
    '',
   ['The guesses are provided to bvp4c as a structure that is formed '...
    'with bvpinit. For a mesh of [0, 1, 2, 3, 4] and a constant '...
    'guess of y(x) = 1, y''(x) = 0, use'],
   ''
   '>>  solinit = bvpinit([0 1 2 3 4],[1; 0]);'};

  %========== Slide 8 ==========
            
  slide(8).code={      
   'solinit = bvpinit([0 1 2 3 4],[1; 0]);',
   'sol = bvp4c(@twoode,@twobc,solinit);',
   'xint = linspace(0,4,50);',
   'yint = bvpval(sol,xint);',
   'plot(xint,yint(1,:),''b'');',
   'xlabel(''x'')',
   'ylabel(''solution y'')',
   'hold on'};
  slide(8).text={
   'After an initial guess is constructed, the problem is solved with',
   '',
   '>>  sol = bvp4c(@twoode, @twobc, solinit);',
   '',
   'The solution sol is then evaluated at points xint using bvpval and plotted',
   '>>  xint = linspace(0, 4, 50);',
   '>>  yint = bvpval(sol, xint);',
   '>>  plot(xint, yint(1,:));'};

  %========== Slide 9 ==========
            
  slide(9).code={      
   'solinit = bvpinit([0 1 2 3 4],[-1; 0]);',
   'sol = bvp4c(@twoode,@twobc,solinit);',
   'xint = linspace(0,4,50);',
   'yint = bvpval(sol,xint);',
   'plot(xint,yint(1,:),''r'');',
   'hold off'};
  slide(9).text={
   '',
   '',   
   ['This particular boundary value problem has exactly two solutions. '...
    'The other solution is obtained for an initial guess of y(x) = -1, '...
    'y''(x) = 0 and plotted as before'],
   '',
   '>>  solinit = bvpinit([0 1 2 3 4],[-1; 0]);',
   '>>  sol = bvp4c(@twoode,@twobc,solinit);'};

  %========== Slide 10 ==========
  
  slide(10).code={
      ['xptext('' Initial-Boundary Value Problem for PDEs '', '...
       ' '''','' Partial differential equation '', '...
       ' '''',''          \pi^2 {\partial}u/{\partial}t = {\partial^2}u/{\partial}x^2'', '...
       ' '''','' Initial condition    u(x,0) = sin(\pi{x}) '', '...
       ' '' Boundary conditions  u(0,t) = 0, '', '...
       ' ''                      \pi{exp(-t)}+{\partial}u(1,t)/{\partial}t=0'')']};
  
  slide(10).text={
   ['pdepe solves partial differential equations in one space variable '...
    'and time. To learn about the form of PDEs that can be solved with '...
    'pdepe, use the command'],
   '',
   '>>  doc pdepe',
   '',
   ['The examples pdex1, pdex2, pdex3, pdex4, pdex5 read in order form a '...
    'mini-tutorial on using pdepe. This example problem uses functions '...
    'pdex1pde, pdex1ic, and pdex1bc.']};

  %========== Slide 11 ==========
  
  slide(11).code={
   'x = linspace(0,1,20);',
   't = [0 0.5 1 1.5 2];',
   'sol = pdepe(0,@pdex1pde,@pdex1ic,@pdex1bc,x,t);', 
   'u1 = sol(:,:,1);',
   'surf(x,t,u1);',
   'xlabel(''x'')',
   'ylabel(''t'')',
   'zlabel(''u'')',
   'hold on'};
  slide(11).text={
   '',
   ['pdepe requires the user to specify the spatial discretization '...
    '(as a vector of nodes), and a vector of values of t, at which '...
    'the solution is requested. We solve this problem using a mesh '...
    'of 20 nodes and request the solution at five values of t'],
   '',
   '>>  x = linspace(0,1,20);',
   '>>  t = [0 0.5 1 1.5 2];',
   '>>  sol = pdepe(0,@pdex1pde,@pdex1ic,@pdex1bc,x,t);'};
  
  %========== Slide 12 ==========
  
  slide(12).code={
    'hold off'};
  slide(12).text={
   '',
   'The first component of the solution is extracted',
   '',
   '>>  u1 = sol(:,:,1);',
   ''
   'and plotted ',
   '',
   '>>  surf(x,t,u1);',
   '>>  xlabel(''x''); ylabel(''t''); zlabel(''u'')'};

end
