public class SparseMatrix {
private static int N = 10;
public static void main(String[] args) {
double[][] matrix2 = new double[N][N];
for(int i = 0; i < N; i++) {
matrix2[i][i] = 1.0;
}
double[] b2 = new double[N];
b2[0] = b2[1] = b2[N-1] = 1;
double[] c = new double[N];
//brutal force
for(int i = 0; i < N; i++) {
double sum = 0;
for(int j = 0; j < N; j++) {
sum += matrix2[i][j] * b2[i];
}
c[i] = sum;
}
System.out.print("[");
for(int i = 0; i < N - 1; i++) {
System.out.print(c[i] + ",");
}
System.out.println(c[N-1] + "]");
}
}