#include<iostream> #include<cmath> #include<iomanip> #include<cstdlib> using namespace std; int main() { double Ua, Ub,Ux,Urx; double Ub_equp; int i; const int N = 10; double temp = 0; const double square_root_3 = sqrt(3); double average; double f, Urf, Uf,v,Urv,Uv; double value[N] = { 9.86,9.86,9.85,9.91,9.84,9.82,9.88,9.87,9.83,9.84 }; /* proto[2 * N] = { 61.36,66.84,70.54,75.80,80.50,85.80,90.60,95.10,100.08,105.30, 110.30,114.90,119.66,124.46,130.40,135.00,139.50,145.00,149.60,154.90 };*/ cout << "请输入" << N << "个数据:(注意化成相同单位" << endl; /* for (i = 0;i < 2 * N;i++) { cout << "请输入第" << i + 1 << "个数据: "; cin >> proto[i]; }*/ for (i = 0;i < N;i++) { /*value[i] = (proto[i + 10] - proto[i]) / 5; cout << "第" << i + 1 << "个逐差数据为: " << value[i] << endl;*/ temp += value[i]; } average = temp / N; cout << "平均值为: " << setprecision(5) << average << endl; cout << "仪器不确定度: "; cin >> Ub_equp; Ub = Ub_equp / square_root_3; temp = 0; for (i = 0;i < N;i++) temp += ((value[i] - average)*(value[i] - average)); Ua = sqrt(temp / (N*(N - 1))); cout << "数值不确定度 Ua: " << setprecision(5) << Ua << endl; cout << "仪器不确定度Ub: " << setprecision(5) << Ub << endl; Ux = sqrt(Ua*Ua + Ub*Ub); cout << "合成不确定度: " << setprecision(5) << Ux << endl; Urx = Ux / average; cout << "合成数值不确定度: " << setprecision(5) << Urx << endl; Uf = 0.01 / square_root_3; cout << "频率的仪器不确定度: " << setprecision(5) <<Uf<< endl; cout << "频率: "; cin >> f; Urf = Uf / f; cout << "频率的不确定度:" << setprecision(5) << Urf << endl; v = average*f; cout << "声速: " << v << endl; Urv = sqrt(Urx*Urx + Urf*Urf); cout << "声速不确定度:" << Urv << endl; Uv = Urv*v; cout << "声速不确定度数值:" << Uv << endl; cout << "百分误差: " << fabs(v - 341.70) / 341.70 * 100 << endl; system("pause"); }