前些天发现了十分不错的人工智能学习电子书,通俗易懂,风趣幽默,没有广告,分享给大家,大家可以自行看看。(点击跳转人工智能学习资料)
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("灵敏度为:" + s);//求线性误差System.out.println("非线性误差为:" + maxy/fully);}//返回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 ) / npublic 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区间");matching(x1, y1,inputs1,y1[y1.length-1]);System.out.println("-1区间");matching(x2, y2,inputs2,y2[y2.length-1]);System.out.println("+3区间");matching(x3, y3,inputs3,y3[y3.length-1]);System.out.println("-3区间");matching(x4, y4,inputs4,y4[y4.length-1]);}
}
以下可忽略!
差动变压器指的是一种广泛用于电子技术和非电量检测中的变压器装置。主要用于测 量位移、压力、振动等非电量参量。它既可用于静态测量,也可用于动态测量。
差动变压器由初级线圈和次级线圈组成,次级线圈分成极性相反的两部分。当交流电压加在初级线圈上时,若铁芯离开中心,则次级线圈上感应电动势的差,随着铁芯移动,电动势的差随之变大。
差动变压器以其结构简单、良好的环境适应性、灵敏度高、测量精度高、线性度好、输出稳定且输出曲线光滑以及驱动力小等特点,广泛应用于电子技术各种线位移的测量与转换、仪表仪器以及传感器技术当中。介绍一种差动变压器在给定线性位移的情况下输出一定的可控电气量,从而实现主令控制的应用。针对设计制造、试制调试的过程中出现的各种问题,分析了差动变压器的零点残余电压产生的原因和对实际电气控制的影响,以及差动变压器的几何形状尺寸、电和磁的各种参数的对称性对零点残余电压的影响。