Evaluating Determinant in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter EngWiPy
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary
SUMMARY

The forum discussion focuses on evaluating determinants in Mathematica, specifically addressing issues with the MatrixForm function. Users are advised to remove MatrixForm to ensure that the determinant is calculated as a numerical value rather than a display object. The correct approach involves defining the matrix without MatrixForm and ensuring that the indices k and l are correctly utilized to access the matrix elements. The final code provided successfully computes the determinant as intended.

PREREQUISITES
  • Mathematica programming language
  • Understanding of matrix operations
  • Familiarity with the determinant function in Mathematica
  • Knowledge of numerical integration in Mathematica
NEXT STEPS
  • Explore advanced matrix manipulation techniques in Mathematica
  • Learn about the use of NIntegrate for numerical computations in Mathematica
  • Study the properties of determinants and their applications in Mathematica
  • Investigate the implications of using display functions like MatrixForm in mathematical computations
USEFUL FOR

This discussion is beneficial for Mathematica users, mathematicians, and researchers who are working with matrix operations and determinants, particularly in the context of numerical analysis and integration.

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 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 18 ·
Replies
18
Views
5K