public void TestOrthogonalRotation() { StandardDistribution gaussian = new StandardDistribution(); for (int i = 0; i < 100; i++) { Vector v = Vector.Random(2, gaussian); Matrix rotation = Orthogonal.Rotation(v); Vector res = rotation * v; Assert.That(Matrix.Transpose(rotation) * rotation, NumericIs.AlmostEqualTo(Matrix.Identity(2, 2)), "orthogonal rotation matrix"); Assert.That(rotation.Norm2(), NumericIs.AlmostEqualTo((double)1), "rotation matrix norm"); Assert.That(Math.Abs(res[0]), NumericIs.AlmostEqualTo(v.Norm(), 1e-12), "res(1)"); Assert.That(res[1], NumericIs.AlmostEqualTo((double)0, 1e-12), "res(2)"); } }
public void TestOrthogonalRotationComplex() { StandardDistribution gaussian = new StandardDistribution(); for (int i = 0; i < 100; i++) { ComplexVector v = new ComplexVector(new Complex[] { Complex.Random(gaussian), Complex.Random(gaussian) }); ComplexMatrix rotation = Orthogonal.Rotation(v); ComplexVector res = rotation * v; Assert.That(rotation.HermitianTranspose() * rotation, NumericIs.AlmostEqualTo(ComplexMatrix.Identity(2, 2)), "unitary rotation matrix"); Assert.That(rotation[0, 0].IsReal, "c1 real"); Assert.That(rotation[1, 1].IsReal, "c2 real"); Assert.That(res[0].Modulus, NumericIs.AlmostEqualTo(v.Norm(), 1e-12), "res(1)"); Assert.That(res[1], NumericIs.AlmostEqualTo((Complex)0, 1e-12), "res(2)"); } }
public OrthogonalState(Orthogonal <TState, TTransition, TSignal> machine, State <TState, TTransition, TSignal> state, in OrthogonalState <TState, TTransition, TSignal> parent = default)
public OrthogonalSignal(Orthogonal <TState, TTransition, TSignal> machine, Signal <TState, TTransition, TSignal> signal, in OrthogonalState <TState, TTransition, TSignal> outerState = default)
public static double[] pds_random(int n, ref typeMethods.r8NormalData data, ref int seed) //****************************************************************************80 // // Purpose: // // PDS_RANDOM returns the PDS_RANDOM matrix. // // Discussion: // // The matrix is a "random" positive definite symmetric matrix. // // The matrix returned will have eigenvalues in the range [0,1]. // // Properties: // // A is symmetric: A' = A. // // A is positive definite: 0 < x'*A*x for nonzero x. // // The eigenvalues of A will be real. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 15 June 2011 // // Author: // // John Burkardt // // Parameters: // // Input, int N, the order of the matrix. // // Input/output, int &SEED, a seed for the random // number generator. // // Output, double PDS_RANDOM[N*N], the matrix. // { int j; double[] a = new double[n * n]; // // Get a random set of eigenvalues. // double[] lambda = UniformRNG.r8vec_uniform_01_new(n, ref seed); // // Get a random orthogonal matrix Q. // double[] q = Orthogonal.orth_random(n, ref data, ref seed); // // Set A = Q * Lambda * Q'. // for (j = 0; j < n; j++) { int i; for (i = 0; i < n; i++) { a[i + j * n] = 0.0; int k; for (k = 0; k < n; k++) { a[i + j * n] += q[i + k * n] * lambda[k] * q[j + k * n]; } } } return(a); }
public static void test05(int degree, int numnodes, double[] vert1, double[] vert2, double[] vert3) //****************************************************************************80 // // Purpose: // // TEST05 calls TRIASYMQ for a quadrature rule of given order and region. // // Licensing: // // This code is distributed under the GNU GPL license. // // Modified: // // 28 June 2014 // // Author: // // Original FORTRAN77 version by Hong Xiao, Zydrunas Gimbutas. // C++ version by John Burkardt. // // Reference: // // Hong Xiao, Zydrunas Gimbutas, // A numerical algorithm for the construction of efficient quadrature // rules in two and higher dimensions, // Computers and Mathematics with Applications, // Volume 59, 2010, pages 663-676. // // Parameters: // // Input, int DEGREE, the desired total polynomial degree // exactness of the quadrature rule. 0 <= DEGREE <= 50. // // Input, int NUMNODES, the number of nodes to be used by the rule. // // Input, double VERT1[2], VERT2[2], VERT3[2], the // vertices of the triangle. // { int i; int j; double[] z = new double[2]; Console.WriteLine(""); Console.WriteLine("TEST05"); Console.WriteLine(" Compute a quadrature rule for a triangle."); Console.WriteLine(" Check it by integrating orthonormal polynomials."); Console.WriteLine(" Polynomial exactness degree DEGREE = " + degree + ""); double area = typeMethods.triangle_area(vert1, vert2, vert3); // // Retrieve a symmetric quadrature rule. // double[] rnodes = new double[2 * numnodes]; double[] weights = new double[numnodes]; SymmetricQuadrature.triasymq(degree, vert1, vert2, vert3, ref rnodes, ref weights, numnodes); // // Construct the matrix of values of the orthogonal polynomials // at the user-provided nodes // int npols = (degree + 1) * (degree + 2) / 2; double[] rints = new double[npols]; for (j = 0; j < npols; j++) { rints[j] = 0.0; } for (i = 0; i < numnodes; i++) { z[0] = rnodes[0 + i * 2]; z[1] = rnodes[1 + i * 2]; double[] r = typeMethods.triangle_to_ref(vert1, vert2, vert3, z); double[] pols = Orthogonal.ortho2eva(degree, r); for (j = 0; j < npols; j++) { rints[j] += weights[i] * pols[j]; } } double scale = Math.Sqrt(Math.Sqrt(3.0)) / Math.Sqrt(area); for (j = 0; j < npols; j++) { rints[j] *= scale; } double d = Math.Pow(rints[0] - Math.Sqrt(area), 2); for (j = 1; j < npols; j++) { d += rints[j] * rints[j]; } d = Math.Sqrt(d) / npols; Console.WriteLine(""); Console.WriteLine(" RMS integration error = " + d + ""); }
public OrthogonalTransition(Orthogonal <TState, TTransition, TSignal> machine, Transition <TState, TTransition, TSignal> transition, in OrthogonalState <TState, TTransition, TSignal> parent = default)