一.自准值法测凸透镜代码
数据的输入
int n;
double x,sum=0,e,s=0,k,z,c;
cout << "输入光源的位置数据" << endl;
double xp;
cin >> xp;
cout << "输入凸透镜的位置数据个数" << endl;
cin >> n;
cout << "输入凸透镜的位置X1,数据间用回车相隔" << endl;
double X1[500];
for (int i = 0; i < n; i++)
{
cin >> X1[i];
}
cout << "输入凸透镜旋转180度后的位置X2,数据用回车相隔" << endl;
double X2[500];
for (int i = 0; i < n; i++)
{
cin >> X2[i];
}
此段代码的含义是输入相应的实验数据。
数据计算
double X[500];
for (int i = 0; i < n; i++)
{
sum += xp - (X1[i] + X2[i]) / 2;
e = sum / n;
}
for (int i = 0; i < n; i++)
{
s += (xp-(X1[i] + X2[i])/2 - e) * (xp - (X1[i] + X2[i]) / 2 - e);
}
k = s / (n - 1);
z = sqrt(k);
if (n == 2) {
c = z * 8.98;
}
else if (n == 3) {
c = z * 2.48;
}
else if (n == 4) {
c = z * 1.59;
}
else if (n == 5) {
c = z * 1.24;
}
else if (n == 6) {
c = z * 1.05;
}
else if (n == 7) {
c = z * 0.93;
}
else if (n == 8) {
c = z * 0.84;
}
else if (n == 9) {
c = z * 0.77;
}
else if (n == 10) {
c = z * 0.72;
}
此段代码含义是求数据的不确定度。
处理后的数据输出
cout << "焦距为" << e << endl;
cout << "A不确定度为" << c << endl;
cout << "如果需要计算总不确定度,请输入仪器偏差" << endl;
double l, j;
cin >> l;
j = sqrt(c * c + l * l);
cout << "总不确定度为" << j << endl;
完整代码如下
#include
using namespace std;
int main()
{
int n;
double x,sum=0,e,s=0,k,z,c;
cout << "输入光源的位置数据" << endl;
double xp;
cin >> xp;
cout << "输入凸透镜的位置数据个数" << endl;
cin >> n;
cout << "输入凸透镜的位置X1,数据间用回车相隔" << endl;
double X1[500];
for (int i = 0; i < n; i++)
{
cin >> X1[i];
}
cout << "输入凸透镜旋转180度后的位置X2,数据用回车相隔" << endl;
double X2[500];
for (int i = 0; i < n; i++)
{
cin >> X2[i];
}
double X[500];
for (int i = 0; i < n; i++)
{
sum += xp - (X1[i] + X2[i]) / 2;
e = sum / n;
}
for (int i = 0; i < n; i++)
{
s += (xp-(X1[i] + X2[i])/2 - e) * (xp - (X1[i] + X2[i]) / 2 - e);
}
k = s / (n - 1);
z = sqrt(k);
if (n == 2) {
c = z * 8.98;
}
else if (n == 3) {
c = z * 2.48;
}
else if (n == 4) {
c = z * 1.59;
}
else if (n == 5) {
c = z * 1.24;
}
else if (n == 6) {
c = z * 1.05;
}
else if (n == 7) {
c = z * 0.93;
}
else if (n == 8) {
c = z * 0.84;
}
else if (n == 9) {
c = z * 0.77;
}
else if (n == 10) {
c = z * 0.72;
}
cout << "焦距为" << e << endl;
cout << "A不确定度为" << c << endl;
cout << "如果需要计算总不确定度,请输入仪器偏差" << endl;
double l, j;
cin >> l;
j = sqrt(c * c + l * l);
cout << "总不确定度为" << j << endl;
}
运行效果
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)