Exemple #1
0
    /// <summary>
    /// Splits the string from the input field at every space and adds the elements to a float array
    /// converts the values from the array to a list of Monoms
    /// </summary>
    public void NumbersToPolynom()
    {
        PolynomialEquation = new List <Monom>();
        numbersString      = null;
        numbersString      = inputNumbers.text.Trim().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

        if (numbersString != null)
        {
            numbersArray = new float[numbersString.Length];

            for (int i = 0; i < numbersString.Length; i++)
            {
                numbersArray[i] = float.Parse(numbersString[i].Trim());
            }

            for (int i = numbersArray.Length - 1; i >= 0; i--)
            {
                var monomObj = new Monom(numbersArray[numbersArray.Length - 1 - i], i);
                if (!string.IsNullOrEmpty(monomObj.MonomString()))
                {
                    PolynomialEquation.Add(monomObj);
                }
            }

            if (PolynomialEquation.Count > 0)
            {
                resultText.text = string.Join(" ", MonomUtils.PrintPolynomial(PolynomialEquation));
            }
            else
            {
                resultText.text = "Polynom is 0.";
            }
        }
    }
    /// <summary>
    /// this function is called when you press Divide button on UI, it needs refference in button component
    /// it shows the resulted polynom on UI
    /// </summary>
    public void OnDividePress()
    {
        ResultedPolynomialEquation = new List <Monom>();

        if (polynomial1Input.PolynomialEquation.Count == 0 || polynomial2Input.PolynomialEquation.Count == 0)
        {
            resultedPolynomial.text = "Division by 0 is not posible";
        }
        else if (polynomial1Input.PolynomialEquation.Count < polynomial2Input.PolynomialEquation.Count)
        {
            resultedPolynomial.text = "The second polynom is greater than the first one.";
        }
        else
        {
            var remainder = new List <Monom>();
            remainder = DividePolynomials(polynomial1Input.PolynomialEquation, polynomial2Input.PolynomialEquation);

            if (ResultedPolynomialEquation.Count > 0)
            {
                if (remainder != null)
                {
                    resultedPolynomial.text = string.Join(" ", MonomUtils.PrintPolynomial(ResultedPolynomialEquation)) + "\n with remainder: " + string.Join(" ", MonomUtils.PrintPolynomial(remainder));
                }
                else
                {
                    resultedPolynomial.text = string.Join(" ", MonomUtils.PrintPolynomial(ResultedPolynomialEquation));
                }
            }
            else
            {
                resultedPolynomial.text = "Polynom is 0.";
            }
        }
    }
Exemple #3
0
    /// <summary>
    /// this function is called when the user presses the button Integrate
    /// it calls the Integrate funtion above and prints the result to interface
    /// </summary>
    public void OnIntegratePress()
    {
        IntegratePolynomial();
        operationToPolynomial.text = "Polynomial integrated is: ";

        if (resultedPolynomialEquation.Count > 0)
        {
            resultedPolynomial.text = string.Join(" ", MonomUtils.PrintPolynomial(resultedPolynomialEquation)) + " + C";
        }
        else
        {
            resultedPolynomial.text = "Polynomial is 0.";
        }
    }
Exemple #4
0
    /// <summary>
    /// this function is called when the user presses the button Derivative
    /// it calls the Derivative funtion above and prints the result to interface
    /// </summary>
    public void OnDerivativePress()
    {
        DerivativePolynomial();
        operationToPolynomial.text = "Derivative polynomial is: ";

        if (resultedPolynomialEquation.Count > 0)
        {
            resultedPolynomial.text = string.Join(" ", MonomUtils.PrintPolynomial(resultedPolynomialEquation));
        }
        else
        {
            resultedPolynomial.text = "Polynomial is 0.";
        }
    }
    /// <summary>
    /// this function is called when you press Multiply button on UI, it needs refference in button component
    /// it shows the resulted polynom on UI
    /// </summary>
    public void OnMultiplyPress()
    {
        MultiplyArrays();
        ResultedPolynomialEquation = AddEquation(resultedAddedEquation);

        if (ResultedPolynomialEquation.Count > 0)
        {
            resultedPolynomial.text = string.Join(" ", MonomUtils.PrintPolynomial(ResultedPolynomialEquation));
        }
        else
        {
            resultedPolynomial.text = "Polynom is 0.";
        }
    }
    /// <summary>
    /// this function is called when you press Substract button on UI, it needs refference in button component
    /// it shows the resulted polynom on UI
    /// </summary>
    public void OnSubstractPress()
    {
        AddOrSubPolynomials(false);
        ResultedPolynomialEquation = AddEquation(resultedAddedEquation);

        if (ResultedPolynomialEquation.Count > 0)
        {
            resultedPolynomial.text = string.Join(" ", MonomUtils.PrintPolynomial(ResultedPolynomialEquation));
        }
        else
        {
            resultedPolynomial.text = "Polynom is 0.";
        }
    }