gpt4 book ai didi

java - LU 分解方法中线程 "main"java.lang.NullPointerException 异常

转载 作者:行者123 更新时间:2023-12-01 16:22:50 24 4
gpt4 key购买 nike

我有 2 个来自 LU 分解方法的矩阵(下矩阵和上矩阵),我正在尝试获取变量。 Here are my Lower matrix and Upper matrix

public void getZ() {
for(int i = 0; i < z.length; i++) { // iteration
if(i != nodeApplied) { // first we initialize the z with 0
// unless we reach the node that the force was applied
z[i] = 0;
} else {
z[i] = force;
}
}
}

public void getNewZ() {
// lower
int[] newZ = new int[n]; // we create a new int list to save the values of the variables
for (int i = 0; i < n; i++) {
int decrement = 0; // all positions in the row before the diagonal subtracted
for (int j = 0; j < n; j++) {
if (j == i) { // if it is a diagonal
newZ[i] = (z[i] - decrement) / lu.lower[i][i];
} else { // if is not in the diagonal
decrement += lu.lower[i][j] * newZ[j];
}
}
}
this.z = newZ;
}

public void getVariables() {
getNewZ();
for(int i = 0; i < n; i++) {
System.out.println(z[i]);
}
}
<小时/>
Exception in thread "main" java.lang.NullPointerException
at Matrix.getNewZ(Matrix.java:92)
at Matrix.<init>(Matrix.java:68)
at Matrix.main(Matrix.java:118)

最佳答案

我认为变量“lu”尚未实例化,当前指向 null。

关于java - LU 分解方法中线程 "main"java.lang.NullPointerException 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62224843/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com