% Written by Min-Hua Huang
% June 9, 2011
% Testing Student's t distribution function (related to the Hypergeometric function as an "h" function).
% Section 4.6 in "Indefinite Integration of the Gamma Integral".
% c is an considerably larger number, as a proxy of the infinite upper limit. 
clear; clc; format long; n=10^5; c=50; digits(700);
fprintf('Testing Student t distribution (associated with the Hypergeometric function):\n\n');
% ************************************************************************
% Student's t distribution
x=-0.73; v=20;
answer1=tcdf(x,v);
t=x^2/v; b=(v+1)/2; record=ones(1,3); sum=0;
for i=0:1:100
    d=vpa((-1)^i*t^(1/2+i)/(factorial(i)*(1/2+i)));
    sum=vpa(sum+d);
    record(i+1,1)=d;
    record(i+1,2)=sum;
end
first=sum;
for i=0:1:100
    sum=vpa(sum-(-1)^i*t^(1/2+i)/(factorial(i)*(1/2+i)));
    record(i+1,3)=sum;
end
f21=first+(b-1)*record(1,3);
for i=1:1:100
    product=1;
    if i==1
       product=b^2;
    else
       for j=1:1:i-1 
       product=product*(b+j-1);
       end
       product=product*(b+i-1)^2;
    end
    f21=f21+product*record(i+1,3);
end
check1=double(1/2+x*c^((v+1)/2)*exp(-c)*h((v-1)/2,-c,n)*(f21/(2*sqrt(t)))/(sqrt(pi*v)*c^(v/2)*exp(-c)*h(v/2-1,-c,n)));
fprintf('Student t=%8.5f, h method=%8.5f.\n\n',answer1,check1);
