Esempio n. 1
0
        public PolynomialX Differentiate()
        {
            PolynomialX polynomial = new PolynomialX(Coefficients.Length - 1);

            for (int i = 1; i < Coefficients.Length; i++)
            {
                polynomial[i - 1] = i * this[i];
            }
            return(polynomial);
        }
 public static bool Verify(IntX[] output, PolynomialX poly, InputTypes type, int startingValue = -1, bool verify = false)
 {
     IntX[] input = GenerateInput(output, type, startingValue);
     for (int i = 0; i < output.Length; i++)
     {
         if (output[i] != poly.F(input[i]))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 3
0
        public PolynomialX DivideOutRoot(FractionX root)
        {
            var         copy   = Copy();
            PolynomialX result = new PolynomialX(Coefficients.Length - 1);
            FractionX   last   = Coefficients[Coefficients.Length - 1];

            result[result.Coefficients.Length - 1] = last;
            for (int i = Coefficients.Length - 3; i >= 0; i--)
            {
                copy[i + 1] += root * last;
                result[i]    = last = copy[i + 1];
            }
            return(result);
        }
        public static string[] BuildMessage(string output, InputTypes type, PolynomialX poly, TextFormat format, char functionVariable = 'x', string functionName = "f", int startingValue = -1)
        {
            string exportMessage;

            switch (type)
            {
            case InputTypes.Primes:
                exportMessage = "Input the first " + output.Length + " consecutive primes to get the message ASCII values for the string: \"" + output + "\".";
                break;

            case InputTypes.Recursive:
                exportMessage = "Input " + startingValue +
                                " into the following function and put the output into the function and repeat the recursive process to get the first "
                                + output.Length + " outputs which will corrospond to the ASCII values for the string: \"" + output + "\".";
                break;

            case InputTypes.RecursivePrimes:
                exportMessage = "Input " + startingValue +
                                " into the following function and multiply the output by the first prime number" +
                                ", then put that product into the function, repeat with the next output and the second consecutive prime prime" +
                                "and so on until "
                                + output.Length + " output values have been obtained.  These values will corospond to the ASCII values which give the following string: \"" + output + "\".";
                break;

            case InputTypes.PreviousProduct:
                exportMessage = "Input " + startingValue +
                                " into the following function and multiply the output by the previous input and put that into the function a total of "
                                + (output.Length - 1) + " times to get a total of " + output.Length + " output values will corrospond to the ASCII values for the string: \"" + output + "\".";
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(new string[]
            {
                exportMessage,
                functionName + "(" + functionVariable + ") = " + poly.ToString(functionVariable, format)
            });
        }
        public static PolynomialX Generate(IntX[] input, IntX[] output)
        {
            if (input.Length != output.Length)
            {
                return(null);
            }
            MatrixX A = new MatrixX(input.Length, input.Length);

            MatrixX column = new MatrixX(1, input.Length);

            for (int i = 0; i < input.Length; i++)
            {
                IntX prod = 1;
                for (int j = 0; j < input.Length; j++)
                {
                    A[j, i] = prod;
                    prod   *= input[i];
                }
                column[0, i] = output[i];
            }
            var det = A.Determinant();

            if (det == 0)
            {
                return(null);
            }
            var         adjoint = A.GetAdjointMatrix();
            PolynomialX poly    = new PolynomialX(input.Length);
            var         result  = adjoint * column;

            for (int i = 0; i < input.Length; i++)
            {
                poly.Coefficients[i] = (FractionX)result[i, 0] / det;
            }
            return(poly);
        }
 public static void Export(string path, string output, InputTypes type, PolynomialX poly, TextFormat format, char functionVariable = 'x', string functionName = "f", int startingValue = -1) =>
 File.WriteAllLines(path, BuildMessage(output, type, poly, format, functionVariable, functionName, startingValue));