1
$\begingroup$

Below is my toyproblem code I am trying to improve.

Remove["Global`*"];//Quiet
ClearAll;
matrix={{(2*x-5)^2+2,x+2},{x^5/(x-7)^2,1/x}};
matrix//MatrixForm
determinant=Det[matrix]
step1=Together[determinant]
step2=Factor[Distribute[x*(x-7)^2*step1]]
rootsWithDenominator=x/.NSolve[step1==0,x]//TableForm
rootsWithOutDenominator=x/.NSolve[step2==0,x]//TableForm

And the output is

(2+(-5+2 x)^2   2+x
x^5/(-7+x)^2    1/x)

-(1358/(-7+x)^2)+1323/((-7+x)^2 x)+(503 x)/(-7+x)^2-(76 x^2)/(-7+x)^2+(4 x^3)/(-7+x)^2-(2 x^5)/(-7+x)^2-x^6/(-7+x)^2

(1323-1358 x+503 x^2-76 x^3+4 x^4-2 x^6-x^7)/((-7+x)^2 x)

1323-1358 x+503 x^2-76 x^3+4 x^4-2 x^6-x^7

-3.74679+2.34084 I
-3.74679-2.34084 I
0.24533 +3.05429 I
0.24533 -3.05429 I
1.6188 +1.21207 I
1.6188 -1.21207 I
1.76533

-3.74679-2.34084 I
-3.74679+2.34084 I
 0.24533 -3.05429 I
 0.24533 +3.05429 I
 1.6188 -1.21207 I
 1.6188 +1.21207 I
 1.76533

My goal is to find all x's when determinant of matrix is equal to zero. As you can see, I have step2 to eliminate denominator which does not contribute to number of roots to find. When you look at the output of NSolve of step1 and step2 they look almost the same. However, for very complicated equation the difference is in speed (I've seen 10 fold increase in speed of finding roots.) Another difference is the order of roots that are placed in the column (note minus signs) Is there another way to implement step2 to eliminate denominators without typing in denominators and without going through the symbolic 'Solve' process? I have tried something like Simplify[step1==0]. But denominators are still there.

$\endgroup$
1
  • 2
    $\begingroup$ Maybe Numerator? $\endgroup$
    – John Doty
    Jul 6, 2017 at 0:13

2 Answers 2

1
$\begingroup$
x /. NSolve[Numerator@Together@Det[matrix] == 0, x] // TableForm

enter image description here

Check

sol = Det[matrix] // Together // Numerator;

Plot[sol, {x, 0, 3},
 Epilog -> {PointSize @ 0.02, Red,
   Point[Append[x /. NSolve[sol == 0, x, Reals], 0]]}]

enter image description here

$\endgroup$
1
$\begingroup$

I just realized that I could do this way,

step2=Factor[Distribute[Denominator[step1]*step1]]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.