#! /usr/bin/env python
#
def w_polynomial_zeros ( n ):

#*****************************************************************************80
#
## W_POLYNOMIAL_ZEROS returns zeroes of the Chebyshev polynomial W(n,x).
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    12 July 2015
#
#  Author:
#
#    John Burkardt
#
#  Parameters:
#
#    Input, integer N, the order of the polynomial.
#
#    Output, real Z(N), the zeroes.
#
  import numpy as np

  z = np.zeros ( n )

  for i in range ( 0, n ):
    angle = float ( 2 * n - 2 * i ) * np.pi / float ( 2 * n + 1 )
    z[i] = np.cos ( angle )

  return z

def w_polynomial_zeros_test ( ):

#*****************************************************************************80
#
## W_POLYNOMIAL_ZEROS_TEST tests W_POLYNOMIAL_ZEROS.
#
#  Licensing:
#
#    This code is distributed under the GNU LGPL license.
#
#  Modified:
#
#    12 July 2015
#
#  Author:
#
#    John Burkardt
#
  import platform
  from w_polynomial import w_polynomial

  print ( '' )
  print ( 'W_POLYNOMIAL_ZEROS_TEST:' )
  print ( '  Python version: %s' % ( platform.python_version ( ) ) )
  print ( '  W_POLYNOMIAL_ZEROS computes the zeros of W(n,x)' )
  print ( '' )
  print ( '     N      X         W(n,x)' )

  for n in range ( 0, 6 ):

    x = w_polynomial_zeros ( n )
    fx = w_polynomial ( n, n + 1, x )

    print ( '' )
    for i in range ( 0, n ):
      print ( '  %4d  %8.4g  %14.6g' % ( i, x[i], fx[i,n] ) )
#
#  Terminate.
#
  print ( '' )
  print ( 'W_POLYNOMIAL_ZEROS_TEST:' )
  print ( '  Normal end of execution.' )
  return

if ( __name__ == '__main__' ):
  from timestamp import timestamp
  timestamp ( )
  w_polynomial_zeros_test ( )
  timestamp ( )