资讯专栏INFORMATION COLUMN

传感与检测技术,Pt100热电阻测温实验报告,江南大学物联网

binta / 828人阅读

摘要:线性回归系数值线性回归系数值用来记录最大偏差寻找最大偏差最大偏差为求灵敏度灵敏度为求非线性误差非线性误差为返回的系数公式返回常量系数系数公式求和求平方和返回对应项相乘后的和热电阻测温实验拟合直线



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("线性回归系数 k 值:/t" + k + "/n" + "线性回归系数 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("灵敏度为:" + Math.abs(s)); //求非线性误差 System.out.println("非线性误差为:" + Math.abs(maxy/fully*100) + "%"); } //返回 x 的系数 k 公式:k = (n sum( xy ) - sum( x ) sum( y )) / (n sum( x^2 )-sum(x) ^ 2) 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))); } //返回常量系数系数 b 公式:b = sum( y ) / n - k * sum( x ) / n 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 = {52.5,55,60,65,70,75,80,85,90,95,100}; double[] y1 = {0,-0.54,-1.46,-2.32,-3.20,-4.06,-4.90,-5.72,-6.51,-7.31,-8.01}; double[] inputs1 = x1; System.out.println("Pt100 热电阻测温实验拟合直线:"); matching(x1, y1,inputs1,y1[y1.length-1]); }}

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/123285.html

相关文章

发表评论

0条评论

最新活动
阅读需要支付1元查看
<