Author 
Comment/Response 
Pierre

10/09/12 1:33pm
Hello,
I am a French student studying in US for 1 month, and new Mathematica user (since this night..), yet I used to work with Matlab.
I need to solve a civil engineering problem using Mathematica,and my first part is to create the stiffness matrix for an association of 3 bars (context, not really important).
I have 3 matrix 4x4, each term of each matrix must be associated in a global matrix 8x8.
So, for each matrix, I want to create a 8x8 matrix, and then make the global matrix, summing the 3 matrices.
I tryed to create a double iterative function, in order to fulfill automatically the 8x8 matrix.
Here is my program :
For[i = 1, i < 9, i++,
For[j = 1, j < 9, j++,
If[i == N11, If[j == N11, K1[[i, j]] = M1[[1, 1]], K1[[i, j]] = 0],
K1[[i, j]] = 0]
If[i == N11, If[j == N12, K1[[i, j]] = M1[[1, 2]], K1[[i, j]] = 0],
K1[[i, j]] = 0]
If[i == N11, If[j == N13, K1[[i, j]] = M1[[1, 3]], K1[[i, j]] = 0],
K1[[i, j]] = 0]
If[i == N11, If[j == N14, K1[[i, j]] = M1[[1, 4]], K1[[i, j]] = 0],
K1[[i, j]] = 0]
If[i == N12, If[j == N11, K1[[i, j]] = M1[[2, 1]], K1[[i, j]] = 0],
K1[[i, j]] = 0]
If[i == N12, If[j == N12, K1[[i, j]] = M1[[2, 2]], K1[[i, j]] = 0],
K1[[i, j]] = 0]
If[i == N12, If[j == N13, K1[[i, j]] = M1[[2, 3]], K1[[i, j]] = 0],
K1[[i, j]] = 0]
If[i == N12, If[j == N14, K1[[i, j]] = M1[[2, 4]], K1[[i, j]] = 0],
K1[[i, j]] = 0]
If[i == N13, If[j == N11, K1[[i, j]] = M1[[3, 1]], K1[[i, j]] = 0],
K1[[i, j]] = 0]
If[i == N13, If[j == N12, K1[[i, j]] = M1[[3, 2]], K1[[i, j]] = 0],
K1[[i, j]] = 0]
If[i == N13, If[j == N13, K1[[i, j]] = M1[[3, 3]], K1[[i, j]] = 0],
K1[[i, j]] = 0]
If[i == N13, If[j == N14, K1[[i, j]] = M1[[3, 4]], K1[[i, j]] = 0],
K1[[i, j]] = 0]
If[i == N14, If[j == N11, K1[[i, j]] = M1[[3, 1]], K1[[i, j]] = 0],
K1[[i, j]] = 0]
If[i == N14, If[j == N12, K1[[i, j]] = M1[[3, 2]], K1[[i, j]] = 0],
K1[[i, j]] = 0]
If[i == N14, If[j == N13, K1[[i, j]] = M1[[3, 3]], K1[[i, j]] = 0],
K1[[i, j]] = 0]
If[i == N14, If[j == N14, K1[[i, j]] = M1[[3, 4]], K1[[i, j]] = 0],
K1[[i, j]] = 0]]]
MatrixForm[K1]
M1 is the 4x4 matrix, K1 the 8x8 matrix.
i is the number of the row, j the number of the column. i goes from 1 to 8, and for each value of i, j goes from 1 to 8. Then, I can fulfill the matrix, row by row.
But the problem is that it doesn't work.. and I do not understand (after spending several hours). It should be a syntax problem, hope someone can help me. May be I should use the function "Do" ?
Thanks very much in advance,
Pierre
URL: , 
