public static Polynomial Newtonsecond(double [] Y, double h, int n, double x0) { Double[] DalthY = new double[3]; Double[] Dalth2Y = new double[2]; double Dalth3Y = 0; for (int i = 0; i < 3; i++) { DalthY[i] = Y[i + 1] - Y[i]; } for (int i = 0; i < 2; i++) { Dalth2Y[i] = DalthY[i + 1] - DalthY[i]; } Dalth3Y = Dalth2Y[1] - Dalth2Y[0]; Polynomial p = new Polynomial(); Polynomial temp = new Polynomial(); Polynomial temp1 = new Polynomial(); Polynomial temp2 = new Polynomial(); temp = Polynomial.insert(Dalth2Y[0], 0, temp); p = Polynomial.insert(1 / h, 1, p); p = Polynomial.insert(-1 * (x0 / h), 0, p); temp1 = Polynomial.insert(Dalth3Y, 0, temp1); temp1 = Polynomial.multi(temp1, p); temp1 = Polynomial.insert(-1 * Dalth3Y, 0, temp1); temp1 = Polynomial.add(temp1, temp); h = h * h; temp2 = Polynomial.insert((1 / h), 0, temp2); temp1 = Polynomial.multi(temp1, temp2); return(temp1); }
public static Polynomial newtonemethod(double[] x, double[] y, double[,] tab, int n) { Polynomial temp = new Polynomial(); Polynomial temp1 = new Polynomial(); Polynomial temp2 = new Polynomial(); Polynomial temp3 = new Polynomial(); temp = Polynomial.insert(y[0], .0, temp); for (int i = 1; i < n; i++) { temp1 = new Polynomial(); temp1 = Polynomial.insert(1.0, .0, temp1); temp3 = new Polynomial(); temp3 = Polynomial.insert(tab[0, i], .0, temp3); for (int j = 0; j < i; j++) { temp2 = new Polynomial(); temp2 = Polynomial.insert(1.0, 1.0, temp2); temp2 = Polynomial.insert(-1.0 * x[j], .0, temp2); temp1 = Polynomial.multi(temp2, temp1); } temp3 = Polynomial.multi(temp1, temp3); temp = Polynomial.add(temp, temp3); } return(temp); }
public static string lagrang(double[] x, int node, double[] y) { Polynomial temp = new Polynomial(); Polynomial onepoly = new Polynomial(); bool loop = false; for (int i = 0; i < node; i++) { for (int j = 0; j < node; j++) { loop = false; if (i != j) { loop = true; temp = new Polynomial(); double amthallagrang = x[i] - x[j]; temp = Polynomial.insert(y[i] * amthallagrang, 1, temp); temp = Polynomial.insert(y[i] * amthallagrang * -x[j], 0, temp); } if (loop) { onepoly = Polynomial.add(temp, onepoly); } } } return(Polynomial.tostring(onepoly)); }
public static Polynomial Newton(double [] Y, double h, int n, double x0) { Double[] DalthY = new double[3]; Double[] Dalth2Y = new double[2]; double Dalth3Y = 0; for (int i = 0; i < 3; i++) { DalthY[i] = Y[i + 1] - Y[i]; } for (int i = 0; i < 2; i++) { Dalth2Y[i] = DalthY[i + 1] - DalthY[i]; } Dalth3Y = Dalth2Y[1] - Dalth2Y[0]; Polynomial first = new Polynomial(); Polynomial second = new Polynomial(); Polynomial third = new Polynomial(); Polynomial p = new Polynomial(); Polynomial p2 = new Polynomial(); Polynomial temp = new Polynomial(); Polynomial temp1 = new Polynomial(); Polynomial temp2 = new Polynomial(); p = Polynomial.insert(1 / h, 1, p); p = Polynomial.insert(-1 * (x0 / h), 0, p); p2 = Polynomial.multi(p, p); second = Polynomial.insert((2 * Dalth2Y[0]) / 2, 0, second); second = Polynomial.multi(second, p); second = Polynomial.insert(-1 * (Dalth2Y[0] / h), 0, second); first = Polynomial.insert(DalthY[0], 0, first); third = Polynomial.insert((3 * Dalth3Y) / 6, 0, third); third = Polynomial.multi(p2, third); temp = Polynomial.insert(-1 * (Dalth3Y), 0, temp); temp = Polynomial.multi(temp, p); third = Polynomial.add(third, temp); temp1 = Polynomial.insert((2 * Dalth3Y) / 6, 0, temp1); third = Polynomial.add(third, temp1); third = Polynomial.add(third, first); third = Polynomial.add(third, second); temp2 = Polynomial.insert((1 / h), 0, temp2); third = Polynomial.multi(third, temp2); return(third); }
public static Polynomial Splin(double [] x, double [] y, int node, double point) { Polynomial temp = new Polynomial(); int c = 0; for (int i = 0; i < node - 1; i++) { if ((x[i] <= point) && (x[i + 1] >= point)) { c = i; break; } } double constant = (y[c + 1] - y[c]) / (x[c + 1] - x[c]); temp = Polynomial.insert(constant, 1, temp); temp = Polynomial.insert(-1 * constant * x[c], 0, temp); temp = Polynomial.insert(y[c], 0, temp); return(temp); }
private void Send_Click(object sender, EventArgs e) { bool XarrayZero = false; bool YarrayZero = false; string Method = comboBox1.Text; string[] allMethod = { "General Methode", "Spline", "Lagrange", "Newton", "Least Square Method" }; if (Method != ".......") { xcolum = CreatXarray(ref ThereIsErrorX); XarrayZero = Share.IfallZero(xcolum); if (XarrayZero != true) { ycolum = CreatYarray(ref ThereIsErrorY); } YarrayZero = Share.IfallZero(ycolum); string AnyOfMethod = Array.Find(allMethod, s => s.Equals(Method)); if ((XarrayZero != true) && (YarrayZero != true) && (ThereIsErrorX != true) && (ThereIsErrorY != true)) { if ((Method == AnyOfMethod)) { comboBox1.Enabled = false; } else { MessageBox.Show("This Is Not Method", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } XarrayZero = Share.IfallZero(xcolum); YarrayZero = Share.IfallZero(ycolum); switch (Method) { case "General Methode": { if ((XarrayZero != true) && (YarrayZero != true) && (ThereIsErrorX != true) && (ThereIsErrorY != true)) { #region General Methode double[,] matrx; matrx = new double[NumOfNode, NumOfNode]; matrx = InterpolationClass.CreatVandrmondmatrix(NumOfNode, xcolum); double determatrx = InterpolationClass.determine(matrx); double[,] another = new double[NumOfNode, NumOfNode]; Polynomial temp = new Polynomial(); double[] Constant; Constant = new double[NumOfNode]; for (int j = 0; j < NumOfNode; j++) { another = InterpolationClass.creatanothermatrix(j, xcolum, ycolum, NumOfNode); double deternother = InterpolationClass.determine(another); Constant[j] = deternother / determatrx; } for (int i = 0; i < Constant.Length; i++) { temp = Polynomial.insert(Constant[i], i, temp); } string result = Polynomial.tostring(temp); if (MessageBox.Show("If You Have An Internet Connection Click Yes To Show The Function On Net Or Click No To See It Here", "Internet Connection", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string url = "http://texify.com/?" + result; Process.Start(url); } else { label3.Visible = true; richTextBox1.Visible = true; richTextBox1.Text = result; } Send.Enabled = false; Refresh.Visible = true; #endregion } } break; case "Least Square Method": { if ((XarrayZero != true) && (YarrayZero != true) && (ThereIsErrorX != true) && (ThereIsErrorY != true)) { #region Least Square Method int exp = NumOfNode - 1; double sum; double[] tableX = new double[2 * exp]; double[] tableY = new double[NumOfNode]; for (int j = 0; j < (2 * exp); j++) { sum = 0; for (int i = 0; i < NumOfNode; i++) { sum = sum + Math.Pow(xcolum[i], j + 1); tableX[j] = sum; } } for (int j = 0; j < NumOfNode; j++) { sum = 0; for (int i = 0; i < NumOfNode; i++) { if (j == 0) { sum = sum + ycolum[i]; } else { sum = sum + (Math.Pow(xcolum[i], j) * ycolum[i]); } tableY[j] = sum; } } double[,] squer = new double[NumOfNode, NumOfNode]; squer[0, 0] = NumOfNode; for (int i = 1; i < NumOfNode; i++) { squer[0, i] = tableX[i - 1]; } for (int i = 1; i < NumOfNode; i++) { for (int j = 0; j < NumOfNode; j++) { squer[i, j] = tableX[i + j - 1]; } } double[] A = new double[NumOfNode]; double d = InterpolationClass.determine((double[, ])squer.Clone()); for (int j = 0; j < NumOfNode; j++) { A[j] = InterpolationClass.ChangeXY((double[, ])squer.Clone(), tableY, j, NumOfNode) / d; } Send.Enabled = false; Refresh.Visible = true; #endregion } } break; case "Lagrange": { if ((XarrayZero != true) && (YarrayZero != true) && (ThereIsErrorX != true) && (ThereIsErrorY != true)) { #region Lagrange { string result = InterpolationClass.lagrang(xcolum, NumOfNode, ycolum); if (MessageBox.Show("If You Have An Internet Connection Click Yes To Show The Function On Net Or Click No To See It Here", "Internet Connection", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string url = "http://texify.com/?" + result; Process.Start(url); } else { label3.Visible = true; richTextBox1.Visible = true; richTextBox1.Text = result; } } #endregion } } break; case "Spline": { if ((XarrayZero != true) && (YarrayZero != true) && (ThereIsErrorX != true) && (ThereIsErrorY != true)) { #region Splin { double point = 0; if ((textBox2.Text != null) && (Share.Isnumber(textBox2.Text))) { point = double.Parse(textBox2.Text); string result = Polynomial.tostring(InterpolationClass.Splin(xcolum, ycolum, NumOfNode, point)); if (MessageBox.Show("If You Have An Internet Connection Click Yes To Show The Function On Net Or Click No To See It Here", "Internet Connection", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string url = "http://texify.com/?" + result; Process.Start(url); } else { label3.Visible = true; richTextBox1.Visible = true; richTextBox1.Text = result; } } else { MessageBox.Show("Error Entry", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } #endregion } } break; case "Newton": { if ((XarrayZero != true) && (YarrayZero != true) && (ThereIsErrorX != true) && (ThereIsErrorY != true)) { #region Newton double[,] Temp = InterpolationClass.newtonftab(xcolum, ycolum, NumOfNode); Polynomial Newton = InterpolationClass.newtonemethod(xcolum, ycolum, Temp, NumOfNode); string result = Polynomial.tostring(Newton); if (MessageBox.Show("If You Have An Internet Connection Click Yes To Show The Function On Net Or Click No To See It Here", "Internet Connection", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string url = "http://texify.com/?" + result; Process.Start(url); } else { label3.Visible = true; richTextBox1.Visible = true; richTextBox1.Text = result; } #endregion } } break; default: { if (Method == ".......") { MessageBox.Show("No Method Is Selceted ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } break; } }