Ejemplo n.º 1
0
 private void Fourier_MouseDown(object sender, MouseButtonEventArgs e)
 {
     if (e.ChangedButton == MouseButton.Right)
     {
         if (ffff != null)
         {
             var ns = new Ns(ffff);
             var p  = new PopUp()
             {
                 Height                = 425,
                 Width                 = 805,
                 WindowStyle           = WindowStyle.SingleBorderWindow,
                 Title                 = "Fouriers",
                 Owner                 = this,
                 WindowStartupLocation = WindowStartupLocation.CenterOwner,
                 AllowsTransparency    = false
             };
             ns.VerticalAlignment   = VerticalAlignment.Center;
             ns.HorizontalAlignment = HorizontalAlignment.Center;
             p.Content = ns;
             p.ShowDialog();
         }
     }
 }
Ejemplo n.º 2
0
        private void NewFunction_Click(object sender, RoutedEventArgs e)
        {
            var gg = new Grid()
            {
                Background          = Brushes.SkyBlue,
                Width               = 300,
                Height              = 200,
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
            };

            gg.Children.Add(new TextBlock
            {
                Text = "please wait",
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center
            });
            Grid.SetRow(gg, 1);
            MainGrid.Children.Add(gg);
            anbn.Children.Clear();
            var f = new NewFunction();
            var p =
                new PopUp()
            {
                Content = f,
                Owner   = this
            };

            p.Width  = 730;
            p.Height = 340;
            p.ShowDialog();
            if (UI.NewFunction.Piese == false)
            {
                if (UI.NewFunction.Type == FunctionType.normal)
                {
                    var sf = new SimpleFourier(UI.NewFunction.Func, UI.NewFunction.Period, 40);
                    ffff = sf;
                    Fourier.Draw(sf.FourierSeries(30), -10, 10, 0.01);
                    anbn.Children.Add(new TextBlock
                    {
                        Text = "a0: " + sf.a0.ToString(),
                        VerticalAlignment = VerticalAlignment.Stretch,
                        TextAlignment     = TextAlignment.Center
                    });
                    for (int i = 0; i < sf.an.Length; i++)
                    {
                        anbn.Children.Add(new TextBlock
                        {
                            Text = "a" + (i + 1).ToString() + ": " + sf.an[i].ToString() +
                                   "    b" + (i + 1).ToString() + ": " + sf.bn[i].ToString(),
                            VerticalAlignment = VerticalAlignment.Stretch,
                            TextAlignment     = TextAlignment.Center
                        });
                    }
                    Dynamics.GetValues(sf.Function, -sf.Period, sf.Period, 0.001, out KeyValuePair <double, double>[] values);
                    Function.Draw(values);
                }
                else
                {
                    var sf = new OddEvenFourier(UI.NewFunction.Func, UI.NewFunction.Period, 40, UI.NewFunction.Type);
                    ffff = sf;
                    Fourier.Draw(sf.FourierSeries(30), -10, 10, 0.01);
                    anbn.Children.Add(new TextBlock
                    {
                        Text = "a0: " + sf.a0.ToString(),
                        VerticalAlignment = VerticalAlignment.Stretch,
                        TextAlignment     = TextAlignment.Center
                    });
                    for (int i = 0; i < sf.an.Length; i++)
                    {
                        anbn.Children.Add(new TextBlock
                        {
                            Text = "a" + (i + 1).ToString() + ": " + sf.an[i].ToString() +
                                   "    b" + (i + 1).ToString() + ": " + sf.bn[i].ToString(),
                            VerticalAlignment = VerticalAlignment.Stretch,
                            TextAlignment     = TextAlignment.Left
                        });
                    }
                    Dynamics.GetValues(sf.Function, 0, sf.Period, 0.001, out KeyValuePair <double, double>[] values);
                    var othvals = new List <KeyValuePair <double, double> >();
                    if (UI.NewFunction.Type == FunctionType.even)
                    {
                        foreach (var item in values)
                        {
                            //othvals.Add(new KeyValuePair<double, double>(item.Key, item.Value));
                            othvals.Add(new KeyValuePair <double, double>(-item.Key, item.Value));
                        }
                    }
                    else if (UI.NewFunction.Type == FunctionType.odd)
                    {
                        foreach (var item in values)
                        {
                            //othvals.Add(new KeyValuePair<double, double>(item.Key, item.Value));
                            othvals.Add(new KeyValuePair <double, double>(-item.Key, -item.Value));
                        }
                    }
                    foreach (var item in values)
                    {
                        othvals.Add(new KeyValuePair <double, double>(item.Key, item.Value));
                    }
                    Function.Draw(othvals.ToArray());
                }
            }
            else
            {
                var sf = new PiecewiseFourier(40);
                for (int i = 0; i < UI.NewFunction.Pieses.Count; i++)
                {
                    sf.AddCriterion(UI.NewFunction.Pieses[i], UI.NewFunction.Froms[i], UI.NewFunction.Tos[i]);
                }
                sf.Criterioned();
                ffff = sf;
                var vs = new List <KeyValuePair <double, double> >();
                foreach (var item in sf.Values)
                {
                    vs.Add(new KeyValuePair <double, double>(item.Key, item.Value));
                }
                Function.Draw(vs.ToArray());
                Fourier.Draw(sf.FourierSeries(30), -10, 10, 0.01);
                anbn.Children.Add(new TextBlock
                {
                    Text = "a0: " + sf.a0.ToString(),
                    VerticalAlignment = VerticalAlignment.Stretch,
                    TextAlignment     = TextAlignment.Left
                });
                for (int i = 0; i < sf.an.Length; i++)
                {
                    anbn.Children.Add(new TextBlock
                    {
                        Text = "a" + (i + 1).ToString() + ": " + sf.an[i].ToString() +
                               "    b" + (i + 1).ToString() + ": " + sf.bn[i].ToString(),
                        VerticalAlignment = VerticalAlignment.Stretch,
                        TextAlignment     = TextAlignment.Left
                    });
                }
            }
            MainGrid.Children.Remove(gg);
        }