Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Det in Mathematica

  1. Mar 23, 2010 #1
    Hello,

    I have the following code in Mathematica:

    Code (Text):
    G[k_, l_] :=
      MatrixForm[Table[If[i == j, 1, 0], {i, 1, 3}, {j, 1, 3}]];

    Print[\!\(
    \*UnderoverscriptBox[\(\[Sum]\), \(k = 1\), \(3\)]\(
    \*UnderoverscriptBox[\(\[Sum]\), \(l = 1\), \(3\)]Det[G[k, l]]\)\)];
     
    but it does not evaluate the determinant as a number, how to force it to do that?

    Thanks in advance
     
  2. jcsd
  3. Mar 23, 2010 #2

    Hepth

    User Avatar
    Gold Member

    Get rid of that "MatrixForm". A table is by definition a matrix, the matrixform just changes display type. So you're operating on a display object rather than a mathematical object.

    Then it works.

    Remember also the way you have it, k and l are NOT the indices of the matrix. So those sums are just going to give you 9.

    G[k_, l_] :=
    Table[If[i == j, 1, 0], {i, 1, 3}, {j, 1, 3}][[k]][[l]];

    would give you an indexable matrix but then you cannot operate on it like a matrix (det wont work). You'd have to male it a table again:
    Det[Table[G[i, j], {i, 1, 3}, {j, 1, 3}]]
     
  4. Mar 23, 2010 #3
    Yes, I know that the equations do not make sense, it is complicated to explain. But it is working now. The actual code is here, which gives an error (why?) and a very large number (not expected, I guess)!!:

    Code (Text):

    P = {1.6, 1.8, 2};
    p = 1;
    f1[k_, l_, i_, j_] := Gamma[4]*\!\(
    \*UnderoverscriptBox[\(\[Sum]\), \(m = 0\), \(3\)]
    \*FractionBox[\(1\), \(m!\)]*NIntegrate[
    \*SuperscriptBox[\(Log[1 + p*y]\), \(2\)]*
    \*SuperscriptBox[\(y\), \(3 - j\)]*Exp[\(-y\)]*
    \*SuperscriptBox[\((
    \*FractionBox[\(1\), \(P[\([\)\(i\)\(]\)] + y\)])\), \(-\((3 + 1 -
               m)\)\)], {y, 0, Infinity}]\);
    f2[k_, l_, i_, j_] := If[j == k, f3[k, l, i, j], f4[k, l, i, j]];
    f3[k_, l_, i_, j_] :=
      Exp[1/P[[i]]]*
       NIntegrate[(Log[1 + (p*u)]*u^(3 - j))/(1/(P[[i]] + u))^(3 + 1)*
         Gamma[3 + 1, 1/(P[[i]]*u)], {u, 0, Infinity}];
    f4[k_, l_, i_, j_] :=
      N[Gamma[3 - j + 1]*Exp[1/P[[i]]]*P[[i]]^j*Gamma[j, 1/P[[i]]]];
    G[k_, l_] :=
      Table[If[k == l == j, f1[k, l, i, j], f2[k, l, i, j]], {i, 1,
        3}, {j, 1, 3}];

    Print[\!\(
    \*UnderoverscriptBox[\(\[Sum]\), \(k = 1\), \(3\)]\(
    \*UnderoverscriptBox[\(\[Sum]\), \(l = 1\), \(3\)]Det[G[k, l]]\)\)];
     
    Best regards
     
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook