Skip to main content
edited tags
Link
deleted 129 characters in body
Source Link
David G. Stork
  • 42.3k
  • 3
  • 37
  • 106

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]

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]}

{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]}

{-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]]}]]

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]" ]]]

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?

P.S. Sorry I don't know how to make my code look pretty, as in, look like Mathematica on stack exchange, a bit of help in that matter would be cool too.

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?

P.S. Sorry I don't know how to make my code look pretty, as in, look like Mathematica on stack exchange, a bit of help in that matter would be cool too.

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?

edited title
Link

Looking to remove Removing variable characters from set of solutions

Source Link
Loading