[英]Calculating linear systems using EJML
How exactly do I format my code so that It would take 我应该如何精确格式化代码,以便
1x+2y+3z+4w=5e
6x+7y+8z+9w=10e
11x+12y+13z+14w=15e
16x+17y+18z+19w=20e
and return x,y,z,w
? 并返回
x,y,z,w
?
I was trying to follow the format described in this answer , Currently what I have is the following code which which throws IllegalArgumentException: "java.lang.IllegalArgumentException: Can't solve for wide systems. More variables than equations.
when it attempts to calculate the 4 results: 我试图遵循此答案中描述的格式,目前,我拥有的是下面的代码,该代码引发
IllegalArgumentException: "java.lang.IllegalArgumentException: Can't solve for wide systems. More variables than equations.
当它尝试计算时4个结果:
double[20] args = {1,2,3... ,20};
SimpleMatrix A = new SimpleMatrix(4,5);
SimpleMatrix b = new SimpleMatrix(4,1);
int val=0;
for(int i =0;i<4;i++){
for(int j=0;j<5;j++){
A.setRow(i, j, args[val]);
val++;
}
b.setRow(i,0, args[val-1]);
}
double[] result = new double[4]; //results for x y z w
try {
SimpleMatrix solution = A.solve(b); //throws IllegalArgumentException!
for(int i=0;i<solution.getNumElements();i++) {
result[i] = solution.get(i, 0);
}
--print results--
}
catch ( SingularMatrixException e ) {
throw new IllegalArgumentException();
}
What am I doing wrong? 我究竟做错了什么?
I think it may have to do with your matrix dimensions. 我认为这可能与您的矩阵尺寸有关。
new SimpleMatrix A(4,5)
should be replaced with new SimpleMatrix A(4,4)
. new SimpleMatrix A(4,5)
应该替换为new SimpleMatrix A(4,4)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.