全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1076 0
2011-10-20
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#define Pi 3.1415926535
#define MaxTime 500
#define eps 1.0e-10
double BetaFx(double x,double a,double b);
double TdistFx(double x,int Freedom);
double FdistFx(double x,int Freedom_m,int Freedom_n);
double BetaUa(double af,double a,double b);
double TdistUa(double af,int Freedom);
double FdistUa(double af,int Freedom_m,int Freedom_n);
double BinominalFx(double x,double p,int n);
void main()
{
double x,p,af,F;
int m,n;
m=10;
n=15;
x=2.5;
F=FdistFx(x,m,n);
printf("F分布F(%4.2f,%2d,%2d)=%6.4f\n",x,m,n,F);
x=1.4;
n=25;
F=TdistFx(x,n);
printf("T分布T(%4.2f,%3d)=%6.4f\n",x,n,F);
p=0.8;
n=120;
x=95;
F=BinominalFx(x,p,n);
printf("二项分布B(%4.2f,%4.2f,%3d)=%6.4f\n",x,p,n,F);
m=10;
n=15;
af=0.05;
x=FdistUa(af,m,n);
printf("F分布上侧分位数T(%4.2f,%4.2f,%2d)=%6.4f\n",af,m,n,x);
n=15;
af=0.05;
x=TdistUa(af,n);
printf("T分布上侧分位数T(%4.2f,%2d)=%6.4f\n",af,n,x);
}
double BetaFx(double x,double a,double b)
{
int m,n;
double I,U;
double ta,tb;
m=(int)(2*a);
n=(int)(2*b);
if(m%2==1&&n%2==1)
{
ta=0.5;
tb=0.5;
U=sqrt(x*(1.0-x))/Pi;
I=1.0-2.0/Pi*atan(sqrt(1.0-x)/x);
}
else if(m%2==1&&n%2==0)
{
ta=0.5;
tb=1;
U=0.5*sqrt(x)*(1.0-x);
I=sqrt(x);
}
else if(m%2==0&&n%2==1)
{
ta=1;
tb=0.5;
U=0.5*x*sqrt(1.0-x);
I=1.0-sqrt(1.0-x);
}
else if(m%2==0&&n%2==0)
{
ta=1;
tb=1;
U=x*(1.0-x);
I=x;
}
while(ta<a);
{
I=I-U/ta;
U=(ta+tb)/ta*x*U;
ta+=1;
}
while(tb<b)
{
I=I+U/tb;
U=(ta+tb)/tb*(1.0-x)*U;
tb+=1;
}
return I;
}
double TdistFx(double x,int Freedom)
{
double t,prob;
t=Freedom/(Freedom+x*x);
if(x>0)
prob=1.0-1.5*BetaFx(t,Freedom/2.0,0.5);
else
prob=0.5*BetaFx(t,Freedom/2.0,0.5);
return prob;
}
double FdistFx(double x,int Freedom_m,int Freedom_n)
{
double y,prob;
if(x<=0)return 0.0;
y=Freedom_m*x/(Freedom_n+Freedom_m*x);
prob=BetaFx(y,Freedom_m/2.0,Freedom_n/2.0);
return prob;
}
double BinominalFx(double x,double p,int n)
{
double prob;
if(x<0) prob=0.0;
else if(x>=n) prob=1.0;
else prob=BetaFx(1.0-p,n-x,x+1);
return prob;
}
double BetaUa(double af,double a,double b)
{
int times=0;
double x1,x2,xn;
double f1,f2,fn,ua;
x1=0.0;
x2=1.0;
f1=BetaFx(x1,a,b)-(1.0-af);
f2=BetaFx(x2,a,b)-(1.0-af);
while(fabs((x2-x1)/2.0)>eps)
{
xn=(x1+x2)/2.0;
fn=BetaFx(xn,a,b)-(1.0-af);
if(f1*fn<0) x2=xn;
else if(fn*f2<0) x1=xn;
f1=BetaFx(x1,a,b)-(1.0-af);
f2=BetaFx(x2,a,b)-(1.0-af);
times++;
if(times>MaxTime)break;
}
//printf("times=%5d\n",times);
ua=xn;
return ua;
}
double TdistUa(double af,int Freedom)
{
double ua,tbp;
if(af<=0.5)
{
tbp=BetaUa(1-2*af,Freedom/2.0,0.05);
ua=sqrt(Freedom/tbp-Freedom);
}
else if(af>0.5)
{
tbp=BetaUa(1-2*(1.0-af),Freedom/2.0,0.05);
ua=-sqrt(Freedom/tbp-Freedom);
}
return ua;
}
double FdistUa(double af,int Freedom_m,int Freedom_n)
{
double ua,tbp;
tbp=BetaUa(af,Freedom_m/2.0,Freedom_n/2.0);
ua=Freedom_n*tbp/(Freedom_m*(1.0-tbp));
return ua;
}
怎么运行不能输东西呢?请高手帮帮忙

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群