Пример #1
0
        /// <summary>
        /// Responds to button click by pulling data from text boxes and calling appropriate method
        /// </summary>
        /// <param name="sender">The object that send the event argument.</param>
        /// <param name="e">The event argument.</param>
        private void EulerButton_Click(object sender, EventArgs e)
        {
            FunctionEval func = new FunctionEval();

            try
            {
                if (!string.IsNullOrEmpty(FunctionBox.Text) && !string.IsNullOrEmpty(InitialPointBox.Text) && !string.IsNullOrEmpty(EndValueBox.Text))
                {
                    String[] values = InitialPointBox.Text.Replace("(", "").Replace(")", "").Split(',');
                    double   x      = Double.Parse(values[0].Trim());
                    double   y      = Double.Parse(values[1].Trim());

                    if (this.Text == "Euler's Method")
                    {
                        ResultBox.Text = func.Euler(FunctionBox.Text, x, y, Double.Parse(EndValueBox.Text)).ToString();
                    }
                    else if (this.Text == "Heun's Method")
                    {
                        ResultBox.Text = func.Heun(FunctionBox.Text, x, y, Double.Parse(EndValueBox.Text)).ToString();
                    }
                }
                else
                {
                    ResultBox.Text = "All data required";
                }
            }
            catch (Exception ex)
            {
                ResultBox.Text = "Error: " + ex;
            }
        }
Пример #2
0
        /// <summary>
        /// Performs a function evaluation on the math string that has been built prior to this method call
        /// </summary>
        /// <param name="sender">The sender that sent the event argument</param>
        /// <param name="e">The event argument</param>
        private void buttonEquals_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(resultBox.Text))
            {
                try
                {
                    FunctionEval function = new FunctionEval();

                    double result_number = function.Evaluate(result);
                    result         = result_number.ToString();
                    resultBox.Text = result;
                }
                catch (Exception ex)
                {
                    resultBox.Text = "Error: " + ex;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Performs a function evaluation on the math string that has been built prior to this method call
        /// </summary>
        /// <param name="sender">The sender that sent the event argument</param>
        /// <param name="e">The event argument</param>
        private void resultBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == 13)
            {
                result = resultBox.Text;

                if (!string.IsNullOrEmpty(result))
                {
                    try
                    {
                        FunctionEval function = new FunctionEval();

                        double result_number = function.Evaluate(result);
                        resultBox.Text = result_number.ToString();
                    }
                    catch (Exception ex)
                    {
                        resultBox.Text = "Error: " + ex;
                    }
                }
            }
        }
Пример #4
0
        private void buttonEval_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(FunctionBox.Text))
            {
                labelResult.Text = "Function box is empty";
            }
            else if (string.IsNullOrEmpty(VarBox.Text))
            {
                labelResult.Text = "Variable box is empty";
            }
            else
            {
                try
                {
                    FunctionEval func = new FunctionEval();

                    labelResult.Text = "f(" + VarBox.Text + ") = " + func.Evaluate(FunctionBox.Text, Double.Parse(VarBox.Text));
                }
                catch (Exception ex)
                {
                    labelResult.Text = ex.ToString();
                }
            }
        }