static void Main(string[] args) { string fileName = "data.txt"; List <string> strings = File.ReadAllLines(fileName).ToList(); List <double> x_s = strings .First() .Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => double.Parse(x)) .ToList(); List <double> y_s = strings .Last() .Split(new char[] { '\t' }, StringSplitOptions.RemoveEmptyEntries) .Select(x => double.Parse(x)) .ToList(); Console.WriteLine(x_s.First()); Console.WriteLine(x_s.Last()); Langrange langrange = new Langrange(x_s, y_s); double minValue = x_s.First(); double maxValue = x_s.Last(); int numberOfPoints = 300; double step = (Math.Abs(minValue) + Math.Abs(maxValue)) / numberOfPoints; List <double> pol_x = new List <double>(); for (int i = 0; i <= numberOfPoints; ++i) { pol_x.Add(Math.Round(minValue + step * i, preciosion)); } Show(pol_x); }
public void Langrange(IEnumerable <double> x_s, IEnumerable <double> y_s) { PlotView plotView = new PlotView(); plotView.Dock = DockStyle.Fill; if (panel1_1.Controls.Count != 0) { panel1_1.Controls.RemoveAt(0); } panel1_1.Controls.Add(plotView); LinearAxis XAxis = new LinearAxis() { Position = AxisPosition.Bottom, Minimum = x_s.First(), Maximum = x_s.Last() }; PlotModel plotModel = new PlotModel(); plotView.Model = plotModel; Langrange langrange = new Langrange(x_s, y_s); List <double> plot_x = new List <double>(); double step = (Math.Abs(x_s.First()) + Math.Abs(x_s.Last())) / N; for (int i = 0; i <= N; ++i) { plot_x.Add(x_s.First() + step * i); } List <double> plot_y = new List <double>(); foreach (var x in plot_x) { plot_y.Add(langrange.GetLangrangePolynominal(x)); } FunctionSeries functionSeries = new FunctionSeries(); Series series = new LineSeries(); for (int i = 0; i < plot_x.Count; ++i) { DataPoint dataPoint = new DataPoint(plot_x[i], plot_y[i]); functionSeries.Points.Add(dataPoint); } plotView.Model.Series.Add(functionSeries); if (_plotModels.ContainsKey("Langrange")) { _plotModels.Remove("Langrange"); } _plotModels.Add("Langrange", plotModel); }