Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a matrix that has a variable number of columns and rows (but it is always square). The matrix is:

$$ \Gamma = \begin{bmatrix} \Theta & 0 & 0 & 0 & T & 0 & R_j \\ u \Theta & \rho & 0 & 0 & u T & 0 & R_j \\ v \Theta & 0 & \rho & 0 & v T & 0 & R_j \\ w \Theta & 0 & 0 & \rho & w T & 0 & R_j \\ H \Theta -1 & u \rho & v \rho & w \rho & \Omega \rho +H T & \frac{5 \rho }{3} & R_j \\ k \Theta & 0 & 0 & 0 & k T & \rho & k R_j \\ Y_i \Theta & 0 & 0 & 0 & Y_i T & 0 & Y_i R_j+\rho \delta_{ij} \\ \end{bmatrix} $$

where the indices $i,j$ are the row and column indices respectively. For example, if $i,j={1,2}$ the matrix would look like:

$$ \Gamma = \begin{bmatrix} \Theta & 0 & 0 & 0 & T & 0 & R_1 & R_2 \\ u \Theta & \rho & 0 & 0 & u T & 0 & R_1 & R_2 \\ v \Theta & 0 & \rho & 0 & v T & 0 & R_1 & R_2 \\ w \Theta & 0 & 0 & \rho & w T & 0 & R_1 & R_2 \\ H \Theta -1 & u \rho & v \rho & w \rho & \Omega \rho +H T & \frac{5 \rho }{3} & R_1 & R_2 \\ k \Theta & 0 & 0 & 0 & k T & \rho & k R_1 & k R_2 \\ Y_1 \Theta & 0 & 0 & 0 & Y_1 T & 0 & Y_1 R_1+\rho & Y_1 R_2 \\ Y_2 \Theta & 0 & 0 & 0 & Y_2 T & 0 & Y_2 R_1 & Y_2 R_2 + \rho \\ \end{bmatrix} $$

The values for $i$ and $j$ can be arbitrary.

When I put this in as is (just treating the subscripts as notation), I get terms divided by the Kronecker delta only which is impossible. Is there a way to invert this and keep it general in terms of $i,j$? The code to enter the matrix is:

G = 
  {
    {Θ, 0, 0, 0, T, 0, Rj},
    {Θ*u, ρ, 0, 0, T*u, 0, Rj},
    {Θ*v, 0, ρ, 0, T*v, 0, Rj},
    {Θ*w, 0, 0, ρ, T*w, 0, Rj},
    {Θ*H - 1, ρ*u, ρ*v, ρ*w, T*H + ρ*Ω, 5/3*ρ, Rj},
    {Θ*k, 0, 0, 0, T*k, ρ, Rj*k},
    {Θ*Yi, 0, 0, 0, T*Yi, 0, Rj*Yi + ρ*δ}
  };
Ginv = FullSimplify[Inverse[G]];
share|improve this question
    
Can you explain what is wrong with this? Ginv.G gives the right thing. Also, what does "terms divided by the Kronecker delta only" mean, and why is it impossible? –  acl Jul 10 at 22:51
    
Mathematica does not know what these symbols mean mathematically. there are just symbols. If you want actual dirac delta, you should use DiracDelta[] btw, you might want to add space here "[Rho][Delta]" to make it "[Rho] [Delta]" just in case. –  Nasser Jul 10 at 22:53
    
@acl If I look at the Ginv, there are terms like $Y_i/\delta_{ij}$ which will be $Y_i/0$ for all but 1 column, which is ill-defined. –  tpg2114 Jul 10 at 22:54
    
@Nasser But how can I tell Mathematica that $i,j$ are for columns and rows? Without that information, the DiracDelta[] wouldn't know what to do either right? –  tpg2114 Jul 10 at 22:55
1  
I do not understand what you have there, so can't help. I do not know what Y_i supposed to mean. And do not know what R_j suppose to mean. Where did these come from? What is "i" there? what is "j" ? your question is fully described well to answer it (for me at least) –  Nasser Jul 10 at 23:03

1 Answer 1

This seems to work although I have not tested it thoroughly. Also, it's a rather brute force approach, so I hope someone else will post a more elegant solution.

g[0] = 
  {{Θ, 0, 0, 0, T, 0}, 
   {u Θ, ρ, 0, 0, T u, 0}, 
   {v Θ, 0, ρ, 0, T v, 0}, 
   {w Θ, 0, 0, ρ, T w, 0}, 
   {-1 + H Θ, u ρ, v ρ, w ρ, H T + ρ Ω, (5 ρ)/3}, 
   {k Θ, 0,0, 0, k T, ρ}}

upperRight[n_] := Transpose@Table[Join[ConstantArray[R[j], 5], {k R[j]}], {j, n}]

lower[n_] := 
  Table[Join[{Θ*Y[i], 0, 0, 0, T*Y[i], 0}, Table[Y[i] R[j], {j, n}]], {i, n}] /. 
    p : R[x_] Y[x_] :> p + ρ

g[n_] := Join[MapThread[Join, {g[0], upperRight[n]}, 1], lower[n]]

g2 = g[2]
{{Θ, 0, 0, 0, T, 0, R[1], R[2]}, 
  {u Θ, ρ, 0, 0, T u, 0, R[1], R[2]}, 
  {v Θ, 0, ρ, 0, T v, 0, R[1], R[2]}, 
  {w Θ, 0, 0, ρ, T w, 0, R[1], R[2]}, 
  {-1 + H Θ, u ρ, v ρ, w ρ, H T + ρ Ω, (5 ρ)/3, R[1], R[2]}, 
  {k Θ, 0, 0, 0, k T, ρ, k R[1], k R[2]}, 
  {Θ Y[1], 0, 0, 0, T Y[1], 0, ρ + R[1] Y[1], R[2] Y[1]}, 
  {Θ Y[2], 0, 0, 0, T Y[2], 0, R[1] Y[2], ρ + R[2] Y[2]}}

The above is invertible although the result is messy.

Short[Inverse[g2], 4]

matrix

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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