예제 #1
0
    Complex CalcTheta()
    {
        Complex t = 0;

        t = Complex.Multiply(2, Complex.Acos(alpha));

        return(t);
    }
        private static void VerifyACos(double x, double y, double expectedReal, double expectedImaginary)
        {
            // for boundary values, ACos returns invalid Values

            Complex complex     = new Complex(x, y);
            Complex acosComplex = Complex.Acos(complex);

            Support.VerifyRealImaginaryProperties(acosComplex, expectedReal, expectedImaginary,
                                                  string.Format("AcOs({0}):{1}", complex, acosComplex));
        }
예제 #3
0
        public void ExecuteComplexNumberTest()
        {
            var complex = new Complex(3, 2);
            var exp     = new Arccos(new ComplexNumber(complex));
            var result  = (Complex)exp.Execute();

            Assert.Equal(Complex.Acos(complex), result);
            Assert.Equal(0.60613782238729386, result.Real, 15);
            Assert.Equal(-1.9686379257930964, result.Imaginary, 15);
        }
        /// <summary>
        /// Арккосинус
        /// </summary>
        /// <param name="Inp">Комплексный вектор значений для преобразования</param>
        public static ComplexVector arccos(ComplexVector Inp)
        {
            ComplexVector A = new ComplexVector(Inp.N);

            for (int i = 0; i < Inp.N; i++)
            {
                A.DataInVector[i] = Complex.Acos(Inp.DataInVector[i]);
            }

            return(A);
        }
예제 #5
0
 public static object Acos(object a)
 {
     if (a is Complex)
     {
         return(Complex.Acos((Complex)a));
     }
     else
     {
         return(Math.Acos(AsDouble(a)));
     }
 }
예제 #6
0
 public static void Main()
 {
     Complex[] values = { new Complex(.5,   2),
                          new Complex(.5,  -2),
                          new Complex(-.5,  2),
                          new Complex(-.3, -.8) };
     foreach (Complex value in values)
     {
         Console.WriteLine("Cos(ACos({0})) = {1}", value,
                           Complex.Cos(Complex.Acos(value)));
     }
 }
        private static void VerifyACos(Double x, Double y, Double expectedReal, Double expectedImaginary)
        {
            // for boundary values, ACos returns invalid Values

            Complex complex     = new Complex(x, y);
            Complex acosComplex = Complex.Acos(complex);

            if (false == Support.VerifyRealImaginaryProperties(acosComplex, expectedReal, expectedImaginary))
            {
                Console.WriteLine("Error AcOs-Err3A6s1N! AcOs({0})", complex, acosComplex);

                Assert.True(false, "Verification Failed");
            }
        }
        private static void VerifyACos(double x, double y)
        {
            // formula used in the feature: arccos(z) = -iln(z + iSqrt(value*value-1))
            // Verification is done with z = ACos(Cos(z));

            Complex complex     = new Complex(x, y);
            Complex cosComplex  = Complex.Cos(complex);
            Complex acosComplex = Complex.Acos(cosComplex);

            if (false == x.Equals((Double)acosComplex.Real) || false == y.Equals((Double)acosComplex.Imaginary))
            {
                double realDiff      = Math.Abs(Math.Abs(x) - Math.Abs(acosComplex.Real));
                double imaginaryDiff = Math.Abs(Math.Abs(y) - Math.Abs(acosComplex.Imaginary));
                Assert.False((realDiff > 0.1) || (imaginaryDiff > 0.1), string.Format("({0}) != ACos(Cos():{1}):{2}", complex, cosComplex, acosComplex));
            }
        }
        static string DoFunc1(Match m)
        {
            // function argument is 2nd group.
            Complex n1 = new Complex();

            n1 = GenerateComplexNumberFromString(m.Groups["No1"].Value);
            // function name is 1st group.
            switch (m.Groups["Function"].Value.ToUpper())
            {
            case "EXP":
                return(string.Format(new ComplexFormatter(), "{0:I0}", Complex.Exp(n1)));

            case "LOG":
                return(string.Format(new ComplexFormatter(), "{0:I0}", Complex.Log(n1)));

            case "LOG10":
                return(string.Format(new ComplexFormatter(), "{0:I0}", Complex.Log10(n1)));

            case "ABS":
                return(string.Format(new ComplexFormatter(), "{0:I0}", Complex.Abs(n1)));

            case "SQR":
            case "SQRT":
                return(string.Format(new ComplexFormatter(), "{0:I0}", Complex.Sqrt(n1)));

            case "SIN":
                return(string.Format(new ComplexFormatter(), "{0:I0}", Complex.Sin(n1)));

            case "COS":
                return(string.Format(new ComplexFormatter(), "{0:I0}", Complex.Cos(n1)));

            case "TAN":
                return(string.Format(new ComplexFormatter(), "{0:I0}", Complex.Tan(n1)));

            case "ASIN":
                return(string.Format(new ComplexFormatter(), "{0:I0}", Complex.Asin(n1)));

            case "ACOS":
                return(string.Format(new ComplexFormatter(), "{0:I0}", Complex.Acos(n1)));

            case "ATAN":
                return(string.Format(new ComplexFormatter(), "{0:I0}", Complex.Atan(n1)));

            default:
                return(Convert.ToString(1));
            }
        }
예제 #10
0
    [ImplicitConsts] public static Variable acos(Constants c, Variable a1)
    {
        P6any o1 = a1.Fetch();
        int   r1;

        if (!o1.mo.is_any)
        {
            return(HandleSpecial1(c, a1, o1, acos_d));
        }
        P6any n1 = GetNumber(a1, o1, out r1);

        if (r1 == NR_COMPLEX)
        {
            Complex v1 = PromoteToComplex(r1, n1);
            return(c.setting.MakeComplex(v1.Acos()));
        }
        {
            double v1 = PromoteToFloat(r1, n1);
            return(c.setting.MakeFloat(Math.Acos(v1)));
        }
    }
        private static void VerifyACos(Double x, Double y)
        {
            // formula used in the feature: arccos(z) = -iln(z + iSqrt(value*value-1))
            // Verification is done with z = ACos(Cos(z));

            Complex complex     = new Complex(x, y);
            Complex cosComplex  = Complex.Cos(complex);
            Complex acosComplex = Complex.Acos(cosComplex);

            if (false == x.Equals((Double)acosComplex.Real) || false == y.Equals((Double)acosComplex.Imaginary))
            {
                Double realDiff      = Math.Abs(Math.Abs(x) - Math.Abs(acosComplex.Real));
                Double imaginaryDiff = Math.Abs(Math.Abs(y) - Math.Abs(acosComplex.Imaginary));
                if ((realDiff > 0.1) || (imaginaryDiff > 0.1))
                {
                    Console.WriteLine("Error AcOs-Err3A6C6s! ({0}) != ACos(Cos():{1}):{2}", complex, cosComplex, acosComplex);

                    Assert.True(false, "Verification Failed");
                }
            }
        }
예제 #12
0
        /// <summary>
        /// Gets a function that computes the Jacobi elliptic inverse cn for parameter m.
        /// Use this instead of <see cref="arccn(Complex, double)"/> if you use the same value of m many times.
        /// </summary>
        public static Func <Complex, Complex> arccnComplex(double m)
        {
            var ef = FComplex(m);

            return(z => ef(Complex.Acos(z)));
        }
예제 #13
0
        /// <summary>
        /// Calls the compiled function (synonim to Call)
        /// </summary>
        /// <param name="variables">
        /// List arguments in the same order in which you compiled the function
        /// </param>
        /// <returns></returns>
        public ComplexNumber Substitute(params ComplexNumber[] variables)
        {
            if (variables.Length != varCount)
            {
                throw new SysException("Wrong amount of parameters");
            }
            Instruction instruction;

            for (int i = 0; i < instructions.Count; i++)
            {
                instruction = instructions[i];
                switch (instruction.Type)
                {
                case Instruction.InstructionType.PUSHVAR:
                    stack.Push(variables[instruction.VarNumber].AsComplex());
                    break;

                case Instruction.InstructionType.PUSHCONST:
                    stack.Push(instruction.Value);
                    break;

                case Instruction.InstructionType.CALL:
                    switch (instruction.FuncNumber)
                    {
                    case 0:
                        stack.Push(stack.Pop() + stack.Pop());
                        break;

                    case 1:
                        stack.Push(stack.Pop() - stack.Pop());
                        break;

                    case 2:
                        stack.Push(stack.Pop() * stack.Pop());
                        break;

                    case 3:
                        stack.Push(stack.Pop() / stack.Pop());
                        break;

                    case 4:
                        stack.Push(Complex.Pow(stack.Pop(), stack.Pop()));
                        break;

                    case 5:
                        stack.Push(Complex.Sin(stack.Pop()));
                        break;

                    case 6:
                        stack.Push(Complex.Cos(stack.Pop()));
                        break;

                    case 7:
                        stack.Push(Complex.Tan(stack.Pop()));
                        break;

                    case 8:
                        stack.Push(1 / Complex.Tan(stack.Pop()));
                        break;

                    case 9:
                        stack.Push(Complex.Log(stack.Pop(), stack.Pop().Real));
                        break;

                    case 10:
                        stack.Push(Complex.Asin(stack.Pop()));
                        break;

                    case 11:
                        stack.Push(Complex.Acos(stack.Pop()));
                        break;

                    case 12:
                        stack.Push(Complex.Atan(stack.Pop()));
                        break;

                    case 13:
                        stack.Push(Complex.Atan(1 / stack.Pop()));
                        break;
                    }
                    break;

                case Instruction.InstructionType.PULLCACHE:
                    stack.Push(Cache[instruction.CacheNumber]);
                    break;

                default:
                    Cache[instruction.CacheNumber] = stack.Peek();
                    break;
                }
            }
            var res = stack.Pop();

            RealNumber Normalize(double value)
            {
                if (value > maxDecimal)
                {
                    return(RealNumber.PositiveInfinity());
                }
                else if (value < minDecimal)
                {
                    return(RealNumber.NegativeInfinity());
                }
                else
                {
                    return(Number.Create(value));
                }
            }

            var re = Normalize(res.Real);
            var im = Normalize(res.Imaginary);

            return(Number.Create(re, im));
        }
예제 #14
0
 public static Complex Acos(Complex value)
 => Complex.Acos(value);
예제 #15
0
        static void SolveByViet(double a, double b, double c, double d, out Complex[] result)
        {
            b /= a; c /= a; d /= a;
            a  = b; b = c; c = d;

            double Q = (a * a - 3 * b) / 9;
            double R = (2 * Math.Pow(a, 3) - 9 * a * b + 27 * c) / 54;
            double S = Math.Pow(Q, 3) - Math.Pow(R, 2);

            result = new Complex[3];
            if (S > 0)
            {
                //Console.WriteLine("Comment: S > 0 (Tested)");//TODO del
                Complex fi = Complex.Acos(R / Complex.Pow(Q, 3.0 / 2)) / 3;
                result[0] = -2 * Complex.Sqrt(Q) * Complex.Cos(fi) - a / 3;
                result[1] = -2 * Complex.Sqrt(Q) * Complex.Cos(fi + 2.0 / 3 * Math.PI) - a / 3;
                result[2] = -2 * Complex.Sqrt(Q) * Complex.Cos(fi - 2.0 / 3 * Math.PI) - a / 3;
            }
            else if (S < 0)
            {
                if (Q > 0)
                {
                    //Console.WriteLine("Comment: S < 0   Q > 0 (Tested)");//TODO del
                    Complex fi       = Arch(Math.Abs(R) / Math.Pow(Q, 3.0 / 2)) / 3;
                    Complex tmValue1 = Math.Sign(R) * Math.Sqrt(Q) * Complex.Cosh(fi);
                    Complex tmValue2 = Complex.ImaginaryOne * Math.Sqrt(3) *
                                       Math.Sqrt(Q) * Complex.Sinh(fi);

                    result[0] = -2 * tmValue1 - a / 3;
                    result[1] = tmValue1 - a / 3 + tmValue2;
                    result[2] = tmValue1 - a / 3 - tmValue2;
                }
                else if (Q < 0)
                {
                    //Console.WriteLine("Comment: S < 0   Q < 0 (Tested)");//TODO del
                    Complex fi       = Arsh(Math.Abs(R) / Math.Pow(Math.Abs(Q), 3.0 / 2)) / 3;
                    Complex tmValue1 = Math.Sign(R) * Math.Sqrt(Math.Abs(Q)) * Complex.Sinh(fi);
                    Complex tmValue2 = Complex.ImaginaryOne * Math.Sqrt(3) *
                                       Math.Sqrt(Math.Abs(Q)) * Complex.Cosh(fi);

                    result[0] = -2 * tmValue1 - a / 3;
                    result[1] = tmValue1 - a / 3 + tmValue2;
                    result[2] = tmValue1 - a / 3 - tmValue2;
                }
                else
                {
                    //Console.WriteLine("Comment: S < 0   Q = 0 (Tested)");//TODO del
                    double tmValue = c - Math.Pow(a, 3) / 27;
                    result[0] = -Math.Sign(tmValue) * Math.Pow(Math.Abs(tmValue), 1.0 / 3) -
                                a / 3;
                    result[1] = -(a + result[0]) / 2 + Complex.ImaginaryOne / 2 *
                                Math.Sqrt(Complex.Abs((a - 3 * result[0]) * (a + result[0]) - 4 * b));
                    result[2] = -(a + result[0]) / 2 - Complex.ImaginaryOne / 2 *
                                Math.Sqrt(Complex.Abs((a - 3 * result[0]) * (a + result[0]) - 4 * b));
                }
            }
            else
            {
                //Console.WriteLine("Comment: S = 0 (Tested)");
                result[0] = -2 * Complex.Pow(R, 1.0 / 3) - a / 3;
                result[1] = Complex.Pow(R, 1.0 / 3) - a / 3;
                result[2] = result[1];
            }
        }
예제 #16
0
 /// <summary>
 /// Returns the angle that is the arc cosine of the specified sequence of complex numbers.
 /// </summary>
 /// <param name="source">
 /// A sequence of complex numbers that represent the cosine.
 /// </param>
 /// <returns>
 /// The angle, measured in radians, which is the arc cosine of value.
 /// </returns>
 public static MathEnumerable <Complex> Acos(this MathEnumerable <Complex> source)
 {
     return(source.Select(c => Complex.Acos(c)));
 }
예제 #17
0
 /// <summary>
 /// Returns a cvec3 from component-wise application of Acos (Complex.Acos(v)).
 /// </summary>
 public static Complex Acos(Complex v) => Complex.Acos(v);
예제 #18
0
 /// <summary>
 /// Jacobi elliptic inverse cn.
 /// </summary>
 public static Complex arccn(Complex z, double m)
 {
     return(F(Complex.Acos(z), m));
 }
예제 #19
0
 public static Complex Asec(Complex a)
 => Complex.Acos(1 / a);
        /// <summary>
        /// Calls the compiled function (synonim to Call)
        /// </summary>
        /// <param name="values">
        /// List arguments in the same order in which you compiled the function
        /// </param>
        /// <returns></returns>
        // TODO: Optimization
        public Complex Substitute(params Complex[] values)
        {
            if (values.Length != varCount)
            {
                throw new SysException("Wrong amount of parameters");
            }
            Instruction instruction;

            for (int i = 0; i < instructions.Count; i++)
            {
                instruction = instructions[i];
                switch (instruction.Type)
                {
                case Instruction.InstructionType.PUSHVAR:
                    stack.Push(values[instruction.VarNumber]);
                    break;

                case Instruction.InstructionType.PUSHCONST:
                    stack.Push(instruction.Value);
                    break;

                case Instruction.InstructionType.CALL:
                    switch (instruction.FuncNumber)
                    {
                    case 0:
                        stack.Push(stack.Pop() + stack.Pop());
                        break;

                    case 1:
                        stack.Push(stack.Pop() - stack.Pop());
                        break;

                    case 2:
                        stack.Push(stack.Pop() * stack.Pop());
                        break;

                    case 3:
                        stack.Push(stack.Pop() / stack.Pop());
                        break;

                    case 4:
                        stack.Push(Complex.Pow(stack.Pop(), stack.Pop()));
                        break;

                    case 5:
                        stack.Push(Complex.Sin(stack.Pop()));
                        break;

                    case 6:
                        stack.Push(Complex.Cos(stack.Pop()));
                        break;

                    case 7:
                        stack.Push(Complex.Tan(stack.Pop()));
                        break;

                    case 8:
                        stack.Push(1 / Complex.Tan(stack.Pop()));
                        break;

                    case 9:
                        stack.Push(Complex.Log(stack.Pop(), stack.Pop().Real));
                        break;

                    case 10:
                        stack.Push(Complex.Asin(stack.Pop()));
                        break;

                    case 11:
                        stack.Push(Complex.Acos(stack.Pop()));
                        break;

                    case 12:
                        stack.Push(Complex.Atan(stack.Pop()));
                        break;

                    case 13:
                        stack.Push(Complex.Atan(1 / stack.Pop()));
                        break;
                    }
                    break;

                case Instruction.InstructionType.PULLCACHE:
                    stack.Push(Cache[instruction.CacheNumber]);
                    break;

                default:
                    Cache[instruction.CacheNumber] = stack.Peek();
                    break;
                }
            }

            return(stack.Pop());
        }
예제 #21
0
 public SqlComplex Acos()
 {
     return(_value.HasValue ? Complex.Acos(_value.Value) : @null);
 }
 private static Complex Acos(Complex[] args) => Complex.Acos(args.Check(1)[0]);
 public override Complex Compute(Complex z) => Complex.Acos(Arguments[0].Compute(z));
예제 #24
0
 /// <summary>
 /// Evaluates the function on a scalar argument.
 /// </summary>
 /// <param name="Argument">Function argument.</param>
 /// <param name="Variables">Variables collection.</param>
 /// <returns>Function result.</returns>
 public override IElement EvaluateScalar(Complex Argument, Variables Variables)
 {
     return(new ComplexNumber(Complex.Acos(Argument)));
 }
예제 #25
0
 public static Complex Acos(Complex value)
 {
     return(Complex.Acos(value));
 }
예제 #26
0
 /// <summary>
 /// Calculates the exact value of arccosine of num
 /// </summary>
 /// <param name="num"></param>
 /// <returns></returns>
 public static ComplexNumber Arccos(Number num)
 => (num as ComplexNumber).IsDefinite()
         ? Functional.Downcast(Complex.Acos(num.AsComplex())) as ComplexNumber
         : RealNumber.NaN();
예제 #27
0
 /// <summary>
 /// Calculates the this mathematical expression (complex number).
 /// </summary>
 /// <param name="parameters">An object that contains all parameters and functions for expressions.</param>
 /// <returns>
 /// A result of the calculation.
 /// </returns>
 protected override Complex ExecuteComplex(ExpressionParameters parameters)
 {
     return(Complex.Acos((Complex)m_argument.Execute(parameters)));
 }
예제 #28
0
 public static Complex Acos(Complex a)
 => Complex.Acos(a);
예제 #29
0
파일: Arccos.cs 프로젝트: suigin500/xFunc
 /// <summary>
 /// Calculates the this mathematical expression (complex number).
 /// </summary>
 /// <param name="complex">The calculation result of argument.</param>
 /// <returns>
 /// A result of the calculation.
 /// </returns>
 protected override Complex ExecuteComplex(Complex complex)
 {
     return(Complex.Acos(complex));
 }
예제 #30
0
 public override object Evaluate()
 {
     return(Complex.Acos(SubExpression.EvaluateAsComplex()));
 }