function pn = pell_number ( n )

%*****************************************************************************80
%
%% pell_number() returns the N-th Pell number.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    13 December 2023
%
%  Author:
%
%   John Burkardt
%
%  Input:
%
%    integer n: the index, which must be 0 or greater.
%
%  Output:
%
%    integer pn: the N-th Pell number.
%
  if ( n < 0 )
    error ( 'pell_number(): Fatal error!\n' );
  end

  for m = 0 : n

    if ( m == 0 ) 
      pn = 0;
    elseif ( m == 1 )
      pnm1 = pn;
      pn = 1;
    else
      pnm2 = pnm1;
      pnm1 = pn;
      pn = 2 * pnm1 + pnm2;
    end

  end

  return
end
