c sharp,c++ and python problem
Tester1.cs
using System; using System.Collections.Generic; using System.Collections; namespace TriDiagonalMatrix { public class Tester { public static void Main(String [] args) { const int N = 10; TriDiagonalMatrix m1 = new TriDiagonalMatrix(N); TriDiagonalMatrix m2 = new TriDiagonalMatrix(N); int x = 1; for (int row = 0; row < N; row++) { for (int col = 0; col < N; col++) { if (Math.Abs(row-col) <= 1) { m1.set(row, col, 1); m2.set(row, col, x); x++; } } } Console.WriteLine("m1:\n" + m1.CompactPrint()); Console.WriteLine("m2:\n" + m2.CompactPrint()); TriDiagonalMatrix m3 = m1 + m2; Console.WriteLine("m3:\n" + m3.CompactPrint()); } } }
Tester10.cs
using System; using System.Collections.Generic; using System.Collections; namespace TriDiagonalMatrix { public class Tester { public static void Main(String [] args) { try { TriDiagonalMatrix m = new TriDiagonalMatrix(6); Console.WriteLine(m.get(-2, 5)); } catch (ArgumentException e) { Console.WriteLine(e); } } } }
Tester11.cs
using System; using System.Collections.Generic; using System.Collections; namespace TriDiagonalMatrix { public class Tester { public static void Main(String [] args) { try { TriDiagonalMatrix m = new TriDiagonalMatrix(6); Console.WriteLine(m.get(2, -3)); } catch (ArgumentException e) { Console.WriteLine(e); } } } }
Tester12.cs
using System; using System.Collections.Generic; using System.Collections; namespace TriDiagonalMatrix { public class Tester { public static void Main(String [] args) { try { TriDiagonalMatrix m = new TriDiagonalMatrix(6); Console.WriteLine(m.get(8, 3)); } catch (ArgumentException e) { Console.WriteLine(e); } } } }
Tester13.cs
using System; using System.Collections.Generic; using System.Collections; namespace TriDiagonalMatrix { public class Tester { public static void Main(String [] args) { try { TriDiagonalMatrix m = new TriDiagonalMatrix(6); Console.WriteLine(m.get(2, 6)); } catch (ArgumentException e) { Console.WriteLine(e); } } } }
Tester2.cs
using System; using System.Collections.Generic; using System.Collections; namespace TriDiagonalMatrix { public class Tester { public static void Main(String [] args) { const int N = 10; TriDiagonalMatrix m1 = new TriDiagonalMatrix(N); TriDiagonalMatrix m2 = new TriDiagonalMatrix(N); int x = 1; for (int row = 0; row < N; row++) { for (int col = 0; col < N; col++) { if (Math.Abs(row-col) <= 1) { m1.set(row, col, 1); m2.set(row, col, x); x++; } } } TriDiagonalMatrix m3 = m1 + m2; Console.WriteLine("m1:"); foreach (int v in m1) { Console.Write(v + " "); } Console.WriteLine(); Console.WriteLine("m2:"); foreach (int v in m2) { Console.Write(v + " "); } Console.WriteLine(); Console.WriteLine("m3:"); foreach (int v in m3) { Console.Write(v + " "); } Console.WriteLine(); Console.WriteLine("m3:"); TriDiagonalMatrixEnumerator ie = m3.GetEnumerator(); while (ie.MoveNext()) { Console.Write(ie.Current + " "); } Console.WriteLine(); } } }
Tester3.cs
using System; using System.Collections.Generic; using System.Collections; namespace TriDiagonalMatrix { public class Tester { public static void Main(String [] args) { try { TriDiagonalMatrix m = new TriDiagonalMatrix(-2); m.CompactPrint(); } catch (ArgumentException e) { Console.WriteLine(e); } } } }
Tester4.cs
using System; using System.Collections.Generic; using System.Collections; namespace TriDiagonalMatrix { public class Tester { public static void Main(String [] args) { try { TriDiagonalMatrix m1 = new TriDiagonalMatrix(2); TriDiagonalMatrix m2 = new TriDiagonalMatrix(3); TriDiagonalMatrix m3 = m1 + m2; m3.CompactPrint(); } catch (ArgumentException e) { Console.WriteLine(e); } } } }
Tester5.cs
using System; using System.Collections.Generic; using System.Collections; namespace TriDiagonalMatrix { public class Tester { public static void Main(String [] args) { try { TriDiagonalMatrix m = new TriDiagonalMatrix(6); m.set(-2, 4, 3); m.CompactPrint(); } catch (ArgumentException e) { Console.WriteLine(e); } } } }
Tester6.cs
using System; using System.Collections.Generic; using System.Collections; namespace TriDiagonalMatrix { public class Tester { public static void Main(String [] args) { try { TriDiagonalMatrix m = new TriDiagonalMatrix(6); m.set(2, -4, 3); m.CompactPrint(); } catch (ArgumentException e) { Console.WriteLine(e); } } } }
Tester7.cs
using System; using System.Collections.Generic; using System.Collections; namespace TriDiagonalMatrix { public class Tester { public static void Main(String [] args) { try { TriDiagonalMatrix m = new TriDiagonalMatrix(6); m.set(6, 4, 3); m.CompactPrint(); } catch (ArgumentException e) { Console.WriteLine(e); } } } }
Tester8.cs
using System; using System.Collections.Generic; using System.Collections; namespace TriDiagonalMatrix { public class Tester { public static void Main(String [] args) { try { TriDiagonalMatrix m = new TriDiagonalMatrix(6); m.set(2, 7, 3); m.CompactPrint(); } catch (ArgumentException e) { Console.WriteLine(e); } } } }
Tester9.cs
using System; using System.Collections.Generic; using System.Collections; namespace TriDiagonalMatrix { public class Tester { public static void Main(String [] args) { try { TriDiagonalMatrix m = new TriDiagonalMatrix(6); m.set(2, 0, 3); m.CompactPrint(); } catch (ArgumentException e) { Console.WriteLine(e); } } } }
TesterGrad.cs
using System; using System.Collections.Generic; using System.Collections; namespace TriDiagonalMatrix { public class Tester { public static void Main(String [] args) { int N = 31; TriDiagonalMatrix m = new TriDiagonalMatrix(N); float [] b = new float[N]; for (int row = 0; row < N; row++) { for (int col = 0; col < N; col++) { int diff = Math.Abs(row-col); if (diff == 0) { m.set(row, col, 2); } else if (diff == 1) { m.set(row, col, 1); } } b[row] = (float) 16.0 - (float) Math.Abs((float) (row+1) - (float)16.0); } try { Solver s = new Solver(m, b); float [] x = s.Solve(); Console.Write("x: "); for (int i = 0; i < N; i++) { Console.Write((int)Math.Round(x[i], 0) + " "); } Console.WriteLine(); } catch (ArgumentException e) { Console.WriteLine(e); } } } }