2
$\begingroup$

I would like to obtain the sum (or some other reduction) from a set which is the result of a previous operation:

NSolve[z^5 == 1, z, Complexes]

{{z -> -0.809017 - 0.587785 I}, {z -> -0.809017 + 0.587785 I}, {z -> 
   0.309017 - 0.951057 I}, {z -> 0.309017 + 0.951057 I}, {z -> 1.}}

How do I address these elements individually and how can I form a sum (or product)?

$\endgroup$
2
  • 2
    $\begingroup$ sol = NSolve[z^5 == 1, z, Complexes]; {Plus @@ (z /. sol), Times @@ (z /. sol)} $\endgroup$
    – cvgmt
    Commented Apr 11, 2023 at 7:28
  • 1
    $\begingroup$ Also Plus@@soln[[All,1,2]] and Times@@soln[[All,1,2]] $\endgroup$
    – user1066
    Commented Apr 11, 2023 at 7:54

1 Answer 1

7
$\begingroup$
solVals = Last /@ Flatten[NSolve[z^5 == 1, z, Complexes]]

solVals1 = NSolveValues[z^5 == 1, z, Complexes]

solVals == solVals1
(* True *)

 Plus @@ sol
(* 0.+0.I) 

 Times @@ sol
(1. + 0.I *)

For exact sum much better approach is

RootSum[#^5 - 1 &, # &]

(* 0 *)

$\endgroup$
4
  • 4
    $\begingroup$ For the product: Exp@RootSum[#^5 - 1 &, Log] gives $1$. $\endgroup$
    – Roman
    Commented Apr 11, 2023 at 9:08
  • $\begingroup$ @Acus: Mathematica 12 does not recognize NSolveValues; is it a new feature? $\endgroup$
    – Vectorizer
    Commented Apr 11, 2023 at 17:56
  • $\begingroup$ @Vectorizer Documentation says it was introduced in 2021, in version 12.3 $\endgroup$
    – Acus
    Commented Apr 12, 2023 at 6:23
  • $\begingroup$ @Acus: Thanks. I am using 12.0 $\endgroup$
    – Vectorizer
    Commented Apr 12, 2023 at 7:06

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.