大学物理实验不确定度.cpp

xiaoxiao2022-06-11  16

*求合成不确定度 需根据具体实验修改all_uncertainty()函数的内容 需提前定义常量 */ #include <iostream> #include <cmath> #include <iomanip> #include <cstdio> using namespace std; #define PI 3.1415926 #define N 200 //印度人的数组 #define G 9.78069 #define E 0.01 //精准的比较 #define K 0 //拓展不确定度的拓展因子; #define MAXN 0 #define M 10 //t表的一个常量参数 #define L 0 //b类不确定度的 b表 struct uncertainty { int n; //个数 double test[N]; //数据 double average_s; //平均数 //A类不确定度 double s, sx, ua; //标准差,平均值的标准差,a类不确定度 //b类不确定度 double dyi; //仪器的的最大允许误差 double ub; //合成不确定度 double uc; //绝对不确定度 double ucx; //相对不确定度 }mytest; void a_uncertainty_get(int n) { //计算A类不确定度 double t_joy68[] = { 0,0,0,1.32,1.20,1.14,1.11,1.09,1.08,1.07,1.06,0,0,0,0,1.04,0,0,0,0,1.03 };//0.68 t 表 double sum_test = 0; //初始化s,并输入数据到数组 cout << "依次输入该组数据" << endl; for (int i = 0; i < n; i++) { cin >> mytest.test[i]; mytest.test[i] = mytest.test[i]; sum_test += mytest.test[i]; } //计算平均值 mytest.average_s = sum_test / n; //计算标准差 double sum_dtext = 0; for (int i = 0; i < n; i++) { sum_dtext += (mytest.test[i] - mytest.average_s)*(mytest.test[i] - mytest.average_s); } mytest.s = sqrt(sum_dtext / (n - 1)); //计算A类不确定度 //计算平均值的标准差 mytest.sx = mytest.s / sqrt(n); mytest.ua = t_joy68[n > 10 ? M : n] * mytest.sx; } void b_uncertainty_get(double max_dyi){ //计算B类不确定度 double b_joy[] = { 3,sqrt(3) }; //3为仪器误差的正态分布(秒表,千分尺,米尺等) sqrt(3)为矩形分布 (游标卡尺等) mytest.ub = max_dyi / b_joy[L]; } void all_uncertainty_get() { cout << "输入测试数据的个数" << endl; cin >> mytest.n; a_uncertainty_get(mytest.n); cout << "输入测量仪器所允许的最大误差" << endl; cin >> mytest.dyi; b_uncertainty_get(mytest.dyi); mytest.uc = sqrt(mytest.ua * mytest.ua + mytest.ub*mytest.ub); //默认求得是p=0.68置信概率的不去确定度 double k[] = { 1,1.96,2,2.575,3 }; mytest.uc*=k[K]; mytest.ucx = mytest.uc / mytest.average_s * 100; } int main() { while (true) { all_uncertainty_get(); //cout << mytest.s << endl; //方差 //cout << mytest.sx << endl; //标准差 //cout << mytest.ua << endl; //a类不确定度 //cout << mytest.ub << endl; //b类不读确定度 //cout << mytest.average_s << endl; //平均数 //cout << mytest.uc << endl; //绝对不确定度 cout << mytest.ucx << endl; //相对不确定度 } return 0; }

 

转载请注明原文地址: https://www.6miu.com/read-4932021.html
最新回复(0)