コード例 #1
0
        /// <summary>
        /// Returns a <see cref="T:System.String" /> complex number in x + yi or x + yj text format raised to a power.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 2 items: inumber, number.
        /// </para>
        /// <para>
        /// Inumber is a complex number you want to raise to a power.
        /// </para>
        /// <para>
        /// Number is the power to which you want to raise the complex number.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.String" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            double num;

            base.CheckArgumentsLength(args);
            Complex complex = ComplexConvert.ToComplex(args[0]);

            if (!CalcConvert.TryToDouble(args[1], out num, true))
            {
                return(CalcErrors.Value);
            }
            double real = complex.Real;
            double imag = complex.Imag;

            if ((real == 0.0) && (imag == 0.0))
            {
                if (num > 0.0)
                {
                    return(ComplexConvert.ToResult(new Complex(0.0, 0.0)));
                }
                return(CalcErrors.Number);
            }
            double x    = Math.Sqrt((real * real) + (imag * imag));
            double num5 = Math.Atan2(imag, real);

            return(ComplexConvert.ToResult(new Complex(Math.Pow(x, num) * Math.Cos(num * num5), Math.Pow(x, num) * Math.Sin(num * num5))));
        }
コード例 #2
0
ファイル: CalcImAbsFunction.cs プロジェクト: Daoting/dt
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> absolute value (modulus) of a complex number in x + yi or x + yj text format.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 1 item: inumber.
        /// </para>
        /// <para>
        /// Inumber is a complex number for which you want the absolute value.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            Complex complex = ComplexConvert.ToComplex(args[0]);
            double  real    = complex.Real;
            double  imag    = complex.Imag;

            return(CalcConvert.ToResult(Math.Sqrt((real * real) + (imag * imag))));
        }
コード例 #3
0
        /// <summary>
        /// Returns the <see cref="T:System.String" /> exponential of a complex number in x + yi or x + yj text format.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 1 item: inumber.
        /// </para>
        /// <para>
        /// Inumber is a complex number for which you want the exponential.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.String" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            Complex complex = ComplexConvert.ToComplex(args[0]);
            double  real    = complex.Real;
            double  imag    = complex.Imag;

            return(ComplexConvert.ToResult(new Complex(Math.Exp(real) * Math.Cos(imag), Math.Exp(real) * Math.Sin(imag))));
        }
コード例 #4
0
ファイル: CalcImSubFunction.cs プロジェクト: Daoting/dt
        /// <summary>
        /// Returns the <see cref="T:System.String" /> difference of two complex numbers in x + yi or x + yj text format.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 2 items: inumber1, inumber2.
        /// </para>
        /// <para>
        /// Inumber1 is the complex number from which to subtract inumber2.
        /// </para>
        /// <para>
        /// Inumber2 is the complex number to subtract from inumber1.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.String" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            Complex complex  = ComplexConvert.ToComplex(args[0]);
            Complex complex2 = ComplexConvert.ToComplex(args[1]);
            double  real     = complex.Real;
            double  imag     = complex.Imag;
            double  num3     = complex2.Real;
            double  num4     = complex2.Imag;

            return(ComplexConvert.ToResult(new Complex(real - num3, imag - num4)));
        }
コード例 #5
0
ファイル: CalcImArgumentFunction.cs プロジェクト: Daoting/dt
        /// <summary>
        /// Returns the <see cref="T:System.Double" /> argument (theta), an angle expressed in radians.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 1 item: inumber.
        /// </para>
        /// <para>
        /// Inumber is a complex number for which you want the argument .
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            Complex complex = ComplexConvert.ToComplex(args[0]);
            double  real    = complex.Real;
            double  imag    = complex.Imag;

            if ((real == 0.0) && (imag == 0.0))
            {
                return(CalcErrors.DivideByZero);
            }
            return(CalcConvert.ToResult(Math.Atan2(imag, real)));
        }
コード例 #6
0
ファイル: CalcImDivFunction.cs プロジェクト: Daoting/dt
        /// <summary>
        /// Returns the <see cref="T:System.String" /> quotient of two complex numbers in x + yi or x + yj text format.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 2 items: inumber1, inumber2.
        /// </para>
        /// <para>
        /// Inumber1 is the complex numerator or dividend.
        /// </para>
        /// <para>
        /// Inumber2 is the complex denominator or divisor.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.String" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            Complex complex  = ComplexConvert.ToComplex(args[0]);
            Complex complex2 = ComplexConvert.ToComplex(args[1]);
            double  real     = complex.Real;
            double  imag     = complex.Imag;
            double  num3     = complex2.Real;
            double  num4     = complex2.Imag;

            if ((num3 == 0.0) && (num4 == 0.0))
            {
                return(CalcErrors.Number);
            }
            return(ComplexConvert.ToResult(new Complex(((real * num3) + (imag * num4)) / ((num3 * num3) + (num4 * num4)), ((imag * num3) - (real * num4)) / ((num3 * num3) + (num4 * num4)))));
        }
コード例 #7
0
        /// <summary>
        /// Returns the <see cref="T:System.String" /> natural logarithm of a complex number in x + yi or x + yj text format.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 1 item: inumber.
        /// </para>
        /// <para>
        /// Inumber is a complex number for which you want the natural logarithm.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.String" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            Complex complex = ComplexConvert.ToComplex(args[0]);
            double  real    = complex.Real;
            double  imag    = complex.Imag;

            if ((real == 0.0) && (imag == 0.0))
            {
                return(CalcErrors.Number);
            }
            double d    = Math.Sqrt((real * real) + (imag * imag));
            double num4 = Math.Atan2(imag, real);

            return(ComplexConvert.ToResult(new Complex(Math.Log(d), num4)));
        }
コード例 #8
0
ファイル: CalcComplexFunction.cs プロジェクト: Daoting/dt
        /// <summary>
        /// Returns the <see cref="T:System.String" /> complex number given the real and imaginary coefficient.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 2 - 3 items: real_num, i_num, [suffix].
        /// </para>
        /// <para>
        /// Real_num is the real coefficient of the complex number.
        /// </para>
        /// <para>
        /// I_num is the imaginary coefficient of the complex number.
        /// </para>
        /// <para>
        /// Suffix is the suffix for the imaginary component of the complex number.
        /// If omitted, suffix is assumed to be "i".
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.String" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            double num;
            double num2;

            base.CheckArgumentsLength(args);
            if (!CalcConvert.TryToDouble(args[0], out num, true) || !CalcConvert.TryToDouble(args[1], out num2, true))
            {
                return(CalcErrors.Value);
            }
            string suffix = CalcHelper.ArgumentExists(args, 2) ? CalcConvert.ToString(args[2]) : "i";

            if ((suffix != "i") && (suffix != "j"))
            {
                return(CalcErrors.Value);
            }
            return(ComplexConvert.ToResult(new Complex(num, num2), suffix));
        }
コード例 #9
0
        /// <summary>
        /// Returns the <see cref="T:System.String" /> product of 1 to 255 complex numbers in x + yi or x + yj text format.
        /// </summary>
        /// <param name="args"><para>
        /// The args contains 1 - 255 items: inumber1, [inumber2], [inumber3], ..
        /// </para>
        /// <para>
        /// Inumber1, inumber2,¡­   are 1 to 255 complex numbers to multiply.
        /// </para></param>
        /// <returns>
        /// A <see cref="T:System.String" /> value that indicates the evaluate result.
        /// </returns>
        public override object Evaluate(object[] args)
        {
            base.CheckArgumentsLength(args);
            double real = 1.0;
            double imag = 0.0;

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] is CalcArray)
                {
                    CalcArray array = (CalcArray)args[i];
                    for (int j = 0; j < array.RowCount; j++)
                    {
                        for (int k = 0; k < array.ColumnCount; k++)
                        {
                            Complex complex = ComplexConvert.ToComplex(array.GetValue(j, k));
                            double  num6    = real;
                            double  num7    = imag;
                            double  num8    = complex.Real;
                            double  num9    = complex.Imag;
                            real = (num6 * num8) - (num7 * num9);
                            imag = (num6 * num9) + (num7 * num8);
                        }
                    }
                }
                else
                {
                    Complex complex2 = ComplexConvert.ToComplex(args[i]);
                    double  num10    = real;
                    double  num11    = imag;
                    double  num12    = complex2.Real;
                    double  num13    = complex2.Imag;
                    real = (num10 * num12) - (num11 * num13);
                    imag = (num10 * num13) + (num11 * num12);
                }
            }
            return(ComplexConvert.ToResult(new Complex(real, imag)));
        }
コード例 #10
0
ファイル: DObject.cs プロジェクト: QsCompany/Q.Net
 public ComplexConverter(String dbType, ComplexConvert ToCsValue, Convert ToDbValue)
     : base(ToDbValue, dbType)
 {
     this.ToCsValue = ToCsValue;
 }
コード例 #11
0
ファイル: CalcImaginaryFunction.cs プロジェクト: Daoting/dt
 /// <summary>
 /// Returns the <see cref="T:System.Double" /> imaginary coefficient of a complex number in x + yi or x + yj text format.
 /// </summary>
 /// <param name="args"><para>
 /// The args contains 1 item: inumber.
 /// </para>
 /// <para>
 /// Inumber is a complex number for which you want the imaginary coefficient.
 /// </para></param>
 /// <returns>
 /// A <see cref="T:System.Double" /> value that indicates the evaluate result.
 /// </returns>
 public override object Evaluate(object[] args)
 {
     base.CheckArgumentsLength(args);
     return(CalcConvert.ToResult(ComplexConvert.ToComplex(args[0]).Imag));
 }