% g = gegenbauer(K,n,t)
%
% find the n-th K-dimensional Gegenbauer polynomial value at t
%
% this version, based on mfun, is for R2012 and other early Matlab releases
%   mfun is deprecated and probably has already disappeared in recent releases
%   replace mfun('G',n,a,t) with gegenbauerC(n,a,t) [untested] for late rel.

function g = gegenbauer(K,n,t)
  %% new versions of Matlab
  %scale = gegenbauerC(n,(K-2)/2, 1); 
  %g = gegenbauerC(n,(K-2)/2, t) / scale;
  %% mfun() deprecated (old versions of Matlab)
  %scale = mfun('G', n, (K-2)/2, 1);
  %g = mfun('G', n, (K-2)/2, t) / scale;
  %% Octave: % need "pkg load gsl" first
  scale = gsl_sf_gegenpoly_n(n, (K-2)/2, 1);
  g = gsl_sf_gegenpoly_n(n, (K-2)/2, t) / scale;
  %fprintf("gegenbauer: n=%d, t=%f, scale=%f, g=%f\n", n, t, scale, g);
end
