# Mathematica function Det has unexpected behavior

I am using Mathematica "Kernel" -> {"Version" -> "9.0 for Microsoft Windows (64-bit) (January 25, 2013)", "ReleaseID" -> "9.0.1.0 (4055652, 4055188)" on a Win 7 machine.

The file listed below uses the Mathematica function Det to compute the determinant of a matrix whose matrix elements are either:

[1] 0

[2] const + const * m^2 , m may be complex

[3] const * k^2

[4] const * w^2

This file computes the determinant of four different matrices. The first two seem OK.

However, for the last two determinants [in BOLD], Mathematica has given each result as a RATIO, where the denominator of the ratio may, in fact, vanish.

Since the determinant is an algebraic sum of products of matrix elements, I do not understand where the denominators of the last two determinants come from. Does anyone know how to prohibit Mathematica from dividing?

ssg={sg->2^(1/3) Gamma[2/3]};

sys[nt_,start_][k_,w_,m_]:=

Module[{n,var,D5,D6,cLD600,cLD6,residu,ca,q,nx,ret},
If[Not[0=== start || 1=== start],Return[{{}}]];
n=2nt+1;
Print[n(2nt+1)," VARIABLES; ",n(2nt+1+2)," EQUATIONS: TOO MANY EQUATIONS"];
Print[2n," = # EXTRA EQUATIONS"];
If[1=== start,nx=2 n-1];
If[0=== start,nx=2(n-1)];
If[1=== start,q=If[#>= 0,F[#1,#2],-F[-#1,#2]]&];
If[0=== start,q=If[#>= 0,F[#1,#2],F[-#1,#2]]&];
var=Flatten[ParallelTable[q[n8,j],{n8,start,nx,2},{j,-nt,nt}]];
D5=ParallelTable[Sum[-(3/20) X^j q[n8,j]-1/2 m^2 X^j q[n8,j]-n8^2 X^j q[n8,j]-1/2 X^-1 k^2 sg X^j q[n8,j]+1/2 X w^2 sg X^j q[n8,j]-1/9 X^j j^2 q[n8,j]-1/2 X^-1 k^2 sg Sum[((-1)^n8m8 (X^j UnitStep[-2n8m8+n8+nx]q[n8-2 n8m8,j]+X^j UnitStep[nx-(2n8m8+n8)]q[n8+2 n8m8,j]))/(Gamma[5/6-n8m8] Gamma[5/6+n8m8]),{n8m8,1,nx}]+1/2 X w^2 sg Sum[ ((-1)^n8m8 (X^j UnitStep[-2n8m8+n8+nx]q[n8-2 n8m8,j]+X^j UnitStep[nx-(2n8m8+n8)]q[n8+2 n8m8,j]))/(Gamma[5/6-n8m8] Gamma[5/6+n8m8]),{n8m8,1,nx}],{j,-nt,nt}],{n8,start,nx,2}];
D6=ExpandAll[X^(1+nt) D5];
cLD600=Flatten[CoefficientList[D6,X]];
cLD6=Drop[Drop[cLD600,-n],n];
residu=Flatten[{Take[cLD600,n],Take[cLD600,-n]}];
ca=CoefficientArrays[Block[{u},
u=Flatten[cLD6];
ret={var,ca,residu};
ret
]

(* EXAMPLE 1 *)

s1odd=sys[1,1][k,w,m];

Expand[FullSimplify[Det[N[Normal[s1odd[[2]][[2]]]/.ssg]/.{k^2->KS,w^2->KT,m^2->M}]/.{0.->0}]/.{KT->W/KS}]

(* 0.886661 W^3+0.146364 M W^3+0.0080522 M^2 W^3+0.000147638 M^3 W^3-5.43201*10^-18 W^4-2.51499*10^-19 M W^4

(* EXAMPLE 2 *)

s1even=sys[1,0][k,w,m];

Expand[FullSimplify[Det[N[Normal[s1even[[2]][[2]]]/.ssg]/.{k^2->KS,w^2->KT,m^2->M}]/.{0.->0}]/.{KT->W/KS}]

(* 0.541822 W^3+0.21145 M W^3+0.0273022 M^2 W^3+0.00116764 M^3 W^3-1.11445*10^-17 W^4-1.47813*10^-19 M W^4 *)

(* EXAMPLE 3 ; PROBLEM WITH Det[] *)

s2odd=sys[2,1][k,w,m];

s2odd[[2]]

(* {SparseArray[<0>,{25}],SparseArray[<187>,{25,25}]} *)

(N[Normal[s2odd[[2]][[2]]]/.ssg]/.{0.->0})[[1]]

(* {0,0,0,0.719142 w^2,-1.59444-0.5 m^2,0,0,0,0.0486904 w^2,0,0,0,0,0.020049 w^2,0,0,0,0,0.011332 w^2,0,0,0,0,0.00742443 w^2,0} *)

Det[N[Normal[s2odd[[2]][[2]]]/.ssg]]/.{0.->0}
Denominator[%]
FullSimplify[%]

(* -(NUMERATOR)/(k^142 w^170 (3.41252*10^-54 k^30 w^2+3.47154*10^-56 k^30 m^2 w^2)^2)

k^142 w^170 (3.41252*10^-54 k^30 w^2+3.47154*10^-56 k^30 m^2 w^2)^2

**k^202 (3.41252*10^-54+3.47154*10^-56 m^2)^2 w^174**  *)

(* EXAMPLE 4 ; PROBLEM WITH Det[] *)

s2even=sys[2,0][k,w,m];

s2even[[2]]

(* {SparseArray[<0>,{25}],SparseArray[<187>,{25,25}]} *)

(N[Normal[s2even[[2]][[2]]]/.ssg]/.{0.->0})[[1]]

(* {0,0,0,0.853041 w^2,-0.594444-0.5 m^2,0,0,0,0.267797 w^2,0,0,0,0,0.170416 w^2,0,0,0,0,0.130318 w^2,0,0,0,0,0.107654 w^2,0} *)

Det[N[Normal[s2even[[2]][[2]]]/.ssg]]/.{0.->0};
Denominator[%]
FullSimplify[%]

(* k^118 w^206 (1.96078*10^-19 k^6 w^14+2.712*10^-21 k^6 m^2 w^14)^4

k^142 (1.96078*10^-19+2.712*10^-21 m^2)^4 w^262 *)

-
Please put all code in a code block, otherwise it is unreadable and people are not going to look at the problem. Formatting help is on the right of the edit box. – Szabolcs Apr 17 '14 at 18:05
Also, please remove or comment out In/Out tags. Otherwise, people who wish to run the code will have to make modifications first. The normal way to signify an output on this site is to include it as a comment, such as (* -> output *). – Oleksandr R. Apr 17 '14 at 18:21