Mathematica Evaluating Determinant in Mathematica

  • Thread starter Thread starter EngWiPy
  • Start date Start date
  • Tags Tags
    Mathematica
AI Thread Summary
The discussion focuses on resolving an issue with evaluating the determinant of a matrix in Mathematica. The initial code fails because it uses "MatrixForm," which creates a display object instead of a mathematical one. To properly evaluate the determinant, the code should avoid "MatrixForm" and ensure that k and l are correctly indexed. A revised approach is suggested, using a table to create an indexable matrix, although this leads to complications in operations. The final code still produces unexpected results, prompting further inquiry into the errors and large outputs generated.
EngWiPy
Messages
1,361
Reaction score
61
Hello,

I have the following code in Mathematica:

Code:
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
 
Physics news on Phys.org
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 won't work). You'd have to male it a table again:
Det[Table[G[i, j], {i, 1, 3}, {j, 1, 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:
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
 

Similar threads

Replies
5
Views
3K
Replies
1
Views
2K
Replies
1
Views
1K
Replies
19
Views
2K
Replies
2
Views
2K
Replies
7
Views
2K
Replies
13
Views
2K
Replies
18
Views
4K
Back
Top