Download MuPAD from SciFace

MuPAD Pro Computing Essentials - Examples 

Example 9.5 - Roots of complex numbers

Moivre := proc(z:Type::Complex,n:Type::Integer)

/* This procedure will calculate n complex
   roots of a given complex number z  */
local r, k, roots, angle,newr, newRe, newIm, nthroot;
begin
   r := abs(z);
   newr := r^(1/n);
   angle := arg(z);
   newangle := angle/n;
   a := 2*PI/n;
   roots := [];
   for k from 0 to (n-1) do
      newRe := cos(newangle + k*a);
      newIm := sin(newangle + k*a);
      nthroot := newr*(newRe+I*newIm);
      roots :=roots.[nthroot];
   end;
   return(roots)
end:
 
Moivre(-8,3)
 
TOP