%
%   PICARD.M    Sample Problem to Illustrate Picard's Iteration Method
%
%   Evaluate and compare solutions to the following initial value problem (IVP):
%         y' - y = 2x   with  y(0) = 1
%   
%   Picard's result:  y0(x) = 1
%                     y1(x) = 1 + x + x^2
%                     y2(x) = 1 + x +(3x^2)/2 +(x^3)/3
%
%   Exact Solution:    y(x) = 3*exp(x) - 2x -2
%
%   File prepared by J. R. White, UMass-Lowell (July 2003)
%

%
%   getting started
      clear all,  close all,  nfig = 0;
%
%   set x domain
      x = linspace(0,1,51);
%
%   evaluate various Picard estimates of order 0, 1, and 2
      y0 = ones(size(x));
      y1 = 1 + x + x.*x;
      y2 = 1 + x + (3/2)*x.*x + (1/3)*x.*x.*x;
%
%   evaluate exact solution
      ye = 3*exp(x) - 2*x - 2;
%
%   plot comparisons
      v = [0 1 .5 4.5];
      nfig = nfig+1;  figure(nfig)   
      plot(x,y0,x,y1,x,y2,x,ye,'LineWidth',2),axis(v)
      title('Picard:  Example of the Picard Iteration Method')
      xlabel('x values'),ylabel('y(x)'),grid
      gtext('0th order'),gtext('1st order'),gtext('2nd order')
      gtext('exact soln')
%
%   end of demo