Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. package grafikag;
  2.  
  3. import Jama.Matrix;
  4. import ptolemy.plot.Plot;
  5. import ptolemy.plot.PlotApplication;
  6.  
  7. public class Main {
  8.  
  9. public static void mygraph(double[][] points) {
  10. Plot myPlot = new Plot();
  11. myPlot.setTitle("Plot example");
  12. myPlot.setXLabel("x");
  13. myPlot.setYLabel("s(x)");
  14. int dl = points.length;
  15. myPlot.setMarksStyle("dots", 0);
  16. //myPlot.setImpulses(true, 0);
  17. //for(int i=0; i<ticks.length; i++) myPlot.addXTick("",ticks[i][0]);
  18. for (int i = 0; i < dl; i++) myPlot.addPoint(0, points[i][0], points[i][1], false);
  19. PlotApplication app = new PlotApplication(myPlot);
  20. app.setSize(800, 400);
  21. app.setLocation(100, 100);
  22. app.setTitle("MyPicture");
  23. }
  24.  
  25. public static void main(String[] args) {
  26. int i = 3, j = 3;
  27. Matrix A = Matrix.random(i, j);
  28. Matrix B = Matrix.random(j, 1);
  29.  
  30. Matrix D = new Matrix(i, j);
  31. Matrix R = new Matrix(i, j);
  32. Matrix I = Matrix.identity(i, j);
  33. Matrix x = new Matrix(i, 1);
  34. Matrix x1 = new Matrix(i, 1);
  35.  
  36. for (int k = 0; k < i; k++) {
  37. for (int w = 0; w < j; w++) {
  38. if (k == w) {
  39. D.set(k, w, A.get(k, w));
  40. R.set(k, w, 0);
  41. } else {
  42. R.set(k, w, A.get(k, w));
  43. D.set(k, w, 0);
  44. }
  45. }
  46. }
  47.  
  48. for (int k = 0; k < i; k++) {
  49. for (int w = 0; w < j; w++) {
  50. if (k == w) {
  51. D.set(k, w, 1 / D.get(k, w));
  52. }
  53. }
  54. }
  55.  
  56. double norm = I.minus(D.times(A)).normInf();
  57. double norm1 = I.minus(D.times(A)).norm1();
  58.  
  59. if (norm < 1 && norm1 < 1) {
  60. System.out.println("Macierz silnie dominujaca");
  61. System.out.println("normInf: " + norm);
  62. System.out.println("norm1: " + norm1);
  63.  
  64. } else {
  65. System.out.println("Macierz nie jest scisle dominujaca");
  66. }
  67.  
  68. for (int r = 0; r < 100; r++) {
  69. if (norm1 > 1 || norm > 1) {
  70. break;
  71. }
  72. if (x1.minus(x).normF() > 0.000001) {
  73. x1 = (I.minus(D.times(A))).times(x).plus(D.times(B));
  74. x = x1;
  75. break;
  76. }
  77. }
  78.  
  79. System.out.println("normInf: " + norm);
  80. System.out.println("norm1: " + norm1);
  81. A.print(i, j);
  82. B.print(i, j);
  83. D.print(i, j);
  84. R.print(i, j);
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement