0
$\begingroup$

Im trying to assemble new matrices from some previous matrices I have created, but I can´t. What Im trying to do is the following:

1) I have different matrices:

K11e[1] = {{a, a}, {a, a}};
K11e[2] = {{b, b}, {b, b}};
K12e[1] = {{aa, aa, aa, aa}, {aa, aa, aa, aa}};
K12e[2] = {{ab, ab, ab, ab}, {ab, ab, ab, ab}};
K22e[1] = {{ca, ca, ca, ca}, {ca, ca, ca, ca}, {ca, ca, ca, ca}, {ca, ca, ca, ca}};
K22e[2] = {{cb, cb, cb, cb}, {cb, cb, cb, cb}, {cb, cb, cb, cb}, {cb, cb, cb, cb}};
K21e[1] = {{da, da}, {da, da}, {da, da}, {da, da}};
K21e[2] = {{ba, ba}, {ba, ba}, {ba, ba}, {ba, ba}};

2) Define 2 vectors, I will used them to assemble my global matrices:

L1 = {1, 2};
L2 = {3, 4, 5, 6};

3) With "Do" assemble n matrices (2 for this example) with the previous matrices

Do[
KE[z] = ConstantArray[0, {6, 6}];
KE[z][[L1, L1]] = KE[z][[L1, L1]] + K11e[z];
KE[z][[L1, L2]] = KE[z][[L1, L2]] + K12e[z];
KE[z][[L2, L1]] = KE[z][[L2, L1]] + K21e[z];
KE[z][[L2, L2]] = KE[z][[L2, L2]] + K22e[z];, {z, 1, 2}]

4) So Im expecting to get this matrices:

KE[1] = {{a, a, aa, aa, aa, aa}, {a, a, aa, aa, aa, aa}, {da, da, ca, 
  ca, ca, ca}, {da, da, ca, ca, ca, ca}, {da, da, ca, ca, ca, 
  ca}, {da, da, ca, ca, ca, ca}};
KE[2] = {{b, b, ab, ab, ab, ab}, {b, b, ab, ab, ab, ab}, {ba, ba, cb, 
  cb, cb, cb}, {ba, ba, cb, cb, cb, cb}, {ba, ba, cb, cb, cb, 
  cb}, {ba, ba, cb, cb, cb, cb}}

But instead Mathematica give me the next error:

KE[z] in the part assignment is not a symbol.

Many thanks in advance.

$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – bbgodfrey Mar 24 '15 at 22:15
1
$\begingroup$

You should use ArrayFlatten to build block matrices, for example

{{K11e[1], K12e[1]},
  {K21e[1], K22e[1]}} // ArrayFlatten
$\endgroup$
0
$\begingroup$

You can also define your own function if you want to apply it to multiple cases

myFunc = ArrayFlatten@MapThread[List, {{K11e[#], K21e[#]}, {K12e[#], K22e[#]}}, 1] &

myFunc@1 // MatrixForm

Blockquote

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.