摘要:線性回歸系數(shù)值線性回歸系數(shù)值用來(lái)記錄最大偏差尋找最大偏差最大偏差為求靈敏度靈敏度為求非線性誤差非線性誤差為返回的系數(shù)公式返回常量系數(shù)系數(shù)公式求和求平方和返回對(duì)應(yīng)項(xiàng)相乘后的和熱電阻測(cè)溫實(shí)驗(yàn)擬合直線
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; //用來(lái)記錄最大偏差 //尋找最大偏差 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 的系數(shù) 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))); } //返回常量系數(shù)系數(shù) 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; } //返回對(duì)應(yīng)項(xiàng)相乘后的和 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 熱電阻測(cè)溫實(shí)驗(yàn)擬合直線:"); matching(x1, y1,inputs1,y1[y1.length-1]); }}
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/123285.html
摘要:設(shè)置三個(gè)功能鍵,緊急報(bào)警功能鍵,人為報(bào)警和取消報(bào)警,即手動(dòng)報(bào)警。如果識(shí)別出火災(zāi)事故,警報(bào)系統(tǒng)將在微控制器設(shè)計(jì)的指導(dǎo)下啟動(dòng)警報(bào),以警告發(fā)生火災(zāi)事故。 1.1課題研究背...
摘要:線性回歸系數(shù)值線性回歸系數(shù)值用來(lái)記錄最大偏差尋找最大偏差最大偏差為求靈敏度靈敏度為求線性誤差非線性誤差為返回的系數(shù)公式返回常量系數(shù)系數(shù)公式求和求平方和返回對(duì)應(yīng)項(xiàng)相乘后的和區(qū)間區(qū)間區(qū)間區(qū)間 ...
單向交流調(diào)壓接電阻電感性負(fù)載波形圖:
摘要:截至年月,全國(guó)已有個(gè)省區(qū)市發(fā)布了人工智能規(guī)劃,其中個(gè)制定了具體的產(chǎn)業(yè)規(guī)模發(fā)展目標(biāo)。年我國(guó)企業(yè)相繼發(fā)布人工智能芯片。五大數(shù)據(jù)發(fā)展情況在促進(jìn)大數(shù)據(jù)發(fā)展行動(dòng)綱要等政策的指 showImg(http://upload-images.jianshu.io/upload_images/13825820-5b1886a2a4a6c96f.jpg?imageMogr2/auto-orient/stri...
閱讀 2278·2023-04-25 23:15
閱讀 1943·2021-11-22 09:34
閱讀 1563·2021-11-15 11:39
閱讀 971·2021-11-15 11:37
閱讀 2166·2021-10-14 09:43
閱讀 3506·2021-09-27 13:59
閱讀 1517·2019-08-30 15:43
閱讀 3480·2019-08-30 15:43