0
$\begingroup$

I am looking to simply take out the numeric parts of the solutions to a simple equation, i.e.

Roots[-z^4 + 6 z^2 - 1 == 0, z]

Gives

{z == -1 - Sqrt[2] || z == -1 + Sqrt[2] || z == 1 - Sqrt[2] ||   z ==
> 1 + Sqrt[2]}

But what I would really like is:

{-1 - Sqrt[2] ||-1 + Sqrt[2] || 1 - Sqrt[2] ||   1 + Sqrt[2]}

so that way I can do something like this:

Sols = Roots[-z^4 + 6 z^2 - 1 == 0, z]

For[i = 0, i <= Length[Sols], i++, 
 Residue[4 z/(-z^4 + 6 z^2 - 1), {z, Sols[[i]]}]] 

But, as of current, this will not evaluate since Mathematica doesn't know how to make sense of z == -1+$\sqrt2$ in the For loop, whereas it would be able to make sense of -1+$\sqrt2$ in the For loop.

My attempt at solving this problem was to brute force remove the "z==" stuff, but that doesn't seem to be working. This is the bit of code I wrote to do that:

For[i = 0, i <= Length[Sols], i++, 
 ReplacePart[Sols, i -> StringTrim[Sols[[i]], "z \[Equal]" ]]]

But clearly this won't work since Sols[[i]] is not a string. But I feel like something like this ought to exist. After all, finding solutions is only cool when you see what they do. Is there any way to do what I'm doing in a better way? Or is there some way to remove the "variable part" of the solution set?

$\endgroup$
4
  • $\begingroup$ Try {Map[Last, Roots[-z^4 + 6 z^2 - 1 == 0, z]]} $\endgroup$
    – user46676
    Commented Apr 5, 2017 at 1:35
  • $\begingroup$ You're working too hard: fz = z/(-z^4 + 6 z^2 - 1); Table[Residue[fz, {z, res}], {res, z /. Solve[Denominator[fz] == 0, z]}]. Replace Table[] with Sum[] if you're doing contour integration. $\endgroup$ Commented Apr 5, 2017 at 1:38
  • $\begingroup$ For fun - pattern matching: Roots[-z^4 + 6 z^2 - 1 == 0, z] /. Equal[a_, b_] :> b. $\endgroup$
    – corey979
    Commented Apr 5, 2017 at 10:46
  • $\begingroup$ @ J.M. How did you get the text to look like Mathematica code? $\endgroup$
    – Cuhrazatee
    Commented Apr 5, 2017 at 17:16

1 Answer 1

2
$\begingroup$

See the Everything is an expression tutorial.

Last /@ Roots[-z^4 + 6 z^2 - 1 == 0, z]
-1 - Sqrt[2] || -1 + Sqrt[2] || 1 - Sqrt[2] || 1 + Sqrt[2]

Hope this helps.

$\endgroup$

Your Answer

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

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