Re: Help with Matrices in Mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg21211] Re: [mg21054] Help with Matrices in Mathematica
- From: "Hans Michel" <hmichel at meddevel.com>
- Date: Fri, 17 Dec 1999 01:29:10 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
On Dec 12 arani wrote Hi, I am trying to build a matrix of matrices and wondering whether the following does not work. I will appreciate your help. Please e-mail to this address. Thanks, Arani ScientificForm[%]; R11=20 R22=20 L11=10^-8 L22=10^-8 L12=5 10^-9 C11=25 10^-14 C22=25 10^-14 C12=15 10^-14 Rs1=50 Rs2=50 Cs1=10^-14 Cs2=10^-14 Table[Table[f[p,q],{p,4},{q,4}],{i,6},{j,20}] D1={{0,0,-R11,0},{0,0,0,-R22},{0,0,0,0},{0,0,0,0}} E1={{0,0,-L11,-L12},{0,0,-L12,-L22},{-C11,-C12,0,0},{-C12,-C22,0,0}} One={{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}} Mat[[1,1]] = One Mat[[1,2]] = D1 For[i=3, i< 20, i++,Mat[[1,i]]=0] Mat[[2,1]] = E1 Mat[[3,1]] = (1/2) E1.E1 Mat[[4,1]] = (1/6) E1.E1.E1 Mat[[5,1]] = (1/24) E1.E1.E1.E1 Mat[[6,1]] = (1/120) E1.E1.E1.E1.E1 Do[Mat[[i,j]] = (1/(i+j))*(D1.Mat[[i,j-1]] + E1.Mat[[i-1,j]]),{i,2,6,1},{j,2,20,1}] although this is a complicated way of doing things what you are missing is an array defined for Mat Mat = Array[m, {6, 20}]; Try the following modification to your code: I added semicolons and also added the array definition see the asterisk (remove it if R11=20; R22=20; L11=10^-8; L22=10^-8; L12=5 10^-9; C11=25 10^-14; C22=25 10^-14; C12=15 10^-14; Rs1=50; Rs2=50; Cs1=10^-14; Cs2=10^-14; D1={{0,0,-R11,0},{0,0,0,-R22},{0,0,0,0},{0,0,0,0}}; E1={{0,0,-L11,-L12},{0,0,-L12,-L22},{-C11,-C12,0,0},{-C12,-C22,0,0}}; One={{1,1,1,1},{1,1,1,1},{1,1,1,1},{1,1,1,1}}; Mat = Array[m, {6, 20}];* Mat[[1,1]] = One; Mat[[1,2]] = D1; For[i=3, i< 20, i++,Mat[[1,i]]=0]; Mat[[2,1]] = E1; Mat[[3,1]] = (1/2) E1.E1; Mat[[4,1]] = (1/6) E1.E1.E1; Mat[[5,1]] = (1/24) E1.E1.E1.E1; Mat[[6,1]] = (1/120) E1.E1.E1.E1.E1; Do[Mat[[i,j]] = (1/(i+j))*(D1.Mat[[i,j-1]] + E1.Mat[[i-1,j]]),{i,2,6,1},{j,2,20,1}]; Mat[[3,1]] I get {{1.62499999999999982`*^-21, 1.37499999999999977`*^-21, 0, 0}, {1.37499999999999977`*^-21, 1.62499999999999982`*^-21, 0, 0}, {0, 0, 1.62499999999999982`*^-21, 1.37499999999999977`*^-21}, {0, 0, 1.37499999999999977`*^-21, 1.62499999999999982`*^-21}} I would strongly recommend checking out << LinearAlgebra`MatrixManipulation`; there might be a more elegant way to solve your problem paticularly with BlockMatrix Good Luck