Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. import java.io.*;
  2. class Modified4Vectors
  3. {
  4. static BufferedReader keyboard = new
  5. BufferedReader (new InputStreamReader(System.in));
  6. static PrintWriter screen = new PrintWriter( System.out, true);
  7.  
  8. //Absolute Momentum class
  9. private static double getMom(double px, double py, double pz)
  10. {
  11. double Mom;
  12. Mom = Math.sqrt((px*px)+(py*py)+(pz*pz));
  13. return Mom;
  14. }
  15.  
  16. //Invariant Mass class
  17. private static double getInv(double energy, double momentum)
  18. {
  19. double Inv;
  20. Inv = Math.sqrt((energy*energy)-(momentum*momentum));
  21. return Inv;
  22. }
  23.  
  24. //Add vectors
  25. private static double[] getInv(double e1, double p1, double p2, double p3, double e2, double p4, double p5, double p6)
  26. {
  27. double [] thirdvector = new double[4];
  28. thirdvector[0] = e1 + e2;
  29. thirdvector[1] = p1 + p4;
  30. thirdvector[2] = p2 + p5;
  31. thirdvector[3] = p3 + p6;
  32.  
  33. return thirdvector[];
  34. }
  35. //Main method
  36. public static void main (String [] args) throws IOException
  37.  
  38. {
  39. int compMax = 4;
  40.  
  41. double [] particle1 = new double[compMax];
  42. double [] particle2 = new double[compMax];
  43. double mom1;
  44. double mom2;
  45. double inv1;
  46. double inv2;
  47. double [] particle3 = new double[compMax];
  48.  
  49. //4Vector 1 loop
  50. for (int p1n = 0; p1n < compMax; p1n++)
  51. {
  52. screen.println("Please enter component " + (p1n+1) + " of the first four vector.");
  53. particle1[p1n] = new Double(keyboard.readLine()).doubleValue();
  54.  
  55. }
  56.  
  57. //4Vector 2 loop
  58. for (int p2n = 0; p2n < compMax; p2n++)
  59. {
  60. screen.println("Please enter component " + (p2n+1) + " of the first four vector.");
  61. particle2[p2n] = new Double(keyboard.readLine()).doubleValue();
  62.  
  63. }
  64.  
  65. mom1 = getMom(particle1[1],particle1[2],particle1[3]);
  66. screen.println("The absolute momentum of the first vector is " + mom1);
  67. mom2 = getMom(particle2[1],particle2[2],particle2[3]);
  68. screen.println("The absolute momentum of the second vector is " + mom2);
  69.  
  70. inv1 = getInv(particle1[0],mom1);
  71. screen.println("The invariant mass related to the first vector is " + inv1);
  72. inv2 = getInv(particle2[0],mom2);
  73. screen.println("The invariant mass related to the second vector is " + inv1);
  74.  
  75. particle3 = getInv(particle1[0],particle1[1],particle1[2],particle1[3],particle2[0],particle2[1],particle2[2],particle2[3]);
  76. for( int n = 0; n < 4; n++)
  77. {
  78. screen.println( n + " location, value stored = " + particle3[n] );
  79.  
  80. }
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement