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
    Apr 11 at 7:28
  • 1
    $\begingroup$ Also Plus@@soln[[All,1,2]] and Times@@soln[[All,1,2]] $\endgroup$
    – user1066
    Apr 11 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
    Apr 11 at 9:08
  • $\begingroup$ @Acus: Mathematica 12 does not recognize NSolveValues; is it a new feature? $\endgroup$
    – Vectorizer
    Apr 11 at 17:56
  • $\begingroup$ @Vectorizer Documentation says it was introduced in 2021, in version 12.3 $\endgroup$
    – Acus
    Apr 12 at 6:23
  • $\begingroup$ @Acus: Thanks. I am using 12.0 $\endgroup$
    – Vectorizer
    Apr 12 at 7:06

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.