void JacobiM() { //if (!Initial.SequenceEqual(Iteration.MassX)) //{ Jacobi.Iteration(Iteration.MassX); dataGridView1.ColumnCount += 1; for (int i = 0; i < Iteration.Count_x; i++) { dataGridView1[1, i].Value = Iteration.MassX[i]; } Second = new int[Iteration.Count_x]; Iteration.MassX.CopyTo(Second, 0); do { int n; Jacobi.Iteration(Iteration.MassX); dataGridView1.ColumnCount += 1; n = dataGridView1.ColumnCount; for (int i = 0; i < Iteration.Count_x; i++) { dataGridView1[n - 1, i].Value = Iteration.MassX[i]; } } while (!Second.SequenceEqual(Iteration.MassX)); //} }
public void TestProfileFormatJacobi() { int predCoeff = 0; Vector expectedAnswer = new Vector(dim); for (int i = 0; i < dim; i++) { expectedAnswer[i] = i + 1; } var matrix = generateProfileMatrix(predCoeff); var rightPart = generateRightPart(matrix, expectedAnswer); Jacobi solver = new Jacobi(); EmptyPreconditioner precond = EmptyPreconditioner.Create(matrix); Vector answer = solver.Solve(precond, rightPart, new Vector(dim), Logger.Instance, Logger.Instance, new JacobiParametrs(eps, maxIter)); Console.Write("Generate complete...\n"); for (int i = 0; i < dim; i++) { Console.Write(expectedAnswer[i].ToString() + "\t" + answer[i].ToString() + "\n"); Assert.AreEqual(expectedAnswer[i], answer[i], 0.001, "Not equal!"); } }
public void JacobiMultiComplexTest() { var z = new[] { new Complex(0.0115779438837883, 0.00215513498962569), new Complex(0.0251305156397967, -0.0159972042786677), new Complex(2.12623597863526, 0.480192562215063), new Complex(-1.8128943757431, 0.175402508876567), new Complex(0.974889810203627, 0.317370944403016), }; var m = new[] { .82872474670, .95465479750, .41588039490, .79913716820, .22263345920, }; var cn_ans = new[] { "0.9999353004739177-0.0000249497100713 i", "0.9998120824513089+0.0004018967006233 i", "-0.2620696287961345-0.3671429875904256 i", "0.2003469806496059+0.0828329851756354 i", "0.6050679400137476-0.2419659452739375 i", }; var sn_ans = new[] { "0.011577520035845973+0.002154873907338315 i", "0.02513162775967239-0.01598866500104887 i", "1.0366906460437097-0.0928117050540744 i", "-0.9833652385779392+0.0168760678403997 i", "0.8497782949947773+0.1722870976144199 i", }; var dn_ans = new[] { "0.9999463821545492-0.0000206762130171 i", "0.9998206008771541+0.0003836693444763 i", "0.7479880904783000+0.0534965402190790 i", "0.4777309286723279+0.0277602955990134 i", "0.9203769973939489-0.0354146592336434 i", }; for (int i = 0; i < z.Length; i++) { var mt = Jacobi.Multi(z[i], m[i]); var ex = Parse(cn_ans[i]); Assert.IsTrue(Complex.Abs(mt.cn - ex) < 1e-15); ex = Parse(sn_ans[i]); Assert.IsTrue(Complex.Abs(mt.sn - ex) < 1e-15); ex = Parse(dn_ans[i]); Assert.IsTrue(Complex.Abs(mt.dn - ex) < 1e-15); var f = Jacobi.MultiComplex(m[i]); var mtf = f(z[i]); Assert.AreEqual(mt.sn, mtf.sn); Assert.AreEqual(mt.cn, mtf.cn); Assert.AreEqual(mt.dn, mtf.dn); } }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); w = GraphicsDevice.Viewport.Bounds.Width; h = GraphicsDevice.Viewport.Bounds.Height; data = new uint[w * h]; sw = GraphicsDevice.Viewport.Bounds.Width; sh = GraphicsDevice.Viewport.Bounds.Height; // texture = new Texture2D(GraphicsDevice, w, h); textureFade = new Texture2D(GraphicsDevice, 1, 1); textureFade.SetData(new uint[] { 0x0f000000 }); textureWhite = new Texture2D(GraphicsDevice, 1, 1); textureWhite.SetData(new uint[] { 0xFFFFFFFF }); // Setup our BasicEffect for drawing the quad worldMatrix = Matrix.CreateScale(w / (float)h, 1, 1); display = Content.Load <Effect>("basic"); depthEffect = Content.Load <Effect>("depth"); Matrix projection = Matrix.CreateOrthographicOffCenter(0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, 0, 0, 1); Matrix halfPixelOffset = Matrix.CreateTranslation(-0.5f, -0.5f, 0); display.Parameters["MatrixTransform"].SetValue(halfPixelOffset * projection); depthEffect.Parameters["MatrixTransform"].SetValue(halfPixelOffset * projection); // Create a vertex declaration vertexDeclaration = new VertexDeclaration( new VertexElement[] { new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0), new VertexElement(12, VertexElementFormat.Vector3, VertexElementUsage.Normal, 0), new VertexElement(24, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0) }); velocity = new RenderTargetDouble(GraphicsDevice, w, h); density = new RenderTargetDouble(GraphicsDevice, w, h); velocityDivergence = new RenderTargetDouble(GraphicsDevice, w, h); velocityVorticity = new RenderTargetDouble(GraphicsDevice, w, h); pressure = new RenderTargetDouble(GraphicsDevice, w, h); advect = new Advect(w, h, timestep, Content); boundary = new Boundary(w, h, Content); diffuse = new Jacobi(Content.Load <Effect>("jacobivector"), w, h); divergence = new Divergence(w, h, Content); poissonPressureEq = new Jacobi(Content.Load <Effect>("jacobiscalar"), w, h); gradient = new Gradient(w, h, Content); splat = new Splat(w, h, Content); vorticity = new Vorticity(w, h, Content); vorticityConfinement = new VorticityConfinement(Content.Load <Effect>("vorticityforce"), w, h, timestep); // this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader(); this.depthFrameReader = this.kinectSensor.DepthFrameSource.OpenReader(); this.kinectSensor.Open(); // this.bodyFrameReader.FrameArrived += this.Reader_FrameArrived; this.depthFrameReader.FrameArrived += DepthFrameReader_FrameArrived; }
static void Main(string[] args) { /* Compare the time it takes to diagonalize a matrix * of size n by different methods: * Cyclic jacobi, value-by-value and v-b-v * for both highest and lowest eig val. */ Stopwatch sw = new Stopwatch(); foreach (string arg in args) { int n = Int32.Parse(arg); // Generate symmetric nxn matrix A matrix A = randomMatrix(n, n); restoreUpperTriang(A); // Cyclic jacobi matrix V = new matrix(n, n); vector e = new vector(n); sw.Start(); int sweeps = Jacobi.cyclic(A, V, e); sw.Stop(); double cyclic = sw.Elapsed.Ticks / 10000.0; sw.Reset(); // Value-by-value full V = new matrix(n, n); e = new vector(n); sw.Start(); vector eigVals = Jacobi.lowestK(A, V, e, n); sw.Stop(); double VBVfull = sw.Elapsed.Ticks / 10000.0; sw.Reset(); // Value-by-value 1 V = new matrix(n, n); e = new vector(n); sw.Start(); eigVals = Jacobi.lowestK(A, V, e, 1); sw.Stop(); double VBVlow = sw.Elapsed.Ticks / 10000.0; sw.Reset(); // Value-by-value 1, highest first V = new matrix(n, n); e = new vector(n); sw.Start(); eigVals = Jacobi.highestK(A, V, e, 1); sw.Stop(); double VBVhigh = sw.Elapsed.Ticks / 10000.0; sw.Reset(); // size of matrix and time in ms WriteLine($"{n} {cyclic} {VBVfull} {VBVlow} {VBVhigh}"); } }
/// <summary> /// Initializes a new instance of the <see cref="DynamicSimulationFramework.Simulation.State"/> class. /// </summary> /// <param name='w'> /// World to be simulated. /// </param> /// <param name='dt'> /// Size of the time steps /// </param> /// <param name='solver'> /// <see cref="irolver"/> /// </param> public State(World w, double dt, IIntegrator integrator) { World = w; TimeStep = dt; Time = 0; RigidStates = new Dictionary<IRigid, RigidState> (); Integrator = integrator; Solver = new Jacobi (); }
/// <summary> /// Called by the host. Returns MIDI Key name, so it is displayed i.e. in the FL Studio Piano Roll. /// </summary> /// <returns>True if the note map is defined, false otherwise</returns> public override bool GetMidiKeyName(Jacobi.Vst.Core.VstMidiKeyName midiKeyName, int channel) { try { midiKeyName.Name = p.NoteMaps[midiKeyName.CurrentKeyNumber].KeyName; return true; } catch (Exception) // Most likely out of range, since FL supports notes > 127 { midiKeyName.Name = "Unknown " + midiKeyName.CurrentKeyNumber; // This is actually never seen since we return false below return false; } }
public static void jacobi_poly_values_test() //****************************************************************************80 // // Purpose: // // JACOBI_POLY_VALUES_TEST tests JACOBI_POLY_VALUES. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 19 April 2012 // // Author: // // John Burkardt // { double a = 0; double b = 0; double fx = 0; int n = 0; double x = 0; Console.WriteLine(""); Console.WriteLine("JACOBI_POLY_VALUES_TEST:"); Console.WriteLine(" JACOBI_POLY_VALUES returns values of"); Console.WriteLine(" the Jacobi polynomial."); Console.WriteLine(""); Console.WriteLine(" N A B X J(N,A,B)(X)"); Console.WriteLine(""); int n_data = 0; for (;;) { Jacobi.jacobi_poly_values(ref n_data, ref n, ref a, ref b, ref x, ref fx); if (n_data == 0) { break; } Console.WriteLine(" " + n.ToString(CultureInfo.InvariantCulture).PadLeft(6) + " " + a.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + b.ToString(CultureInfo.InvariantCulture).PadLeft(8) + " " + x.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + fx.ToString("0.################").PadLeft(24) + ""); } }
public void JacobiCnDoubleArgTest() { for (int i = 0; i < jacobiData.Length; i += 5) { var z = jacobiData[i]; var m = jacobiData[i + 1]; var ex = jacobiData[i + 2]; var cn = Jacobi.cn(z, m); var err = Math.Abs(ex - cn) / Math.Abs(ex); Assert.IsTrue(err < 1e-15); var f = Jacobi.cnDouble(m); var cn2 = f(z); Assert.AreEqual(cn, cn2); } }
public static void jacobi_cn_values_test() //****************************************************************************80 // // Purpose: // // jacobi_cn_values_test tests jacobi_cn_values(). // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 19 November 2020 // // Author: // // John Burkardt // { double a = 0; double fx = 0; double k = 0; double m = 0; double u = 0; Console.WriteLine(""); Console.WriteLine("jacobi_cn_values_test:"); Console.WriteLine(" jacobi_cn_values() returns values of "); Console.WriteLine(" the Jacobi elliptic CN function."); Console.WriteLine(""); Console.WriteLine(" U M CN(U,M)"); Console.WriteLine(""); int n_data = 0; for (;;) { Jacobi.jacobi_cn_values(ref n_data, ref u, ref a, ref k, ref m, ref fx); if (n_data == 0) { break; } Console.WriteLine(" " + u.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + m.ToString(CultureInfo.InvariantCulture).PadLeft(10) + " " + fx.ToString("0.################").PadLeft(24) + ""); } }
public void JacobiAmDoubleTest() { for (int i = 0; i < jacobiData.Length; i += 5) { var z = jacobiData[i]; var m = jacobiData[i + 1]; var sn = jacobiData[i + 3]; var ex = Math.Asin(sn); var am = Jacobi.am(z, m); var err = Math.Abs(am - ex) / Math.Abs(ex); Assert.IsTrue(err < 1e-14); var f = Jacobi.amDouble(m); var am2 = f(z); Assert.AreEqual(am, am2); } }
public void JacobiDnDoubleArgTest() { for (int i = 0; i < jacobiData.Length; i += 5) { var z = jacobiData[i]; var m = jacobiData[i + 1]; var ex = jacobiData[i + 4]; var dn = Jacobi.dn(z, m); var err = Math.Abs(ex - dn) / Math.Abs(ex); Assert.IsTrue(err < 1e-14); //System.Diagnostics.Trace.WriteLine(dn); var f = Jacobi.dnDouble(m); var dn2 = f(z); Assert.AreEqual(dn, dn2); } }
static void Main() { int n = 6; WriteLine($"Generate symmetric {n}x{n} matrix A"); matrix A = randomMatrix(n, n); restoreUpperTriang(A); A.print("A: "); matrix V = new matrix(n, n); vector e = new vector(n); int sweeps; // Cyclic sweeps = Jacobi.cyclic(A, V, e); WriteLine($"Cyclic Jacobi done in {sweeps} sweeps"); e.print("Cyclic eigenvalues: "); // Lowest k restoreUpperTriang(A); V = new matrix(n, n); e = new vector(n); int k = n / 3; vector v = Jacobi.lowestK(A, V, e, k); v.print($"Lowest {k} values:"); A.print($"Test that {k} rows are cleared"); // Highest k restoreUpperTriang(A); V = new matrix(n, n); e = new vector(n); k = n / 3; v = Jacobi.highestK(A, V, e, k); v.print($"Highest {k} values:"); A.print($"Test that {k} rows are cleared"); restoreUpperTriang(A); V = new matrix(n, n); e = new vector(n); int rots = Jacobi.classic(A, V, e); e.print($"Classical done! rotations: {rots}"); A.print($"Test that all rows are cleared"); }
public static double evaluate(double u, double m) //****************************************************************************80 // // Purpose: // // JACOBI_DN evaluates the Jacobi elliptic function DN(U,M). // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 26 June 2018 // // Author: // // Original ALGOL version by Roland Bulirsch. // C++ version by John Burkardt // // Reference: // // Roland Bulirsch, // Numerical calculation of elliptic integrals and elliptic functions, // Numerische Mathematik, // Volume 7, Number 1, 1965, pages 78-90. // // Parameters: // // Input, double U, M, the arguments. // // Output, double JACOBI_DN, the function value. // { double cn = 0; double dn = 0; double sn = 0; Jacobi.sncndn(u, m, ref sn, ref cn, ref dn); return(dn); }
public void JacobiMultiDoubleTest() { for (int i = 0; i < jacobiData.Length; i += 5) { var z = jacobiData[i]; var m = jacobiData[i + 1]; var cn = jacobiData[i + 2]; var sn = jacobiData[i + 3]; var dn = jacobiData[i + 4]; var multi = Jacobi.Multi(z, m); Assert.IsTrue(Math.Abs(cn - multi.cn) < 1e-14); Assert.IsTrue(Math.Abs(sn - multi.sn) < 1e-14); Assert.IsTrue(Math.Abs(dn - multi.dn) < 1e-14); var fm = Jacobi.MultiDouble(m); var m2 = fm(z); Assert.AreEqual(multi.cn, m2.cn); Assert.AreEqual(multi.sn, m2.sn); Assert.AreEqual(multi.dn, m2.dn); } }
public void JacobiArcDoubleTest() { for (int i = 0; i < jacobiData.Length; i += 5) { var z = jacobiData[i]; var m = jacobiData[i + 1]; var cn = jacobiData[i + 2]; var sn = jacobiData[i + 3]; var arc = Jacobi.arccn(cn, m); Assert.IsTrue(Math.Abs(arc - Math.Abs(z)) < 1e-14); arc = Jacobi.arcsn(sn, m); Assert.IsTrue(Math.Abs(arc - z) < 1e-14); var f = Jacobi.arccnDouble(m); arc = f(cn); Assert.IsTrue(Math.Abs(arc - Math.Abs(z)) < 1e-14); f = Jacobi.arcsnDouble(m); arc = f(sn); Assert.IsTrue(Math.Abs(arc - z) < 1e-14); } }
private void btnJacobi_Click(object sender, EventArgs e) { txtEcuaciones.Clear(); Jacobi mt = new Jacobi(dgvEcuaciones.RowCount, dgvEcuaciones.ColumnCount); float[,] matIn = llenarArray(); for (int i = 0; i < dgvEcuaciones.RowCount; i++) { for (int j = 0; j < dgvEcuaciones.ColumnCount; j++) { mt.SetValue(i, j, matIn[i, j]); } } mt.Cambio += new EventHandler <MatrizEventArgs>(mt_Cambio); mt.Completo += new EventHandler <MatrizEventArgs>(mt_Completo); mt.ApplyJacobyMethod(); }
public void JacobiArcsnComplexArgTest() { var z = new[] { new Complex(0.0115779438837883, 0.00215513498962569), new Complex(0.0251305156397967, -0.0159972042786677), new Complex(1.4511560737138, -0.480192562215063), new Complex(-1.8128943757431, 0.175402508876567), new Complex(0.974889810203627, 0.317370944403016), }; var m = new[] { .82872474670, .95465479750, .41588039490, .79913716820, .22263345920, }; var ans = new[] { "0.011577520035845973+0.002154873907338315 i", "0.02513162775967239-0.01598866500104887 i", "1.0366906460437097-0.0928117050540744 i", "-0.9833652385779392+0.0168760678403997 i", "0.8497782949947773+0.1722870976144199 i", }; for (int i = 0; i < z.Length; i++) { var sn = Parse(ans[i]); var arcsn = Jacobi.arcsn(sn, m[i]); var ex = z[i]; Assert.IsTrue(Complex.Abs(arcsn - ex) < 1e-14); var f = Jacobi.arcsnComplex(m[i]); var a2 = f(sn); Assert.AreEqual(arcsn, a2); } }
public void JacobiArccnComplexArgTest() { var z = new[] { new Complex(0.0115779438837883, 0.00215513498962569), new Complex(0.0251305156397967, -0.0159972042786677), new Complex(2.12623597863526, 0.480192562215063), new Complex(1.8128943757431, -0.175402508876567), new Complex(0.974889810203627, 0.317370944403016), }; var m = new[] { .8287247467, .9546547975, .4158803949, .7991371682, .2226334592, }; var ans = new[] { "0.9999353004739177-0.0000249497100713 i", "0.9998120824513089+0.0004018967006233 i", "-0.2620696287961345-0.3671429875904256 i", "0.2003469806496059+0.0828329851756354 i", "0.6050679400137476-0.2419659452739375 i", }; for (int i = 0; i < z.Length; i++) { var cn = Parse(ans[i]); var arccn = Jacobi.arccn(cn, m[i]); var ex = z[i]; Assert.IsTrue(Complex.Abs(arccn - ex) < 1e-13); var f = Jacobi.arccnComplex(m[i]); var a2 = f(cn); Assert.AreEqual(arccn, a2); } }
public void JacobiDnComplexArgTest() { var z = new[] { new Complex(0.0115779438837883, 0.00215513498962569), new Complex(0.0251305156397967, -0.0159972042786677), new Complex(2.12623597863526, 0.480192562215063), new Complex(-1.8128943757431, 0.175402508876567), new Complex(0.974889810203627, 0.317370944403016), }; var m = new[] { .82872474670, .95465479750, .41588039490, .79913716820, .22263345920, }; var ans = new[] { "0.9999463821545492-0.0000206762130171 i", "0.9998206008771541+0.0003836693444763 i", "0.7479880904783000+0.0534965402190790 i", "0.4777309286723279+0.0277602955990134 i", "0.9203769973939489-0.0354146592336434 i", }; for (int i = 0; i < z.Length; i++) { var dn = Jacobi.dn(z[i], m[i]); var ex = Parse(ans[i]); Assert.IsTrue(Complex.Abs(dn - ex) < 1e-15); var f = Jacobi.dnComplex(m[i]); dn = f(z[i]); Assert.IsTrue(Complex.Abs(dn - ex) < 1e-15); } }
public void JacobiAmComplexTest() { var data = new[] { 1, 0, .7, 0.90554608446342, 0, .5, 0, .8, 0.48427327785248, 0, .5, .5, .5, 0.51828196329292, 0.47708333882708, 0, .5, .4, 0, 0.50881372387993, .7, -.7, .2, 0.71761686290329, -0.67315349672164, }; for (int i = 0; i < data.Length; i += 5) { var z = new Complex(data[i], data[i + 1]); var m = data[i + 2]; var ex = new Complex(data[i + 3], data[i + 4]); var am = Jacobi.am(z, m); var amf = Jacobi.amComplex(m); var am2 = amf(z); Assert.AreEqual(am, am2); var err = Complex.Abs(am - ex) / Complex.Abs(ex); Assert.IsTrue(err < 1e-14); } }
// Simulation public void ShapeMatch() { if (IsDirty) { CalculateInvariants(); IsDirty = false; } for (int i = 0; i != mParticles.Count; ++i) { SmParticle particle = mParticles[i]; particle.mSumData.mV = particle.PerRegionMass * particle.mX; particle.mSumData.mM = Matrix3x3.MultiplyWithTranspose(particle.PerRegionMass * particle.mX, particle.mX0); } SumParticlesToRegions(); for (int i = 0; i != mRegions.Count; ++i) { SmRegion r = mRegions[i]; Vector3 Fmixi = r.mSumData.mV; Matrix3x3 Fmixi0T = r.mSumData.mM; r.mC = (1 / r.mM) * Fmixi; //9 r.mA = Fmixi0T - Matrix3x3.MultiplyWithTranspose(r.mM * r.mC, r.mC0); Matrix3x3 S = r.mA.transpose * r.mA; S = r.mEigenVectors.transpose * S * r.mEigenVectors; float[] eigenValues = new float[3]; Jacobi.jacobi(3, ref S, ref eigenValues, ref r.mEigenVectors); for (int j = 0; j != 3; ++j) { if (eigenValues[j] <= 0.0f) { eigenValues[j] = 0.05f; } eigenValues[j] = 1.0f / Mathf.Sqrt(eigenValues[j]); } Matrix3x3 DPrime = new Matrix3x3(eigenValues[0], 0, 0, 0, eigenValues[1], 0, 0, 0, eigenValues[2]); S = r.mEigenVectors * DPrime * r.mEigenVectors.transpose; r.mR = r.mA * S; if (r.mR.determinant < 0) { r.mR *= (-1.0f); } r.mT = r.mC - r.mR * r.mC0; r.mSumData.mM = r.mR; r.mSumData.mV = r.mT; } SumRegionsToParticles(); for (int i = 0; i != mParticles.Count; ++i) { SmParticle particle = mParticles[i]; float invNumParentRegions = 1.0f / particle.mParentRegions.Count; particle.mG = (invNumParentRegions * particle.mSumData.mM) * particle.mX0 + invNumParentRegions * particle.mSumData.mV; particle.mR = invNumParentRegions * particle.mSumData.mM; } }
private static void test01() //****************************************************************************80 // // Purpose: // // TEST01 uses a 4x4 test matrix. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 15 July 2013 // // Author: // // John Burkardt // { const int N = 4; double[] a = { 4.0, -30.0, 60.0, -35.0, -30.0, 300.0, -675.0, 420.0, 60.0, -675.0, 1620.0, -1050.0, -35.0, 420.0, -1050.0, 700.0 } ; double[] d = new double[N]; int it_num = 0; int rot_num = 0; double[] v = new double[N * N]; Console.WriteLine(""); Console.WriteLine("TEST01"); Console.WriteLine(" For a symmetric matrix A,"); Console.WriteLine(" JACOBI_EIGENVALUE computes the eigenvalues D"); Console.WriteLine(" and eigenvectors V so that A * V = D * V."); typeMethods.r8mat_print(N, N, a, " Input matrix A:"); const int it_max = 100; Jacobi.jacobi_eigenvalue(N, a, it_max, ref v, ref d, ref it_num, ref rot_num); Console.WriteLine(""); Console.WriteLine(" Number of iterations = " + it_num + ""); Console.WriteLine(" Number of rotations = " + rot_num + ""); typeMethods.r8vec_print(N, d, " Eigenvalues D:"); typeMethods.r8mat_print(N, N, v, " Eigenvector matrix V:"); // // Compute eigentest. // double error_frobenius = typeMethods.r8mat_is_eigen_right(N, N, a, v, d); Console.WriteLine(""); Console.WriteLine(" Frobenius norm error in eigensystem A*V-D*V = " + error_frobenius + ""); }
/// <inheritdoc /> public Jacobi.Vst.Core.VstTimeInfo GetTimeInfo(Jacobi.Vst.Core.VstTimeInfoFlags filterFlags) { RaisePluginCalled("GetTimeInfo(" + filterFlags + ")"); return null; }
static int Main() { // Generate matrix A int n = 12; WriteLine("Creating random 7x7 matrix, A..."); matrix A = randomMatrix(n, n); // Make A symmetric restoreUpperTriang(A); matrix V = new matrix(n, n); vector e = new vector(n); // Vector of eigenvalues A.print("A:"); WriteLine("Calculating eigenvalues..."); (int sweeps, int rots) = Jacobi.cyclic(A, V, e); WriteLine($"Calculation done! Number of sweeps: {sweeps}"); V.print("Eigenvectors"); matrix D = new matrix(n, n); for (int i = 0; i < n; i++) { D[i, i] = e[i]; } D.print("Diagonal composition, D:"); restoreUpperTriang(A); // Restore A matrix test = V.transpose() * A * V; test.print("Test that V^T * A * V = D"); matrix test2 = V * D * V.transpose(); test2.print("Test that V * D * V^T = A"); WriteLine("Test first eigenvalue and vector:"); vector eigvec = A * V[0]; vector eigval = D[0, 0] * V[0]; eigvec.print("A * V[0] : "); eigval.print("D[0,0] * V[0] : "); // Calculate numerically Quantum particle in a box WriteLine("--- Calculate numerically QM particle in a box ---"); // Generate H int N = 23; // Number of numerical steps double s = 1.0 / (N + 1); matrix H = new matrix(N, N); for (int i = 0; i < N - 1; i++) { H[i, i] = -2; H[i, i + 1] = 1; H[i + 1, i] = 1; } H[N - 1, N - 1] = -2; H.print("H, before scaling"); H = -1 / s / s * H; // Diagonalize H using jacobi matrix boxV = new matrix(N, N); vector boxE = new vector(N); (int hsweeps, int hrots) = Jacobi.cyclic(H, boxV, boxE); // Test that WriteLine("Calculation done: Checking that energies are correct"); WriteLine("E_n \t Calculation \t Exact"); for (int k = 0; k < N / 3; k++) { double exact = PI * PI * (k + 1) * (k + 1); double calc = boxE[k]; WriteLine($"E_{k} \t {calc.ToString("N5")} \t {exact.ToString("N5")}"); } // Scaling factor a double a = Sqrt(2) / boxV[N / 2, 0]; WriteLine($"a: {a}"); // Generate plotting data to plot with using (StreamWriter sw = new StreamWriter("data-A.txt")){ // Plot the first 3 wave funcs // Format: x \t psi0 \t psi_n ... sw.WriteLine($"0 \t 0 \t 0 \t 0 \t 0 \t 0"); for (int i = 0; i < N; i++) { sw.Write($"{(i+1.0)/(N+1)} "); for (int k = 0; k < 5; k++) { sw.Write($"\t {a*boxV[i,k]} "); } sw.Write("\n"); } sw.WriteLine($"1 \t 0 \t 0 \t 0 \t 0 \t 0"); } return(0); }
private static void test03() //****************************************************************************80 // // Purpose: // // TEST03 uses a 5x5 test matrix. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 15 July 2013 // // Author: // // John Burkardt // { const int N = 5; double[] a = new double[N * N]; double[] d = new double[N]; int it_num = 0; int j; int rot_num = 0; double[] v = new double[N * N]; Console.WriteLine(""); Console.WriteLine("TEST03"); Console.WriteLine(" For a symmetric matrix A,"); Console.WriteLine(" JACOBI_EIGENVALUE computes the eigenvalues D"); Console.WriteLine(" and eigenvectors V so that A * V = D * V."); Console.WriteLine(""); Console.WriteLine(" Use the discretized second derivative matrix."); for (j = 0; j < N; j++) { int i; for (i = 0; i < N; i++) { if (i == j) { a[i + j * N] = -2.0; } else if (i == j + 1 || i == j - 1) { a[i + j * N] = 1.0; } else { a[i + j * N] = 0.0; } } } typeMethods.r8mat_print(N, N, a, " Input matrix A:"); const int it_max = 100; Jacobi.jacobi_eigenvalue(N, a, it_max, ref v, ref d, ref it_num, ref rot_num); Console.WriteLine(""); Console.WriteLine(" Number of iterations = " + it_num + ""); Console.WriteLine(" Number of rotations = " + rot_num + ""); typeMethods.r8vec_print(N, d, " Eigenvalues D:"); typeMethods.r8mat_print(N, N, v, " Eigenvector matrix V:"); // // Compute eigentest. // double error_frobenius = typeMethods.r8mat_is_eigen_right(N, N, a, v, d); Console.WriteLine(""); Console.WriteLine(" Frobenius norm error in eigensystem A*V-D*V = " + error_frobenius + ""); }
private static void test14() //****************************************************************************80 // // Purpose: // // TEST14 demonstrates R_JACOBI. // // Discussion: // // R_JACOBI returns recursion coefficients ALPHA and BETA for rules // using a Jacobi type weight w(x) = (1-x)^A * (1+x)^B. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 17 July 2013 // // Author: // // John Burkardt // // Reference // // Walter Gautschi, // Orthogonal Polynomials: Computation and Approximation, // Oxford, 2004, // ISBN: 0-19-850672-4, // LC: QA404.5 G3555. // { int i; Console.WriteLine(""); Console.WriteLine("TEST14"); Console.WriteLine(" R_JACOBI computes recursion coefficients ALPHA and BETA"); Console.WriteLine(" Gauss quadrature rule, given the ALPHA and BETA"); Console.WriteLine(" recursion coefficients."); // // Legendre rule. // int n = 10; double a = 0.0; double b = 0.0; double[] alpha = new double[n]; double[] beta = new double[n]; Jacobi.r_jacobi(n, a, b, ref alpha, ref beta); Console.WriteLine(""); Console.WriteLine(" Legendre weight"); Console.WriteLine(" A = " + a + ", B = " + b + ""); Console.WriteLine(" Alpha Beta"); Console.WriteLine(""); for (i = 0; i < n; i++) { Console.WriteLine(" " + alpha[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + " " + beta[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + ""); } // // Chebyshev Type 1 rule. // n = 10; a = -0.5; b = -0.5; alpha = new double[n]; beta = new double[n]; Jacobi.r_jacobi(n, a, b, ref alpha, ref beta); Console.WriteLine(""); Console.WriteLine(" Chebyshev Type 1 weight"); Console.WriteLine(" A = " + a + ", B = " + b + ""); Console.WriteLine(" Alpha Beta"); Console.WriteLine(""); for (i = 0; i < n; i++) { Console.WriteLine(" " + alpha[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + " " + beta[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + ""); } // // Chebyshev Type 2 rule. // n = 10; a = +0.5; b = +0.5; alpha = new double[n]; beta = new double[n]; Jacobi.r_jacobi(n, a, b, ref alpha, ref beta); Console.WriteLine(""); Console.WriteLine(" Chebyshev Type 2 weight"); Console.WriteLine(" A = " + a + ", B = " + b + ""); Console.WriteLine(" Alpha Beta"); Console.WriteLine(""); for (i = 0; i < n; i++) { Console.WriteLine(" " + alpha[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + " " + beta[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + ""); } // // General Jacobi rule. // n = 10; a = +0.5; b = +1.5; alpha = new double[n]; beta = new double[n]; Jacobi.r_jacobi(n, a, b, ref alpha, ref beta); Console.WriteLine(""); Console.WriteLine(" General Jacobi weight"); Console.WriteLine(" A = " + a + ", B = " + b + ""); Console.WriteLine(" Alpha Beta"); Console.WriteLine(""); for (i = 0; i < n; i++) { Console.WriteLine(" " + alpha[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + " " + beta[i].ToString(CultureInfo.InvariantCulture).PadLeft(14) + ""); } }
public static void jacobi_compute(int order, double alpha, double beta, ref double[] x, ref double[] w) //****************************************************************************80 // // Purpose: // // JACOBI_COMPUTE computes a Jacobi quadrature rule. // // Discussion: // // The integration interval is [ -1, 1 ]. // // The weight function is w(x) = (1-X)^ALPHA * (1+X)^BETA. // // The integral to approximate: // // Integral ( -1 <= X <= 1 ) (1-X)^ALPHA * (1+X)^BETA * F(X) dX // // The quadrature rule: // // Sum ( 1 <= I <= ORDER ) W(I) * F ( X(I) ) // // Thanks to Xu Xiang of Fudan University for pointing out that // an earlier implementation of this routine was incorrect! // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 18 February 2008 // // Author: // // Original FORTRAN77 version by Arthur Stroud, Don Secrest. // C++ version by John Burkardt. // // Reference: // // Arthur Stroud, Don Secrest, // Gaussian Quadrature Formulas, // Prentice Hall, 1966, // LC: QA299.4G3S7. // // Parameters: // // Input, int ORDER, the order of the rule. // 1 <= ORDER. // // Input, double ALPHA, BETA, the exponents of (1-X) and // (1+X) in the quadrature rule. For simple Legendre quadrature, // set ALPHA = BETA = 0.0. -1.0 < ALPHA and -1.0 < BETA are required. // // Output, double X[ORDER], the abscissas. // // Output, double W[ORDER], the weights. // { double dp2 = 0; int i; double p1 = 0; double temp; double x0 = 0; switch (order) { case < 1: Console.WriteLine(""); Console.WriteLine("JACOBI_COMPUTE - Fatal error!"); Console.WriteLine(" Illegal value of ORDER = " + order + ""); return; } double[] b = new double[order]; double[] c = new double[order]; switch (alpha) { // // Check ALPHA and BETA. // case <= -1.0: Console.WriteLine(""); Console.WriteLine("JACOBI_COMPUTE - Fatal error!"); Console.WriteLine(" -1.0 < ALPHA is required."); return; } switch (beta) { case <= -1.0: Console.WriteLine(""); Console.WriteLine("JACOBI_COMPUTE - Fatal error!"); Console.WriteLine(" -1.0 < BETA is required."); return; } // // Set the recursion coefficients. // for (i = 1; i <= order; i++) { if (alpha + beta == 0.0 || beta - alpha == 0.0) { b[i - 1] = 0.0; } else { b[i - 1] = (alpha + beta) * (beta - alpha) / ((alpha + beta + 2 * i) * (alpha + beta + (2 * i - 2))); } c[i - 1] = i switch { 1 => 0.0, _ => 4.0 * (i - 1) * (alpha + (i - 1)) * (beta + (i - 1)) * (alpha + beta + (i - 1)) / ((alpha + beta + (2 * i - 1)) * Math.Pow(alpha + beta + (2 * i - 2), 2) * (alpha + beta + (2 * i - 3))) }; } double delta = typeMethods.r8_gamma(alpha + 1.0) * typeMethods.r8_gamma(beta + 1.0) / typeMethods.r8_gamma(alpha + beta + 2.0); double prod = 1.0; for (i = 2; i <= order; i++) { prod *= c[i - 1]; } double cc = delta * Math.Pow(2.0, alpha + beta + 1.0) * prod; for (i = 1; i <= order; i++) { double r2; double r3; double r1; switch (i) { case 1: double an = alpha / order; double bn = beta / order; r1 = (1.0 + alpha) * (2.78 / (4.0 + order * order) + 0.768 * an / order); r2 = 1.0 + 1.48 * an + 0.96 * bn + 0.452 * an * an + 0.83 * an * bn; x0 = (r2 - r1) / r2; break; case 2: r1 = (4.1 + alpha) / ((1.0 + alpha) * (1.0 + 0.156 * alpha)); r2 = 1.0 + 0.06 * (order - 8.0) * (1.0 + 0.12 * alpha) / order; r3 = 1.0 + 0.012 * beta * (1.0 + 0.25 * Math.Abs(alpha)) / order; x0 -= r1 * r2 * r3 * (1.0 - x0); break; case 3: r1 = (1.67 + 0.28 * alpha) / (1.0 + 0.37 * alpha); r2 = 1.0 + 0.22 * (order - 8.0) / order; r3 = 1.0 + 8.0 * beta / ((6.28 + beta) * (order * order)); x0 -= r1 * r2 * r3 * (x[0] - x0); break; default: { if (i < order - 1) { x0 = 3.0 * x[i - 2] - 3.0 * x[i - 3] + x[i - 4]; } else if (i == order - 1) { r1 = (1.0 + 0.235 * beta) / (0.766 + 0.119 * beta); r2 = 1.0 / (1.0 + 0.639 * (order - 4.0) / (1.0 + 0.71 * (order - 4.0))); r3 = 1.0 / (1.0 + 20.0 * alpha / ((7.5 + alpha) * (order * order))); x0 += r1 * r2 * r3 * (x0 - x[i - 3]); } else if (i == order) { r1 = (1.0 + 0.37 * beta) / (1.67 + 0.28 * beta); r2 = 1.0 / (1.0 + 0.22 * (order - 8.0) / order); r3 = 1.0 / (1.0 + 8.0 * alpha / ((6.28 + alpha) * (order * order))); x0 += r1 * r2 * r3 * (x0 - x[i - 3]); } break; } } Jacobi.jacobi_root(ref x0, order, alpha, beta, ref dp2, ref p1, b, c); x[i - 1] = x0; w[i - 1] = cc / (dp2 * p1); } // // Reverse the order of the values. // for (i = 1; i <= order / 2; i++) { temp = x[i - 1]; x[i - 1] = x[order - i]; x[order - i] = temp; } for (i = 1; i <= order / 2; i++) { temp = w[i - 1]; w[i - 1] = w[order - i]; w[order - i] = temp; } } }
private static void wishart_unit_sample_test() //****************************************************************************80 // // Purpose: // // WISHART_UNIT_SAMPLE_TEST demonstrates the unit Wishart sampling function. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 02 August 2013 // // Author: // // John Burkardt // { int it_num = 0; int rot_num = 0; Console.WriteLine(""); Console.WriteLine("WISHART_UNIT_SAMPLE_TEST:"); Console.WriteLine(" WISHART_UNIT_SAMPLE samples unit Wishart matrices by:"); Console.WriteLine(" W = Wishart.wishart_unit_sample ( n, df );"); // // Set the parameters and call. // int n = 5; int df = 8; double[] w = Wishart.wishart_unit_sample(n, df); typeMethods.r8mat_print(n, n, w, " Wishart.wishart_unit_sample ( 5, 8 ):"); // // Calling again yields a new matrix. // w = Wishart.wishart_unit_sample(n, df); typeMethods.r8mat_print(n, n, w, " Wishart.wishart_unit_sample ( 5, 8 ):"); // // Reduce DF // n = 5; df = 5; w = Wishart.wishart_unit_sample(n, df); typeMethods.r8mat_print(n, n, w, " Wishart.wishart_unit_sample ( 5, 5 ):"); // // Try a smaller matrix. // n = 3; df = 5; w = Wishart.wishart_unit_sample(n, df); typeMethods.r8mat_print(n, n, w, " Wishart.wishart_unit_sample ( 3, 5 ):"); // // What is the eigendecomposition of the matrix? // int it_max = 50; double[] v = new double[n * n]; double[] lambda = new double[n]; Jacobi.jacobi_eigenvalue(n, w, it_max, ref v, ref lambda, ref it_num, ref rot_num); typeMethods.r8mat_print(n, n, v, " Eigenvectors of previous matrix:"); typeMethods.r8vec_print(n, lambda, " Eigenvalues of previous matrix:"); }
/// <inheritdoc /> public Jacobi.Vst.Core.VstTimeInfo GetTimeInfo(Jacobi.Vst.Core.VstTimeInfoFlags filterFlags) { RaisePluginCalled("GetTimeInfo(" + filterFlags + ")"); // our sample calculator performs: // Create TimeInfo class VstTimeInfo vstTimeInfo = new VstTimeInfo(); // most common settings vstTimeInfo.SamplePosition = Parent.SampleOffset + Parent.BufferIncrement; vstTimeInfo.SampleRate = Parent.Settings.Rate; // filterFlags |= VstTimeInfoFlags.ClockValid; if (filterFlags.HasFlag(VstTimeInfoFlags.ClockValid)) { // should we floor this? int cp = MasterClock.SolvePPQ(Parent.SampleOffset, Parent.Settings).ClocksAtPosition.ToInt32(); vstTimeInfo.SamplesToNearestClock = MasterClock.SolveSamples(cp * 24, Parent.Settings).Samples32Floor; } // NanoSecondsValid filterFlags |= VstTimeInfoFlags.NanoSecondsValid; if (filterFlags.HasFlag(VstTimeInfoFlags.NanoSecondsValid)) { vstTimeInfo.NanoSeconds = (Parent.SampleOffset / Parent.Settings.Rate) * billionth; } // TempoValid filterFlags |= VstTimeInfoFlags.TempoValid; if (filterFlags.HasFlag(VstTimeInfoFlags.TempoValid)) { vstTimeInfo.Tempo = Parent.Settings.Tempo; } // PpqPositionValid filterFlags |= VstTimeInfoFlags.PpqPositionValid; if (filterFlags.HasFlag(VstTimeInfoFlags.PpqPositionValid)) { vstTimeInfo.PpqPosition = MasterClock.SolvePPQ(vstTimeInfo.SamplePosition, Parent.Settings).Frame; } // BarStartPositionValid filterFlags |= VstTimeInfoFlags.BarStartPositionValid; if (filterFlags.HasFlag(VstTimeInfoFlags.BarStartPositionValid)) { vstTimeInfo.BarStartPosition = MasterClock.SolvePPQ(vstTimeInfo.SamplePosition, Parent.Settings).Pulses; // * st.SamplesPerQuarter } // CyclePositionValid filterFlags |= VstTimeInfoFlags.CyclePositionValid; if (filterFlags.HasFlag(VstTimeInfoFlags.CyclePositionValid)) { vstTimeInfo.CycleStartPosition = Parent.SampleOffset;//st.SolvePPQ(Parent.SampleOffset,Parent.Settings).Frame; vstTimeInfo.CycleEndPosition = Parent.SampleOffset + Parent.CurrentSampleLength; } // TimeSignatureValid if (filterFlags.HasFlag(VstTimeInfoFlags.TimeSignatureValid)) { vstTimeInfo.TimeSignatureNumerator = Parent.Settings.TimeSignature.Numerator; vstTimeInfo.TimeSignatureDenominator = Parent.Settings.TimeSignature.Denominator; } // SmpteValid if (filterFlags.HasFlag(VstTimeInfoFlags.SmpteValid)) { vstTimeInfo.SmpteFrameRate = smpte_rate; /* 30 fps no-drop */ vstTimeInfo.SmpteOffset = 0; /* not quite valid */ } vstTimeInfo.Flags = filterFlags; return vstTimeInfo; }
/// <summary> /// Requests the host to process the <paramref name="events"/>. /// </summary> /// <param name="events">Must not be null.</param> /// <returns>Returns true if supported by the host.</returns> public bool ProcessEvents(Jacobi.Vst.Core.VstEvent[] events) { foreach (VstEvent vste in events) Console.WriteLine("hvste: {0}", vste.Data.StringifyHex()); RaisePluginCalled("ProcessEvents(" + events.Length + ")"); return true; }
/// <inheritdoc /> public bool OpenFileSelector(Jacobi.Vst.Core.VstFileSelect fileSelect) { switch (fileSelect.Command) { case VstFileSelectCommand.DirectorySelect: { if (!string.IsNullOrEmpty(fileSelect.InitialPath) && System.IO.Directory.Exists(fileSelect.InitialPath)) fbd.SelectedPath = fileSelect.InitialPath; if (!string.IsNullOrEmpty(fileSelect.Title)) fbd.Description = fileSelect.Title; if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) fileSelect.ReturnPaths = new string[]{ fbd.SelectedPath }; } break; case VstFileSelectCommand.FileLoad: { if (!string.IsNullOrEmpty(fileSelect.InitialPath) && System.IO.Directory.Exists(fileSelect.InitialPath)) ofd.InitialDirectory = fileSelect.InitialPath; if (!string.IsNullOrEmpty(fileSelect.Title)) ofd.Title = fileSelect.Title; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) fileSelect.ReturnPaths = new string[]{ ofd.FileName }; } break; case VstFileSelectCommand.FileSave: { if (!string.IsNullOrEmpty(fileSelect.InitialPath) && System.IO.Directory.Exists(fileSelect.InitialPath)) sfd.InitialDirectory = fileSelect.InitialPath; if (!string.IsNullOrEmpty(fileSelect.Title)) sfd.Title = fileSelect.Title; if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK) fileSelect.ReturnPaths = new string[]{ sfd.FileName }; } break; case VstFileSelectCommand.MultipleFilesLoad: { if (!string.IsNullOrEmpty(fileSelect.InitialPath) && System.IO.Directory.Exists(fileSelect.InitialPath)) sfd.InitialDirectory = fileSelect.InitialPath; if (!string.IsNullOrEmpty(fileSelect.Title)) sfd.Title = fileSelect.Title; if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) fileSelect.ReturnPaths = ofd.SafeFileNames; } break; } RaisePluginCalled("OpenFileSelector(" + fileSelect.Command + ")"); return false; }
private static void jacobi_test01() //****************************************************************************80 // // Purpose: // // JACOBI_TEST01 tests JACOBI1. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 24 June 2011 // // Author: // // John Burkardt // { List <string> command = new(); List <string> data = new(); int i; int it; int j; const double w = 0.5; Console.WriteLine(""); Console.WriteLine("JACOBI_TEST01:"); const int it_num = 2000; const int n = 33; // // Set the matrix A. // double[] a = Matrix.dif2(n, n); // // Determine the right hand side vector B. // double[] x_exact = new double[n]; for (i = 0; i < n; i++) { double t = i / (double)(n - 1); x_exact[i] = Math.Exp(t) * (t - 1) * t; // x_exact[i] = ( double ) ( i + 1 ); } double[] b = typeMethods.r8mat_mv_new(n, n, a, x_exact); // // Set the initial estimate for the solution. // double[] x = new double[n]; for (i = 0; i < n; i++) { x[i] = 0.0; } // // Allocate plot arrays. // double[] m_plot = new double[it_num + 1]; double[] r_plot = new double[it_num + 1]; double[] s_plot = new double[it_num + 1]; double[] x_plot = new double[n * (it_num + 1)]; // // Initialize plot arrays. // r_plot[0] = typeMethods.r8mat_residual_norm(n, n, a, x, b); m_plot[0] = 1.0; for (i = 0; i < n; i++) { x_plot[i + 0 * n] = x[i]; } for (j = 0; j <= it_num; j++) { s_plot[j] = j; } // // Carry out the iteration. // for (it = 1; it <= it_num; it++) { double[] x_new = Jacobi.jacobi1(n, a, b, x); r_plot[it] = typeMethods.r8mat_residual_norm(n, n, a, x_new, b); // // Compute the average point motion. // m_plot[it] = typeMethods.r8vec_diff_norm_squared(n, x, x_new) / n; // // Update the solution // for (i = 0; i < n; i++) { x[i] = (1.0 - w) * x[i] + w * x_new[i]; } // r8vec_copy ( n, x_new, x ); for (i = 0; i < n; i++) { x_plot[i + 0 * n] = x[i]; } } typeMethods.r8vec_print(n, x, "Solution"); // // Plot the residual. // double[] rl_plot = new double[it_num + 1]; for (j = 0; j <= it_num; j++) { rl_plot[j] = Math.Log(r_plot[j]); } // // Create the data file. // string data_filename = "residual_data.txt"; for (j = 0; j <= it_num; j++) { data.Add(j + " " + rl_plot[j] + ""); } File.WriteAllLines(data_filename, data); Console.WriteLine(" "); Console.WriteLine(" Data stored in \"" + data_filename + "\"."); // // Create the command file. // string command_filename = "residual_commands.txt"; command.Add("# residual_commands.txt"); command.Add("#"); command.Add("# Usage:"); command.Add("# gnuplot < residual_commands.txt"); command.Add("#"); command.Add("set term png"); command.Add("set output 'residual.png'"); command.Add("set style data lines"); command.Add("set xlabel 'Iteration'"); command.Add("set ylabel 'Residual'"); command.Add("set title 'Log(Residual) over Iterations'"); command.Add("set grid"); command.Add("plot 'residual_data.txt' using 1:2 lw 2"); command.Add("quit"); File.WriteAllLines(command_filename, command); Console.WriteLine(" Plot commands stored in \"" + command_filename + "\"."); // // Plot the average point motion. // double[] ml_plot = new double[it_num + 1]; for (j = 0; j <= it_num; j++) { ml_plot[j] = Math.Log(m_plot[j]); } // // Create the data file. // data_filename = "motion_data.txt"; data.Clear(); for (j = 0; j <= it_num; j++) { data.Add(j + " " + ml_plot[j] + ""); } File.WriteAllLines(data_filename, data); Console.WriteLine(" "); Console.WriteLine(" Data stored in \"" + data_filename + "\"."); // // Create the command file. // command_filename = "motion_commands.txt"; command.Clear(); command.Add("# motion_commands.txt"); command.Add("#"); command.Add("# Usage:"); command.Add("# gnuplot < motion_commands.txt"); command.Add("#"); command.Add("set term png"); command.Add("set output 'motion.png'"); command.Add("set style data lines"); command.Add("set xlabel 'Iteration'"); command.Add("set ylabel 'Motion'"); command.Add("set title 'Log(Motion) over Iterations'"); command.Add("set grid"); command.Add("plot 'motion_data.txt' using 1:2 lw 2"); command.Add("quit"); File.WriteAllLines(command_filename, command); // // Plot the evolution of the locations of the generators. // //figure ( 3 ) //y = ( 0 : it_num ); //for k = 1 : n // plot ( x_plot(k,1:it_num+1), y ) // hold on; //end //grid on //hold off; //title ( "Generator evolution." ); //xlabel ( "Generator positions" ); //ylabel ( "Iterations" ); }
public void OpenPlugin(string pluginPath, Jacobi.Vst.Core.Host.IVstHostCommandStub hostCmdStub) { try { //HostCommandStub hostCmdStub = new HostCommandStub(); //hostCmdStub.PluginCalled += new EventHandler<PluginCalledEventArgs>(HostCmdStub_PluginCalled); VstPluginContext ctx = VstPluginContext.Create(pluginPath, hostCmdStub); // add custom data to the context ctx.Set("PluginPath", pluginPath); ctx.Set("HostCmdStub", hostCmdStub); // actually open the plugin itself ctx.PluginCommandStub.Open(); //doPluginOpen(); PluginContext = ctx; } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.ToString()); } }
private void GaussJacobiMethod_click(object sender, RoutedEventArgs e) { GaussSeidal_class.MethodName = "GaussJacobi"; Jacobi.Begin(); this.Frame.Navigate(typeof(GaussSeidal)); }
public static void moment_method(int n, double[] moment, ref double[] x, ref double[] w) //****************************************************************************80 // // Purpose: // // MOMENT_METHOD computes a quadrature rule by the method of moments. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 18 September 2013 // // Author: // // John Burkardt // // Reference: // // Gene Golub, John Welsch, // Calculation of Gaussian Quadrature Rules, // Mathematics of Computation, // Volume 23, Number 106, April 1969, pages 221-230. // // Parameters: // // Input, int N, the order of the quadrature rule. // // Input, double MOMENT[2*N+1], moments 0 through 2*N. // // Output, double X[N], W[N], the points and weights of the quadrature rule. // { int flag = 0; int i; int it_num = 0; int j; int rot_num = 0; const bool debug = false; switch (debug) { case true: typeMethods.r8vec_print(2 * n + 1, moment, " Moments:"); break; } // // Define the N+1 by N+1 Hankel matrix H(I,J) = moment(I+J). // double[] h = new double[(n + 1) * (n + 1)]; for (i = 0; i <= n; i++) { for (j = 0; j <= n; j++) { h[i + j * (n + 1)] = moment[i + j]; } } switch (debug) { case true: typeMethods.r8mat_print(n + 1, n + 1, h, " Hankel matrix:"); break; } // // Compute R, the upper triangular Cholesky factor of H. // double[] r = typeMethods.r8mat_cholesky_factor_upper(n + 1, h, ref flag); if (flag != 0) { Console.WriteLine(""); Console.WriteLine("MOMENT_METHOD - Fatal error!"); Console.WriteLine(" R8MAT_CHOLESKY_FACTOR_UPPER returned FLAG = " + flag + ""); return; } switch (debug) { case true: typeMethods.r8mat_print(n + 1, n + 1, r, " Cholesky factor:"); break; } // // Compute ALPHA and BETA from R, using Golub and Welsch's formula. // double[] alpha = new double[n]; alpha[0] = r[0 + 1 * (n + 1)] / r[0 + 0 * (n + 1)]; for (i = 1; i < n; i++) { alpha[i] = r[i + (i + 1) * (n + 1)] / r[i + i * (n + 1)] - r[i - 1 + i * (n + 1)] / r[i - 1 + (i - 1) * (n + 1)]; } double[] beta = new double[n - 1]; for (i = 0; i < n - 1; i++) { beta[i] = r[i + 1 + (i + 1) * (n + 1)] / r[i + i * (n + 1)]; } // // Compute the points and weights from the moments. // double[] jacobi = new double[n * n]; for (j = 0; j < n; j++) { for (i = 0; i < n; i++) { jacobi[i + j * n] = 0.0; } } for (i = 0; i < n; i++) { jacobi[i + i * n] = alpha[i]; } for (i = 0; i < n - 1; i++) { jacobi[i + (i + 1) * n] = beta[i]; jacobi[i + 1 + i * n] = beta[i]; } switch (debug) { case true: typeMethods.r8mat_print(n, n, jacobi, " The Jacobi matrix:"); break; } // // Get the eigendecomposition of the Jacobi matrix. // const int it_max = 100; double[] v = new double[n * n]; Jacobi.jacobi_eigenvalue(n, jacobi, it_max, ref v, ref x, ref it_num, ref rot_num); switch (debug) { case true: typeMethods.r8mat_print(n, n, v, " Eigenvector"); break; } for (i = 0; i < n; i++) { w[i] = moment[0] * Math.Pow(v[0 + i * n], 2); } }
public bool ProcessEvents(Jacobi.Vst.Core.VstEvent[] events) { //RaisePluginCalled("ProcessEvents(" + events.Length + ")"); if(FProcessEventsAction != null) FProcessEventsAction(events); return false; }
/// <inheritdoc /> public Jacobi.Vst.Core.VstTimeInfo GetTimeInfo(Jacobi.Vst.Core.VstTimeInfoFlags filterFlags) { RaisePluginCalled("GetTimeInfo(" + filterFlags + ")"); vstTimeInfo.SamplePosition = 0.0; vstTimeInfo.SampleRate = 44100; vstTimeInfo.NanoSeconds = 0.0; vstTimeInfo.PpqPosition = 0.0; vstTimeInfo.Tempo = 120.0; vstTimeInfo.BarStartPosition = 0.0; vstTimeInfo.CycleStartPosition = 0.0; vstTimeInfo.CycleEndPosition = 0.0; vstTimeInfo.TimeSignatureNumerator = 4; vstTimeInfo.TimeSignatureDenominator = 4; vstTimeInfo.SmpteOffset = 0; vstTimeInfo.SmpteFrameRate = new Jacobi.Vst.Core.VstSmpteFrameRate(); vstTimeInfo.SamplesToNearestClock = 0; vstTimeInfo.Flags = 0; return vstTimeInfo; }
/// <inheritdoc /> public bool ProcessEvents(Jacobi.Vst.Core.VstEvent[] events) { RaisePluginCalled("ProcessEvents(" + events.Length + ")"); return false; }
/// <inheritdoc /> public bool CloseFileSelector(Jacobi.Vst.Core.VstFileSelect fileSelect) { RaisePluginCalled("CloseFileSelector(" + fileSelect.Command + ")"); return false; }
public static double[] ortho2eva0(int mmax, double[] z) //****************************************************************************80 // // Purpose: // // ORTHO2EVA0 evaluates the orthonormal polynomials on the triangle. // // Licensing: // // This code is distributed under the GNU GPL license. // // Modified: // // 30 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 MMAX, the maximum order to which the polynomials are // to be evaluated. // // Input, double Z[2], the coordinates of the evaluation point. // // Output, double ORTHO2EVA0[(mmax+1)*(mmax+2)/2], the orthogonal // polynomials evaluated at the point Z. // { int m; int npols = (mmax + 1) * (mmax + 2) / 2; double[] pols = new double[npols]; const double zero = 0.0; double sqrt3 = Math.Sqrt(3.0); const double r11 = -1.0 / 3.0; double r12 = -1.0 / sqrt3; const double r21 = -1.0 / 3.0; double r22 = 2.0 / sqrt3; double a = z[0]; double b = z[1]; // // Map the reference triangle to the right // triangle with the vertices (-1,-1), (1,-1), (-1,1) // double x = r11 + r12 * b + a; double y = r21 + r22 * b; // // Evaluate the Koornwinder's polynomials via the three term recursion. // double par1 = (2.0 * x + 1.0 + y) / 2.0; double par2 = (1.0 - y) / 2.0; double[] f1 = LegendreScaled.klegeypols(par1, par2, mmax); double[] f2 = new double[(mmax + 1) * (mmax + 1)]; for (m = 0; m <= mmax; m++) { par1 = 2 * m + 1; Jacobi.kjacopols(y, par1, zero, mmax - m, ref f2, polsIndex: +m * (mmax + 1)); } int kk = 0; for (m = 0; m <= mmax; m++) { int n; for (n = 0; n <= m; n++) { // // Evaluate the polynomial (m-n, n) // pols[kk] = f1[m - n] * f2[n + (m - n) * (mmax + 1)]; // // Normalize. // double scale = Math.Sqrt ((1 + (m - n) + n) * (1 + (m - n) + (m - n)) / sqrt3 ); pols[kk] *= scale; kk += 1; } } return(pols); }