xchstwo.c

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

C
44
字号
/* Driver for routine chstwo */#include <stdio.h>#include <math.h>#define NRANSI#include "nr.h"#include "nrutil.h"#define NBINS 10#define NPTS 2000int main(void){	long idum=(-17);	int i,ibin,j;	float chsq,df,prob,x,*bins1,*bins2;	bins1=vector(1,NBINS);	bins2=vector(1,NBINS);	for (j=1;j<=NBINS;j++) {		bins1[j]=0.0;		bins2[j]=0.0;	}	for (i=1;i<=NPTS;i++) {		x=expdev(&idum);		ibin=(int) (x*NBINS/3.0+1);		if (ibin <= NBINS) ++bins1[ibin];		x=expdev(&idum);		ibin=(int) (x*NBINS/3.0+1);		if (ibin <= NBINS) ++bins2[ibin];	}	chstwo(bins1,bins2,NBINS,0,&df,&chsq,&prob);	printf("\n%15s %15s\n","dataset 1","dataset 2");	for (i=1;i<=NBINS;i++)		printf("%13.2f %15.2f\n",bins1[i],bins2[i]);	printf("\n%18s %12.4f\n","chi-squared:",chsq);	printf("%18s %12.4f\n","probability:",prob);	free_vector(bins2,1,NBINS);	free_vector(bins1,1,NBINS);	return 0;}#undef NRANSI

⌨️ 快捷键说明

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