Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- class Modified4Vectors
- {
- static BufferedReader keyboard = new
- BufferedReader (new InputStreamReader(System.in));
- static PrintWriter screen = new PrintWriter( System.out, true);
- //Absolute Momentum class
- private static double getMom(double px, double py, double pz)
- {
- double Mom;
- Mom = Math.sqrt((px*px)+(py*py)+(pz*pz));
- return Mom;
- }
- //Invariant Mass class
- private static double getInv(double energy, double momentum)
- {
- double Inv;
- Inv = Math.sqrt((energy*energy)-(momentum*momentum));
- return Inv;
- }
- //Add vectors
- private static double[] getInv(double e1, double p1, double p2, double p3, double e2, double p4, double p5, double p6)
- {
- double [] thirdvector = new double[4];
- thirdvector[0] = e1 + e2;
- thirdvector[1] = p1 + p4;
- thirdvector[2] = p2 + p5;
- thirdvector[3] = p3 + p6;
- return thirdvector[];
- }
- //Main method
- public static void main (String [] args) throws IOException
- {
- int compMax = 4;
- double [] particle1 = new double[compMax];
- double [] particle2 = new double[compMax];
- double mom1;
- double mom2;
- double inv1;
- double inv2;
- double [] particle3 = new double[compMax];
- //4Vector 1 loop
- for (int p1n = 0; p1n < compMax; p1n++)
- {
- screen.println("Please enter component " + (p1n+1) + " of the first four vector.");
- particle1[p1n] = new Double(keyboard.readLine()).doubleValue();
- }
- //4Vector 2 loop
- for (int p2n = 0; p2n < compMax; p2n++)
- {
- screen.println("Please enter component " + (p2n+1) + " of the first four vector.");
- particle2[p2n] = new Double(keyboard.readLine()).doubleValue();
- }
- mom1 = getMom(particle1[1],particle1[2],particle1[3]);
- screen.println("The absolute momentum of the first vector is " + mom1);
- mom2 = getMom(particle2[1],particle2[2],particle2[3]);
- screen.println("The absolute momentum of the second vector is " + mom2);
- inv1 = getInv(particle1[0],mom1);
- screen.println("The invariant mass related to the first vector is " + inv1);
- inv2 = getInv(particle2[0],mom2);
- screen.println("The invariant mass related to the second vector is " + inv1);
- particle3 = getInv(particle1[0],particle1[1],particle1[2],particle1[3],particle2[0],particle2[1],particle2[2],particle2[3]);
- for( int n = 0; n < 4; n++)
- {
- screen.println( n + " location, value stored = " + particle3[n] );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement