pearsn.c

来自「适合大型数值计算代码 现在网络上已经找不到了 购买需要20$」· C语言 代码 · 共 34 行

C
34
字号
#include <math.h>#define TINY 1.0e-20void pearsn(float x[], float y[], unsigned long n, float *r, float *prob,	float *z){	float betai(float a, float b, float x);	float erfcc(float x);	unsigned long j;	float yt,xt,t,df;	float syy=0.0,sxy=0.0,sxx=0.0,ay=0.0,ax=0.0;	for (j=1;j<=n;j++) {		ax += x[j];		ay += y[j];	}	ax /= n;	ay /= n;	for (j=1;j<=n;j++) {		xt=x[j]-ax;		yt=y[j]-ay;		sxx += xt*xt;		syy += yt*yt;		sxy += xt*yt;	}	*r=sxy/(sqrt(sxx*syy)+TINY);	*z=0.5*log((1.0+(*r)+TINY)/(1.0-(*r)+TINY));	df=n-2;	t=(*r)*sqrt(df/((1.0-(*r)+TINY)*(1.0+(*r)+TINY)));	*prob=betai(0.5*df,0.5,df/(df+t*t));}#undef TINY

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?