「最小二乘法java」最小二乘法jacobi矩阵求法

博主:adminadmin 2022-11-22 09:38:06 46

本篇文章给大家谈谈最小二乘法java,以及最小二乘法jacobi矩阵求法对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

最小二乘法,y=a0+a1*x1+a2*x2,要求使用java编写

x2nbsp这其实就是一个多元线性回归问题;2; nbsp,1);

x2=rand(10;

gt,用regress函数就可以了: x1=rand(10.8651其中前四行的作用是产生测试数据,真正需要的只有最后一行代码,得到的a依次为a1、a2,1);

a1=1,1)])

a =

ones(10,1)*0.1;

a=regress(y,[x1 a2=2;a0=3;1;y=a1*x1+a2*x2+a0+randn(10;nbsp.1448

nbsp.1743

2

「最小二乘法java」最小二乘法jacobi矩阵求法

已知一组数据,用JAVA JFRAME利用最小二乘法求出该组数据的多项式拟合公式

这个问题,我好像回答过!

/**

* 最小二乘法计算类

*

* @author Administrator

*

*/

public class LeastSquareMethod {

private double[] x;

private double[] y;

private double[] weight;

private int m;

private double[] coefficient;

public LeastSquareMethod(double[] x, double[] y, int m) {

if (x == null || y == null || x.length 2 || x.length != y.length

|| m 2)

throw new IllegalArgumentException("无效的参数");

this.x = x;

this.y = y;

this.m = m;

weight = new double[x.length];

for (int i = 0; i x.length; i++) {

weight[i] = 1;

}

}

public LeastSquareMethod(double[] x, double[] y, double[] weight, int m) {

if (x == null || y == null || weight == null || x.length 2

|| x.length != y.length || x.length != weight.length || m 2)

throw new IllegalArgumentException("无效的参数");

this.x = x;

this.y = y;

this.m = m;

this.weight = weight;

}

public double[] getCoefficient() {

if (coefficient == null)

compute();

return coefficient;

}

public double fit(double v) {

if (coefficient == null)

compute();

if (coefficient == null)

return 0;

double sum = 0;

for (int i = 0; i coefficient.length; i++) {

sum += Math.pow(v, i) * coefficient[i];

}

return sum;

}

private void compute() {

if (x == null || y == null || x.length = 1 || x.length != y.length

|| x.length m || m 2)

return;

double[] s = new double[(m - 1) * 2 + 1];

for (int i = 0; i s.length; i++) {

for (int j = 0; j x.length; j++)

s[i] += Math.pow(x[j], i) * weight[j];

}

double[] f = new double[m];

for (int i = 0; i f.length; i++) {

for (int j = 0; j x.length; j++)

f[i] += Math.pow(x[j], i) * y[j] * weight[j];

}

double[][] a = new double[m][m];

for (int i = 0; i m; i++) {

for (int j = 0; j m; j++) {

a[i][j] = s[i + j];

}

}

coefficient = Algorithm.multiLinearEquationGroup(a, f);

}

/**

* @param args

*/

public static void main(String[] args) {

LeastSquareMethod l = new LeastSquareMethod(

new double[] { 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 },

new double[] { 37.84, 44.55, 45.74, 63.8, 76.67, 105.59, 178.48, 355.27, 409.92 },

new double[] { 11, 12, 13, 14, 15, 16, 17, 18, 19 },

2);

double[] x = l.getCoefficient();

for (double xx : x) {

System.out.println(xx);

}

System.out.println(l.fit(2009));

}

}

谁能帮忙用java解这个最小二乘法建立的求参数的方程,已知x1,x2,y。求参数a,b1,b2三个参数的值

我是高级Java从业者,数学功底一般般,不给你翻译代码了。这类问题一般用matlab的多,用java处理计算问题的比较少。你可以参考国外大学的一些在线研究成果。如MIT的很多项目都直接放在网上。

他山之石,可以攻玉。这里给你找了一个模拟拟合的网站:

最小二乘法java的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于最小二乘法jacobi矩阵求法、最小二乘法java的信息别忘了在本站进行查找喔。

The End

发布于:2022-11-22,除非注明,否则均为首码项目网原创文章,转载请注明出处。