private void Helper2(IElementalAccessMatrix A, IElementalAccessVector b, IElementalAccessVector x, ILinearSolver solver, IPreconditioner M, ILinearIteration iter) { Random r = new Random(); double K = r.NextDouble(), f = r.NextDouble(), gl = r.NextDouble(), gr = r.NextDouble(); //assemble(A, b, K, f); //boundary(A, b, x, gl, gr); A.SetValue(0, 0, 1); A.SetValue(0, 1, 1); A.SetValue(0, 2, 1.3); A.SetValue(1, 0, -0.5); A.SetValue(1, 1, -0.25); A.SetValue(1, 2, -1.25); A.SetValue(2, 0, 2.5); A.SetValue(2, 1, 3.25); A.SetValue(2, 2, -1.25); b.SetValue(0, 1.25); b.SetValue(1, 3.75); b.SetValue(1, -2.35); double[] ans = solve(A, b, x, solver, M, iter); //double[] ref_Renamed = reference(b.Length - 1, K, f, gl, gr); //checkEqual(ans, ref_Renamed); Console.WriteLine("!: " + solver + " " + M + " " + iter + " " + x.GetValue(0) + " " + x.GetValue(1) + " " + x.GetValue(2)); Blas.Default.Zero(A); Blas.Default.Zero(b); Blas.Default.Zero(x); }
public static void model11(IElementalAccessVector y, IElementalAccessVector x) { //y er residualer, mens x er endogene //for (int i = 0; i < WindowsApplication1.Program.varsBigEndoNoLag.Count; i++) //{ //} y.SetValue(0, x.GetValue(0) - x.GetValue(3) * x.GetValue(3) - 1); y.SetValue(1, x.GetValue(1) + x.GetValue(2) - 1); y.SetValue(2, x.GetValue(0) + x.GetValue(1) + 2); y.SetValue(3, x.GetValue(4) * x.GetValue(3) - 1); y.SetValue(4, x.GetValue(3) + 2 - x.GetValue(0)); }
private void model(IElementalAccessVector y, IElementalAccessVector x) { y.SetValue(0, x.GetValue(0) - x.GetValue(1) - 1); y.SetValue(1, 3 * x.GetValue(0) - 2 * x.GetValue(1) + 1); y.SetValue(2, -2 * x.GetValue(2) * x.GetValue(2) - 1 * x.GetValue(1) + 2); y.SetValue(0, x.GetValue(0) - x.GetValue(3) * x.GetValue(3) - 1); y.SetValue(1, x.GetValue(1) + x.GetValue(2) - 1); y.SetValue(2, x.GetValue(0) + x.GetValue(1) + 2); y.SetValue(3, x.GetValue(4) * x.GetValue(3) - 1); y.SetValue(4, x.GetValue(3) + 2 - x.GetValue(0)); }
/// <summary> Each entry of q is populated from a uniform distribution. The vector will /// have a 2-norm of 1.</summary> protected internal virtual IVector Random(IVector q) { if (!(q is IElementalAccessVector)) { throw new NotSupportedException(); } IElementalAccessVector qe = (IElementalAccessVector)q; for (int i = 0; i < qe.Length; ++i) { qe.SetValue(i, SupportClass.Random.NextDouble()); } return(Blas.Default.Scale(1.0 / Blas.Default.Norm(q, NORMS.NORM2), q)); }
/// <summary> Assembly using set</summary> /// <returns> Dense representation (not a direct copy) /// </returns> public static double[] setAssembleVector(IElementalAccessVector x) { int n = x.Length; double[] data = new double[n]; System.Random r = new System.Random(); for (int i = 0; i < n; ++i) { double entry = r.NextDouble(); data[i] = entry; x.SetValue(i, entry); } return(data); }
/// <summary> Assembly using setValue</summary> /// <param name="nu">Maximum number of entries /// </param> /// <returns> Dense representation (not a direct copy) /// </returns> public static double[] setAssembleVector(IElementalAccessVector x, int nu) { int n = x.Length; double[] data = new double[n]; System.Random r = new System.Random(); for (int i = 0; i < nu; ++i) { int ind = TesterUtilities.getInt(n, r); double entry = r.NextDouble(); data[ind] = entry; x.SetValue(ind, entry); } return(data); }