生活随笔
收集整理的這篇文章主要介紹了
传感与检测实验报告,差动变压器的特性测定,江南大学物联网自动化
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
public class LeastSquares {public static void matching(double[] x
, double[] y
, double[] input
, double fully
) {double k
= getK(x
, y
);double b
= getB(x
, y
);System
.out
.println("線性回歸系數(shù)k值:\t"+k
+"\n" + "線性回歸系數(shù)b值:\t" + b
);double maxy
= 0; for (int i
= 0; i
< input
.length
; i
++) {if (Math
.abs(k
* input
[i
] + b
- y
[i
]) > maxy
){maxy
= Math
.abs(k
* input
[i
] + b
- y
[i
]);}}System
.out
.println("最大偏差為:" + maxy
);double s
= 0;double sum
= 0;for (int i
= 1; i
< y
.length
; i
++) {sum
+= y
[i
] - y
[i
-1];}s
= sum
/ (y
.length
- 1) / 20;System
.out
.println("靈敏度為:" + s
);System
.out
.println("非線性誤差為:" + maxy
/fully
);}public static double getK(double[] x
, double[] y
) {int n
= x
.length
;return (double) ((n
* pSum(x
, y
) - sum(x
) * sum(y
)) / (n
* sqSum(x
) - Math
.pow(sum(x
), 2)));}public static double getB(double[] x
, double[] y
) {int n
= x
.length
;double k
= getK(x
, y
);return sum(y
) / n
- k
* sum(x
) / n
;}private static double sum(double[] ds
) {double s
= 0;for (double d
: ds
) {s
= s
+ d
;}return s
;}
private static double sqSum(double[] ds
) {double s
= 0;for (double d
: ds
) {s
= (double) (s
+ Math
.pow(d
, 2));}return s
;}
private static double pSum(double[] x
, double[] y
) {double s
= 0;for (int i
= 0; i
< x
.length
; i
++) {s
= s
+ x
[i
] * y
[i
];}return s
;}public static void main(String
[] args
) {double[] x1
= {0,0.2,0.4,0.6,0.8,1.0};double[] y1
= {17.6,73.6,133,200,256,312};double[] inputs1
= x1
;double[] x2
= {0,-0.2,-0.4,-0.6,-0.8,-1.0};double[] y2
= {40.0,96,152,208,264,328};double[] inputs2
= x2
;double[] x3
= {0,0.2,0.4,0.6,0.8,1.0,1.2,1.4,1.6,1.8,2.0,2.2,2.4,2.6,2.8,3.0};double[] y3
= {17.6,73.6,133,200,256,312,372,428,484,548,600,672,712,776,832,888};double[] inputs3
= x3
;double[] x4
= {0,-0.2,-0.4,-0.6,-0.8,-1.0,-1.2,-1.4,-1.6,-1.8,-2.0,-2.2,-2.4,-2.6,-2.8,-3.0};double[] y4
= {40.0,96,152,208,264,328,384,440,496,552,616,666,720,784,840,898};double[] inputs4
= x4
;System
.out
.println("+1區(qū)間");matching(x1
, y1
,inputs1
,y1
[y1
.length
-1]);System
.out
.println("-1區(qū)間");matching(x2
, y2
,inputs2
,y2
[y2
.length
-1]);System
.out
.println("+3區(qū)間");matching(x3
, y3
,inputs3
,y3
[y3
.length
-1]);System
.out
.println("-3區(qū)間");matching(x4
, y4
,inputs4
,y4
[y4
.length
-1]);}
}
總結(jié)
以上是生活随笔為你收集整理的传感与检测实验报告,差动变压器的特性测定,江南大学物联网自动化的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。