public void Spline4_Experiment() { //setup int N = 32; int n = 16; double a = 0d; double b = 1d; int index = 0; Vector grid_h = Vector.CreateUniformGrid(N, a, b); Vector grid_2h = Vector.CreateUniformGrid(n, a, b); BasisSpline spline_h = new BasisSpline(4, N, a, b); BasisSpline spline_2h = spline_h.GetBasisSpline_Down(); Matrix A = spline_h.GetMatrix(); Vector z; Vector c; //run for (index = 0; index < n; index++) { z = spline_2h.GetVectorBasis(grid_h, index); c = Solver.BCGSTAB(A, z, 0.0000000001d); Console.WriteLine(index + ") " + c.ToString()); } //Console.WriteLine(A.ToString()); Console.WriteLine("index = " + index); }
public void Interpolate_slow_deg2_tsin() { //setup double EPS = 0.1d; double a = 0d; double b = 3d; int GridSize = 20; int deg = 2; Vector grid = Vector.CreateUniformGrid(GridSize, a, b); Vector y = MyMath.Basic.GetVectorFunction(GridSize, a, b, FunctionLib.tsin); //run BasisSpline bspline = new BasisSpline(deg, grid, y, GridType.ClassicSplineGrid); //compare int N = 150; Vector expect = MyMath.Basic.GetVectorFunction(N, a, b, FunctionLib.tsin); Vector actual = bspline.GetVectorFunction(N, a, b); double result = (expect - actual).Norm; Console.WriteLine("Степень сплайна = " + deg); Console.WriteLine("Сетка по которой построен сплайн = " + bspline.grid.ToString()); Console.WriteLine("значения х = " + grid.ToString()); Console.WriteLine("значение f(x) = " + y.ToString()); Console.WriteLine("coef = " + bspline.COEFICIENT.ToString()); Console.WriteLine("||f - spline|| = " + result.ToString("0.0000")); Assert.AreEqual(0, result, EPS, "Плохая интерполяция!"); }
public void Spline4_ExperimentUniformGrid() { //setup int N = 17; int n = 9; double a = 0d; double b = 1d; int index = 0; Vector grid_h = Vector.CreateUniformGrid(N, a, b); Vector grid_2h = Vector.CreateUniformGrid(n, a, b); BasisSpline spline_h = new BasisSpline(4, grid_h, Vector.GetConstVector(2d, N), GridType.ExperimentSplineGrid); BasisSpline spline_2h = new BasisSpline(4, grid_2h, Vector.GetConstVector(2d, n), GridType.UniformSplineGrid); Matrix A = spline_h.GetMatrix(); Vector z; Vector c; //run for (index = 0; index < 7; index++) { z = spline_2h.GetVectorBasis(grid_h, index); c = Solver.BCGSTAB(A, z, 0.0000000001d); Console.WriteLine(index + ") " + c.ToString()); } //Console.WriteLine(A.ToString()); Console.WriteLine("index = " + index); }
public void FindMatrixTest() { //setup int N = 17; int n = 10; double a = 0d; double b = 1d; Vector grid_h = Vector.CreateUniformGrid(N, a, b); Vector grid_2h = Vector.CreateUniformGrid(n, a, b); BasisSpline spline_h = new BasisSpline(4, N, a, b); BasisSpline spline_2h = spline_h.GetBasisSpline_Down(); Matrix B = spline_2h.GetMatrix(); Matrix BR = new Matrix(n, n); for (int i = 1; i < n - 1; i++) { Vector c = Solver.BCG(B, Vector.GetEn(i, n), 0.00000000001d); for (int j = 0; j < n; j++) { BR[j, i] = c[j]; } } BR[0, 0] = 1; BR[n - 1, n - 1] = 1; Console.WriteLine(B); Console.WriteLine(BR); Console.WriteLine(BR * B); Assert.AreEqual(0, 1); }
public void Spline4_Experiment4() { //setup int N = 17; int n = 10; double a = 0d; double b = 1d; int index = 0; Vector grid_h = Vector.CreateUniformGrid(N, a, b); Vector grid_2h = Vector.CreateUniformGrid(n, a, b); BasisSpline spline_h = new BasisSpline(4, grid_h, Vector.GetConstVector(2d, N), GridType.ClassicSplineGrid); BasisSpline spline_2h = new BasisSpline(4, grid_2h, Vector.GetConstVector(2d, n), GridType.ClassicSplineGrid); Matrix A = spline_h.GetMatrix(); Matrix B = new Matrix(N, n); Vector z; Vector c; //run for (index = 0; index < n; index++) { z = spline_2h.GetVectorBasis(grid_h, index); c = Solver.BCGSTAB(A, z, 0.0000000001d); for (int i = 0; i < N; i++) { B[i, index] = c[i]; } } Console.WriteLine(Matrix.Transpose(B).ToString("0.00")); Console.WriteLine("index = " + index); }
public void create_proection_spline4_mat_test() { //setup //setup int N = 17; int n = 10; double a = 0d; double b = 1d; int index = 0; Vector grid_h = Vector.CreateUniformGrid(N, a, b); Vector grid_2h = Vector.CreateUniformGrid(n, a, b); BasisSpline spline_h = new BasisSpline(4, grid_h, Vector.GetConstVector(2d, N), GridType.ClassicSplineGrid); BasisSpline spline_2h = new BasisSpline(4, grid_2h, Vector.GetConstVector(2d, n), GridType.ClassicSplineGrid); Matrix A = spline_h.GetMatrix(); Matrix B = new Matrix(n, N); Vector z; Vector c; //run for (index = 0; index < n; index++) { z = spline_2h.GetVectorBasis(grid_h, index); c = Solver.BCGSTAB(A, z, 0.0000000001d); for (int i = 0; i < N; i++) { B[index, i] = c[i]; } } //run Matrix CREATE_B = MultyGrid.Proektor.create_proection_spline4_mat(n); Matrix D = B - CREATE_B; double actual = D.NORMF; Console.WriteLine("полученная " + B.ToString()); Console.WriteLine("созданная " + CREATE_B.ToString()); //compare Assert.AreEqual(0d, actual, 0.00000001d, "Эти матрицы не равны!"); }
public void FindProectorMatrixNew_Test() { //setup int N = 17; int n = 10; double a = 0d; double b = 1d; Vector grid_h = Vector.CreateUniformGrid(N, a, b); Vector grid_2h = Vector.CreateUniformGrid(n, a, b); BasisSpline spline_h = new BasisSpline(4, N, a, b); BasisSpline spline_2h = spline_h.GetBasisSpline_Down(); Matrix B = spline_h.GetMatrix(); Matrix BR = new Matrix(N, N); for (int i = 1; i < N - 1; i++) { Vector c = Solver.BCG(B, Vector.GetEn(i, N), 0.00000000001d); for (int j = 0; j < N; j++) { BR[j, i] = c[j]; } } BR[0, 0] = 1; BR[N - 1, N - 1] = 1; Matrix B_2h = new Matrix(N, n); for (int i = 0; i < n; i++) { Vector z = spline_2h.GetVectorBasis(grid_h, i); for (int j = 0; j < N; j++) { B_2h[j, i] = z[j]; } } Console.WriteLine(B_2h); Console.WriteLine(BR * B_2h); Assert.AreEqual(0, 1); }
public void RightUniformBSplineTest() { //setup int GridSize = 5; double a = 0; double b = 5d; int N = 1000; double h = MyMath.Basic.GetStep(GridSize, a, b); int deg = 4; int index = 0; //Vector x = new Vector(MyMath.Basic.CreateUniformGrid(N, a - 2 * h, b + deg * h)); BasisSpline spline = new BasisSpline(deg, GridSize, a, b, GridType.RightUniformSplineGrid); //run double Ba = spline.GetBasis(0.1d, index); //compare Assert.AreEqual(0d, Ba, 0.000001d); }
public void Interpolate_slow_deg4_tsin_ZeroTrace_NewMethod() { //setup double EPS = 0.1d; double a = 0d; double b = Math.PI; int GridSize = 14; int deg = 4; int p = deg - 1; Vector uni_grid = Vector.CreateUniformGrid(GridSize, a, b); Vector f = MyMath.Basic.GetVectorFunction(GridSize, a, b, FunctionLib.tttsin); //run BasisSpline bspline = new BasisSpline(deg, uni_grid, f, GridType.SimpleSplineGrid); Vector c = BasisSpline.SimpleInterpolate(f, bspline.grid, deg); Vector basis_c = new Vector(c.Length + 2 * (deg - 1)); for (int i = 0; i < c.Length; i++) { basis_c[i + p] = c[i]; } bspline.SetNewCoefs(basis_c); Vector bf = bspline.GetVectorFunction(uni_grid); ////compare int N = 150; Vector expect = MyMath.Basic.GetVectorFunction(N, a, b, FunctionLib.tttsin); Vector actual = bspline.GetVectorFunction(N, a, b); double result = (expect - actual).Norm; Console.WriteLine("Степень сплайна = " + deg); Console.WriteLine("Сетка по которой построен сплайн = " + uni_grid.ToString()); Console.WriteLine("trace( f ) = <" + f[0].ToString("0.000") + ", " + f.Last.ToString("0.000") + ">"); Console.WriteLine("coef = " + basis_c); //bspline.COEFICIENT.ToString()); Console.WriteLine("значение f(x) = " + f.ToString()); Console.WriteLine("значение bf(x) = " + bf.ToString()); Console.WriteLine("||f - spline|| = " + result.ToString("0.0000")); Assert.AreEqual(0, result, EPS, "Плохая интерполяция!"); }
public void SimpleUniformBSplineTest_dim() { //setup int GridSize = 2; double a = 0; double b = 7d; int deg = 4; int index = 0; BasisSpline spline = new BasisSpline(deg, GridSize, a, b, GridType.SimpleSplineGrid); Console.WriteLine(new Vector(MyMath.Basic.CreateUniformGrid(GridSize, a, b))); int expect = GridSize + 2 * (deg - 1) + 2 * (deg - 2); //run int actual = spline.grid.Count; //compare Console.WriteLine("expect = " + expect + "; actual = " + actual); Assert.AreEqual(expect, actual, "размерности совпадают"); }
public void CompareConvolutionWhithBasisSplineTest() { //setup int GridSize = 1000; double a = -3d; double b = 5d; Vector grid = Vector.CreateUniformGrid(GridSize, a, b); BasisSpline spline = new BasisSpline(3, 10, a, b); // Console.WriteLine("grid = " + spline.grid); Vector expect = spline.GetVectorBasis(grid, 3); Console.WriteLine("expect = " + expect); //run Vector actual = MyMath.Operations.GetConvolutionVector(FunctionLib.conv_tri_test, FunctionLib.conv_tri_test, GridSize, a, b); Console.WriteLine("actual = " + actual); //compare double NORM = (expect - actual).Norm; Console.WriteLine("Норма разности = " + NORM); Assert.AreEqual(0d, NORM, 0.1d); }
public void Interpolate_slow_deg4_tsin_CompareCoefs_test() { //setup double EPS = 0.1d; double a = 0d; double b = 3 * Math.PI; int GridSize = 17; int deg = 4; Vector grid = Vector.CreateUniformGrid(GridSize, a, b); Vector y = MyMath.Basic.GetVectorFunction(GridSize, a, b, FunctionLib.tsin); //run BasisSpline bspline_h = new BasisSpline(deg, GridSize, a, b); Vector c_h = BasisSpline.Interpolate(y, bspline_h.grid, deg); bspline_h.SetNewCoefs(c_h); Vector c_2h_actual = MultyGrid.Proektor.slow_spline_r(c_h); BasisSpline bspline_2h = bspline_h.GetBasisSpline_Down(); Vector y_2h = MyMath.Basic.GetVectorFunction(c_2h_actual.Length, a, b, FunctionLib.tsin); Vector c_2h_expect = BasisSpline.Interpolate(y_2h, bspline_2h.grid, deg); bspline_2h.SetNewCoefs(c_2h_actual); //compare Console.WriteLine((c_2h_expect - c_2h_actual).ToString()); double result = (c_2h_expect - c_2h_actual).Norm; Console.WriteLine("Степень сплайна = " + deg); Console.WriteLine("Сетка по которой построен сплайн = " + bspline_2h.grid.ToString()); Console.WriteLine("f(x) = " + y); Console.WriteLine("f(x) 2h = " + y_2h); Console.WriteLine("actual c 2h = " + c_2h_actual.ToString()); Console.WriteLine("expect c 2h = " + c_2h_expect.ToString()); Console.WriteLine("||f - spline|| = " + result.ToString("0.0000")); Assert.AreEqual(0, result, EPS, "Плохая интерполяция!"); }
public void DeBoorB_Integrate() { //setup int GridSize = 20; double a = 0; double b = 1d; double c = 10d; double EPS = 0.01d; int N = 1000; int index = 2; Vector grid1 = Vector.CreateUniformGrid(N, a, b); Vector grid2 = Vector.CreateUniformGrid(N, a, c); int deg = 4; BasisSpline spline1 = new BasisSpline(deg, GridSize, a, b); BasisSpline spline2 = new BasisSpline(deg, GridSize, a, c); //run for (index = 0; index < GridSize; index++) { Console.WriteLine("index = " + index); Vector f1 = spline1.GetVectorBasis(grid1, index); Vector f2 = spline2.GetVectorBasis(grid2, index); double I1 = MyMathLib.Integrate.RiemannSum(f1.ToArray, MyMathLib.MyMath.Basic.GetStep(N, a, b)); double I2 = MyMathLib.Integrate.RiemannSum(f2.ToArray, MyMathLib.MyMath.Basic.GetStep(N, a, c)); Console.WriteLine("Integral B" + index + " on [0, 1] = " + I1); Console.WriteLine("Integral B" + index + " on [0, 10] = " + I2); //comp Assert.IsTrue(I2 > I1, "Интеграл с функции большем носителем должен быть больше!"); } }
public void Interpolate_slow_deg4_tsin_PROJECTION_test() { //setup double EPS = 0.1d; double a = 0d; double b = 2 * Math.PI; int GridSize = 17; int deg = 4; Vector grid = Vector.CreateUniformGrid(GridSize, a, b); Vector y = MyMath.Basic.GetVectorFunction(GridSize, a, b, FunctionLib.tsin); //run BasisSpline bspline_h = new BasisSpline(deg, GridSize, a, b); Vector c_h = BasisSpline.Interpolate(y, bspline_h.grid, deg); bspline_h.SetNewCoefs(c_h); Vector c_2h = MultyGrid.Proektor.slow_spline_r(c_h); BasisSpline bspline_2h = bspline_h.GetBasisSpline_Down(); bspline_2h.SetNewCoefs(c_2h); //compare int N = 50; Vector expect = MyMath.Basic.GetVectorFunction(N, a, b, FunctionLib.tsin); Vector actual = bspline_2h.GetVectorFunction(N, a, b); Console.WriteLine((expect - actual).ToString()); double result = (expect - actual).Norm; Console.WriteLine("Степень сплайна = " + deg); Console.WriteLine("Сетка по которой построен сплайн = " + bspline_2h.grid.ToString()); Console.WriteLine("значения х = " + grid.ToString()); Console.WriteLine("значение f(x) = " + y.ToString()); Console.WriteLine("coef h = " + c_h.ToString()); Console.WriteLine("coef 2h = " + bspline_2h.COEFICIENT.ToString()); Console.WriteLine("||f - spline|| = " + result.ToString("0.0000")); Assert.AreEqual(0, result, EPS, "Плохая интерполяция!"); }
public void Spline4_Experiment5_CompareMatr() { //setup int N = 17; int n = 10; double a = 0d; double b = 1d; int index = 0; Vector grid_h = Vector.CreateUniformGrid(N, a, b); Vector grid_2h = Vector.CreateUniformGrid(n, a, b); BasisSpline spline_h = new BasisSpline(4, N, a, b); BasisSpline spline_2h = spline_h.GetBasisSpline_Down(); Matrix A = spline_h.GetMatrix(); Matrix B = new Matrix(N, n); Vector z; Vector c; //run for (index = 0; index < n; index++) { z = spline_2h.GetVectorBasis(grid_h, index); Vector zz = spline_2h.GetVectorBasis(grid_2h, index); c = Solver.BCGSTAB(A, z, 0.0000000001d); for (int i = 0; i < N; i++) { B[i, index] = c[i]; } Console.WriteLine((zz).ToString()); } Console.WriteLine(spline_2h.GetMatrix()); //Console.WriteLine((A*c).ToString()); Console.WriteLine("index = " + index); }