Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using MathNet.Numerics.LinearAlgebra;
- using System.Windows.Forms.DataVisualization.Charting;
- namespace SystemsOfLinearEquations
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- void Button1_Click(object sender, EventArgs e)
- {
- Close();
- }
- public void ClearForm()
- {
- chart1.Series.Clear();
- richTextBox1.Clear();
- }
- double F(double x)
- {
- return Math.Log(x) / (Math.Sin(2.0 * x) + 1.5) - Math.Cos(x / 5.0);
- }
- double IF(double x, Vector<double> A)
- {
- double temp = 0;
- double differences = 1;
- double differences1 = x;
- double result = differences * A[0] + differences1 * A[1];
- for (int row = 2; row < A.Count; row++)
- {
- temp = 2 * x * differences1 - differences;
- result += temp * A[row];
- differences = differences1;
- differences1 = temp;
- }
- return result;
- }
- void Chebyshev(double[] xValues)
- {
- Vector<double> X = Vector<double>.Build.DenseOfArray(xValues);
- Vector<double> A = Vector<double>.Build.Dense(X.Count);
- Vector<double> Y = Vector<double>.Build.Dense(X.Count);
- Matrix<double> N = Matrix<double>.Build.Dense(X.Count, X.Count, 0);
- for (int row = 0; row < X.Count; row++)
- {
- // Y reikšmės apskaičiavimas
- Y[row] = F(X[row]);
- // N matricos eilutės apskaičiavimas
- N[row, 0] = 1;
- N[row, 1] = X[row];
- for (int column = 2; column < X.Count; column++)
- {
- N[row, column] = 2 * X[row] * N[row, column - 1] - N[row, column - 2];
- }
- }
- // A reikšmės apskaičiavimas
- // A = N.Inverse() * Y;
- Matrix<double> Nn = N.Inverse();
- for (int row = 0; row < X.Count; row++)
- {
- for (int column = 0; column < X.Count; column++) {
- A[row] += Nn[row, column] * Y[column];
- }
- }
- Series Original = chart1.Series.Add("Original");
- Series Interpolated = chart1.Series.Add("Interpolated");
- Series Difference = chart1.Series.Add("Difference");
- Series Points = chart1.Series.Add("Points");
- Original.ChartType = SeriesChartType.Line;
- Interpolated.ChartType = SeriesChartType.Line;
- Difference.ChartType = SeriesChartType.Line;
- Points.ChartType = SeriesChartType.Point;
- Original.BorderWidth = 3;
- Interpolated.BorderWidth = 3;
- Difference.BorderWidth = 3;
- for (int i = 0; i < X.Count; i++)
- {
- Points.Points.AddXY(X[i], F(X[i]));
- }
- for (double x = 2; x <= 10; x += 0.1)
- {
- double originalY = F(x);
- double interpolatedY = IF(x, A);
- double differenceY = originalY - interpolatedY;
- Original.Points.AddXY(x, originalY);
- Interpolated.Points.AddXY(x, interpolatedY);
- Difference.Points.AddXY(x, differenceY);
- }
- }
- void Button2_Click(object sender, EventArgs e)
- {
- ClearForm();
- Chebyshev(new double[] { 2, 3, 4, 5, 6, 7, 8, 9, 10 });
- }
- void Button3_Click(object sender, EventArgs e)
- {
- ClearForm();
- double a = 2;
- double b = 10;
- int n = 10;
- double[] xValues = new double[n]; // Mazgai ties Čiobyševo abscisėmis
- for (int i = 0; i < n; i++){
- xValues[i] = (b - a) / 2 * Math.Cos(Math.PI * (2 * i + 1) / (2 * n)) + (b + a) / 2;
- }
- Chebyshev(xValues.ToArray());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement