线性回归系数值线性回归系数值用于记录最大偏差,求最大偏差,求灵敏度,求非线性误差,求非线性误差,返回常系数的系数公式,求系数公式的平方,返回与热电阻测温实验相乘的直线。
public class least squares { public static void matching(double[]x,double[] y,double[] input,double full){ 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 maxy = math . ABS(k * input[I]+b -y[I]);}} System.out.println("最大偏差:"+maxy);//求灵敏度双s = 0;double sum = 0;for(int I = 1;i int n = x.lengthreturn (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公共静态double getb (double [] x,double[]y){ int n = x . length;double k = getK(x,y);return sum(y)/n ^ -k * sum(x)/n;}//Sum私有静态double Sum(double[]ds){ double s = 0;for(double d:ds){ s = s+d;} return s;}//求平方和私有静态double sqsum(double[]ds){ double s = 0;for(double d:ds){ s =(double)(s+math . pow(d,2));} return s;}//返回对应项乘以私有静态double psum的和(double [] x,double[]y){ double s = 0;for(int I = 0;i 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[]inputs 1 = x1;System.out.println("Pt100热电阻测温实验拟合直线:");matching(x1,y1,inputs1,y1[y1 . length -1]);}}
评论前必须登录!
注册