コード例 #1
0
ファイル: Form1.cs プロジェクト: Radmir2015/polycourse
        private void button9_Click(object sender, EventArgs e)
        {
            Polynom temp   = radioButton1.Checked ? p : radioButton2.Checked ? f : result;
            string  answer = "f" + label7.Text + " " + temp.GetRepresentation() + "\n";

            try
            {
                List <string> letters = prepareLetters();
                List <double> nums    = textBox7.Text.Split(' ').Select(StringToDouble).ToList();

                if (letters.Count() > nums.Count())
                {
                    return;
                }

                answer += "f(" + string.Join(", ", nums) + ") = " + letters.Aggregate(temp.GetRepresentation(), (x, y) =>
                                                                                      x.Replace(y, "(" + nums[letters.IndexOf(y)].ToString() + ")")) + " = ";

                answer += temp.GetNodes().Select(x =>
                                                 x.GetK() * x.GetCopiedDict().Select(kv =>
                                                                                     kv.Key == ""
                            ? 1
                            : Math.Pow(nums[letters.IndexOf(kv.Key)], kv.Value)).Sum()).Sum().ToString();

                MessageBox.Show(answer, "Значение функции в точке");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ввод аргументов функции");
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Radmir2015/polycourse
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }
                string text = System.IO.File.ReadAllText(openFileDialog1.FileName);

                string[] split = Regex.Split(text, @"\s+");

                Polynom temp;

                if (new Regex("[a-zA-Z]").Match(text).Length > 0)
                {
                    temp = new Polynom(string.Join(" ", split));
                }
                else
                {
                    temp = new Polynom(Enumerable.Range(0, split.Skip(1).Count()).Select(i =>
                                                                                         new Node(StringToDouble(split.ElementAt(i + 1)),
                                                                                                  (StringToInt(split.ElementAt(0)) - i == 0)
                                    ? 1
                                    : StringToInt(split.ElementAt(0)) - i,
                                                                                                  (StringToInt(split.ElementAt(0)) - i == 0)
                                    ? ""
                                    : "x")).ToList());
                }

                if (radioButton1.Checked)
                {
                    p = new Polynom(temp.GetNodes());

                    textBox3.Text = p.GetRepresentation();
                }

                if (radioButton2.Checked)
                {
                    f = new Polynom(temp.GetNodes());

                    textBox4.Text = f.GetRepresentation();
                }

                if (radioButton3.Checked)
                {
                    p = new Polynom(temp.GetNodes());
                    f = new Polynom(temp.GetNodes());

                    textBox3.Text = p.GetRepresentation();
                    textBox4.Text = f.GetRepresentation();
                }

                prepareLetters();
            }
            catch (Exception exep)
            {
                MessageBox.Show(exep.Message, "Открытие файла");
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: Radmir2015/polycourse
        private void button5_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                p.Clear();
                p             = new Polynom(textBox3.Text);
                textBox3.Text = p.GetRepresentation();
            }

            if (radioButton2.Checked)
            {
                f.Clear();
                f             = new Polynom(textBox4.Text);
                textBox4.Text = f.GetRepresentation();
            }

            if (radioButton3.Checked)
            {
                p.Clear();
                f.Clear();
                p             = new Polynom(textBox3.Text);
                f             = new Polynom(textBox4.Text);
                textBox3.Text = p.GetRepresentation();
                textBox4.Text = f.GetRepresentation();
            }

            prepareLetters();
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: Radmir2015/polycourse
 private void button4_Click(object sender, EventArgs e)
 {
     result.Clear();
     result = p * f;
     prepareLetters();
     textBox5.Text = result.GetRepresentation();
     textBox6.Text = "* (бинарный)";
     lastOperation = "*";
 }
コード例 #5
0
ファイル: Form1.cs プロジェクト: Radmir2015/polycourse
 private void button3_Click(object sender, EventArgs e)
 {
     result.Clear();
     if (radioButton1.Checked)
     {
         isUnary       = true;
         unaryPolynom  = 1;
         result        = new Polynom(new Node(1, 0, "")) * p;
         textBox6.Text = "+ (унарный)";
     }
     if (radioButton2.Checked)
     {
         isUnary       = true;
         unaryPolynom  = 2;
         result        = new Polynom(new Node(1, 0, "")) * f;
         textBox6.Text = "+ (унарный)";
     }
     if (radioButton3.Checked)
     {
         isUnary       = false;
         unaryPolynom  = 0;
         result        = p + f;
         textBox6.Text = "+ (бинарный)";
     }
     lastOperation = "+";
     prepareLetters();
     textBox5.Text = result.GetRepresentation();
 }
コード例 #6
0
ファイル: Form1.cs プロジェクト: Radmir2015/polycourse
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                double k     = StringToDouble(textBox1.Text);
                int    power = StringToInt(textBox2.Text);

                var temp = (power == 0)
                ? new Node(k, 0, "")
                : new Node(k, power);

                if (radioButton1.Checked)
                {
                    p.Add(temp);
                    textBox3.Text = p.GetRepresentation();
                }

                if (radioButton2.Checked)
                {
                    f.Add(temp);
                    textBox4.Text = f.GetRepresentation();
                }

                if (radioButton3.Checked)
                {
                    p.Add(temp);
                    f.Add(temp);
                    textBox3.Text = p.GetRepresentation();
                    textBox4.Text = f.GetRepresentation();
                }

                prepareLetters();
            }
            catch (Exception exep)
            {
                MessageBox.Show(exep.Message, "Добавление узла");
            }
        }