Evaluating Determinant in Mathematica

  • Mathematica
  • Thread starter EngWiPy
  • Start date
  • Tags
    Mathematica
In summary, the code is trying to determine the determinant of a matrix, but is getting an error. It works when k and l are not the indices of the matrix.
  • #1
EngWiPy
1,368
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
  • #2
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}]]
 
  • #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
 

Related to Evaluating Determinant in Mathematica

1. What is a determinant in mathematics?

A determinant is a numerical value that can be calculated from a square matrix. It represents important information about the matrix, including whether it has an inverse and how much the matrix expands or shrinks when multiplied by another matrix.

2. How can I calculate the determinant of a matrix in Mathematica?

To calculate the determinant of a matrix in Mathematica, you can use the built-in function "Det". For example, if your matrix is called "A", you can use the command "Det[A]" to calculate its determinant.

3. What does the determinant tell us about a matrix?

The determinant tells us important information about a matrix, such as whether it has an inverse and how much the matrix expands or shrinks when multiplied by another matrix. It can also be used to solve systems of linear equations and determine the volume of geometric shapes.

4. Can Mathematica handle large determinants?

Yes, Mathematica can handle large determinants with ease. It has powerful built-in functions and algorithms for calculating determinants of matrices of any size, making it a useful tool for mathematicians and scientists working with complex data.

5. Are there any special considerations when evaluating determinants in Mathematica?

One important consideration when evaluating determinants in Mathematica is the precision of the results. By default, Mathematica uses machine precision which may not be suitable for highly accurate calculations. It is recommended to use the "WorkingPrecision" option to specify a higher precision value for more accurate results.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
277
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
Back
Top