額,,,, 前幾天,剛開始玩力熱實驗, 卻沒想到,平時愛玩的實驗誤差分析的不確定度竟然計算那麼複雜,連夜寫了一段代碼, (大佬勿噴,物理專業的小白剛自學,應該也沒人看。。。) 為了以後我用著方便,都寫成了函數塊,接下來會隨著實驗作業和Java的學習,繼續完善 (現在,不明白的是,兩組數,在定義的函數 ...
額,,,,
前幾天,剛開始玩力熱實驗,
卻沒想到,平時愛玩的實驗誤差分析的不確定度竟然計算那麼複雜,連夜寫了一段代碼,
(大佬勿噴,物理專業的小白剛自學,應該也沒人看。。。)
為了以後我用著方便,都寫成了函數塊,接下來會隨著實驗作業和Java的學習,繼續完善
(現在,不明白的是,兩組數,在定義的函數里,怎樣做減法得到一個數組,再把得到的數組返回到其他函數里使用)
import java.util.Scanner;
class zhangli
{
public static void main(String[] args)
{
double [] D1 ={3.342,3.350,3.348,3.354,3.344,3.350};
double [] D2={3.380,3.388,3.396,3.398,3.390,3.392};
double [] u ={0.0313,0.0323,0.0316,0.0314,0.0318};
zhjs(D1,0.002,"D1");
zhjs(D2,0.002,"D2");
zhjs(u,0.0001,"u");
}
public static void zhjs(double a[] ,double jdz,String s)
{
double A =(pingjun(a));
double k =PN(a.length);
double ua2 = cif(ua(k,a,A),2);
double ub2 = cif(jdz/3,2);
double U = cif((ua2+ub2),0.5);
System.out.println(s+"原始數據的平均數是:"+A);
System.out.println(s+"的不確定度是:"+U);
System.out.println(s+"的最終結果是:"+A+" ? "+U+"\n");
}
public static double pingjun (double a[]){
double sum = 0 ;
for (int i = 0; i < a.length; ++i)
{
sum += a[i];
}
return (sum / a.length) ;
}
public static double PN(int a )
{
double t = 0;
switch(a){
case 3:
t =1.32;
break;
case 4:
t =1.20;
break;
case 5:
t =1.14;
break;
case 6:
t =1.11;
break;
case 7:
t =1.09;
break;
default:
System.out.println("超出範圍");
}
return t;
}
public static double ua (double k ,double []a,double p)
{
double sum = 0 ;
int n = a.length;
for (int i = 0 ; i < n ; i ++ ) {
sum = cif((a[i] - p),2 )+sum;
}
double h = sum/(n*(n-1));
double q = k * cif(h,0.5);
return q ;
}
public static double cif(double a ,double n )
{
double q =Math.pow(a,n);
return q;
}
public static void zuoca(double []a ,double []b)
{
int k = a.length;
if (k!=b.length) {
System.out.println("兩組數據長度不一樣!");
}
else{
double [] c = new double [k];
for (int i = 0 ; i < a.length ; i++) {
c[i]=a[i]-b[i];
System.out.println(c[i]);
}
}
}
}