3 回答

TA貢獻1784條經(jīng)驗 獲得超7個贊
您可以在 for 循環(huán)中使用 if 條件為特定單元格設(shè)置不同的值。
import Jama.Matrix;
public class Matrixnonsym {
public static void main(String args[]){
Matrix Mytest=new Matrix(5,5);
for(int i=0;i<4;i++){
if(i == 0){
Mytest.set(i,i,2);
}
Mytest.set(i,i,1);
Mytest.set(i+1,i,1);
}
Mytest.print(9,6);
}
}

TA貢獻1801條經(jīng)驗 獲得超8個贊
我以前從未使用過 Jama,但從 Javadoc 來看,我認為您可以這樣做:
import Jama.Matrix;
public class Matrixnonsym {
public static void main(String args[]){
Matrix Mytest=new Matrix(5,5);
for(int i=0;i<4;i++){
Mytest.set(i,i,1);
Mytest.set(i+1,i,1);
}
Mytest.set(0, 0, 2.0)
Mytest.print(9,6);
}
}

TA貢獻1890條經(jīng)驗 獲得超9個贊
import Jama.Matrix;
public class Matrixnonsym {
public static void main(String args[]){
Matrix Mytest=new Matrix(5,5);
// first column
Mytest.set(0,0,2);
Mytest.set(1,0,1);
// others columns
for(int i=1; i<4; i++){
Mytest.set(i,i,1);
Mytest.set(i+1,i,1);
}
Mytest.print(9,6);
}
}
或者
import Jama.Matrix;
public class Matrixnonsym {
public static void main(String args[]){
Matrix Mytest=new Matrix(5,5);
for(int i=0; i<4; i++){
Mytest.set(i, i, i == 0 ? 2 : 1);
Mytest.set(i+1, i, 1);
}
Mytest.print(9,6);
}
}
添加回答
舉報