示例#1
0
        private void LoadTableFromXML()
        {
            OpenFileDialog openDlg = new OpenFileDialog();

            openDlg.Filter = "XML | *.xml";

            if (openDlg.ShowDialog() == true)
            {
                try
                {
                    Lp = LagrangePolynom.ReadFromXML(openDlg.FileName);
                }
                catch (InvalidOperationException)
                {
                    MessageBox.Show("Invalid XML file!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    return;
                }

                Gx            = new ExprTree.Expression(Lp.ToString(), "x");
                this.FileName = openDlg.FileName;

                //show the values in the point grid
                pointsDt.Clear();
                foreach (Point p in Lp.GetPointCollection())
                {
                    DataRow newRow = pointsDt.NewRow();
                    newRow["X"] = p.X;
                    newRow["Y"] = p.Y;
                    pointsDt.Rows.Add(newRow);
                }
                pointGrid.DataContext = pointsDt;
                pointGrid.UpdateLayout();
            }
        }
示例#2
0
        private Point[] GeneratePoints(double from, double to, int pointsCount)
        {
            ExprTree.Expression   expr = new ExprTree.Expression(lblFunc.Content.ToString(), "x");
            Func <double, double> f    = expr.CompileDynamicMethod();

            //generate points array
            Point[] pointsToXML = new Point[pointsCount];
            for (int i = 1; i <= pointsCount; i++)
            {
                //Chebyshev points
                double Xi = 0.5 * (from + to) + 0.5 * (to - from) * Math.Cos((2.0 * i - 1) / (2.0 * pointsToXML.Length) * Math.PI);

                pointsToXML[pointsCount - i] = new Point(Xi, f(Xi));
            }
            return(pointsToXML);
        }
示例#3
0
        private async void ButtonFindRoots_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (Lp == null)
                {
                    throw new NullReferenceException("Interpolation points were not loaded!");
                }

                //Fx = new ExprTree.Expression(txtFx.Text, "x"); //it is compiled after it's input in txtFx_LostKeybFocus
                //Gx = new ExprTree.Expression(Lp.ToString(), "x");
                ExprTree.Expression Zx = Fx - Gx; //solve for f(x)=(gx) => f(x)-g(x)=0

                CheckRootFindInterval();

                StartRootsCalc(this, EventArgs.Empty);
                this.roots = await Zx.FindRootsBruteAsync(this.rootFindInterval.Value.From, this.rootFindInterval.Value.To, 1e-5, this.eps);

                if (this.RootsCalculated != null)
                {
                    RootsCalculated(this, EventArgs.Empty);
                }
            }
            catch (NullReferenceException ex)
            {
                if (ex.Message == "Interpolation points were not loaded!")
                {
                    pointGrid.BorderBrush = new SolidColorBrush(Colors.Red);
                }
                else
                {
                    throw;
                }
            }
            catch (Exception ex)
            {
                txtFx.BorderBrush = new SolidColorBrush(Colors.Red);
                MessageBox.Show(ex.Message);
            }
        }
示例#4
0
        private void MenuConvertFuncToXML_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ExprTree.Expression expr = new ExprTree.Expression(txtFx.Text, "x");
            }
            catch (Exception)
            {
                MessageBox.Show("Input function is incorrect!");
                txtFx.BorderBrush = new SolidColorBrush(Colors.Red);
                txtFx.SelectAll();
                return;
            }
            txtFx.BorderBrush = new SolidColorBrush(Colors.Green);

            //converts F(x) to xml format
            FunctionConvertXMLWindow convertWnd = new FunctionConvertXMLWindow();

            convertWnd.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterOwner;
            convertWnd.Owner = this;
            convertWnd.Show();
        }