示例#1
0
 public static ComplexNumber Reciprocal(ComplexNumber c)
 {
     if (c.IsReal())
     {
         return(new ComplexNumber(1.0 / c.Real));
     }
     else
     {
         double square = Square(c);
         return(new ComplexNumber(c.Real / square, -c.Img / square));
     }
 }
示例#2
0
        public static ComplexNumber Exp(ComplexNumber exponent)
        {
            if (exponent.IsReal())
            {
                return(Math.Exp(exponent.Real));
            }

            double newRadius = Math.Exp(exponent.Real);
            double newAngle  = exponent.Img;

            return(ComplexNumber.FromPolarCoordinates(newRadius, newAngle));
        }
示例#3
0
        public static ComplexNumber Pow(ComplexNumber theBase, ComplexNumber exponent)
        {
            if (exponent.IsReal())
            {
                return(Pow(theBase, exponent.Real));
            }

            double baseRadius = theBase.PolarRadius;
            double baseAngle  = theBase.PolarAngleInRadians;

            double newRadius = Math.Pow(baseRadius, exponent.Real) * Math.Exp(-baseAngle * exponent.Img);
            double newAngle  = exponent.Img * Math.Log(baseRadius) + exponent.Real * baseAngle;

            return(ComplexNumber.FromPolarCoordinates(newRadius, newAngle));
        }
示例#4
0
        // same funtionality as below, but more efficient if we know exponent isn't complex
        public static ComplexNumber Pow(ComplexNumber theBase, double exponent)
        {
            if (theBase.Real >= 0 && theBase.IsReal())
            {
                return(Math.Pow(theBase.Real, exponent));
            }

            double baseRadius = theBase.PolarRadius;
            double baseAngle  = theBase.PolarAngleInRadians;

            double newRadius = Math.Pow(baseRadius, exponent);
            double newAngle  = exponent * baseAngle;

            return(ComplexNumber.FromPolarCoordinates(newRadius, newAngle));
        }