function segment = p07_boundary_segment ( segment_index, m, segment_length )

%*****************************************************************************80
%
%% p07_boundary_segment returns a boundary segment in problem 07.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    12 April 2009
%
%  Author:
%
%    John Burkardt
%
%  Reference:
%
%    Per-Olof Persson and Gilbert Strang,
%    A Simple Mesh Generator in MATLAB,
%    SIAM Review,
%    Volume 46, Number 2, June 2004, pages 329-345.
%
%  Input:
%
%    integer SEGMENT_INDEX, the index of the boundary segment.
%
%    integer M, the spatial dimension.
%
%    integer SEGMENT_length, the number of points in the segment.
%
%  Output:
%
%    SEGMENT(M,SEGMENT_length), points on the boundary segment.
%
  if ( segment_index == 1 )

    n1 = floor ( ( segment_length - 3 ) / 2 );
    n2 = segment_length - 3 - n1;

    c = 2.5 * pi;

    x_lo = -c;
    x_hi =  c;

    j = 0;

    j = j + 1;
    x = x_lo;
    y = 0.0;
    segment(1:2,j) = [ x, y ]';

    for i = 1 : n1
      x = ( ( n1 - i + 1 ) * x_lo   ...
          + (      i     ) * x_hi ) ...
          / ( n1     + 1 );
      y = cos ( x );
      j = j + 1;
      segment(1:2,j) = [ x, y ]';
    end

    j = j + 1;
    x = x_hi;
    y = 0.0;
    segment(1:2,j) = [ x, y ]';

    for i = 1 : n2
      x = ( ( n2 - i + 1 ) * x_hi   ...
          + (      i     ) * x_lo ) ...
          / ( n2     + 1 );
      y = 5.0 * ( x / c )^4 - 5.0;
      j = j + 1;
      segment(1:2,j) = [ x, y ]';
    end

    j = j + 1;
    x = x_lo;
    y = 0.0;
    segment(1:2,j) = [ x, y ]';

  else

    fprintf ( 1, '\n' );
    fprintf ( 1, 'P07_boundary_segment - Fatal error!\n' );
    fprintf ( 1, '  Illegal SEGMENT_INDEX = %d\n', segment_index );
    error ( 'P07_boundary_segment - Fatal error!' );

  end

  return
end

