This Java program approximates the integral of the function ( \frac{1}{\sqrt{2\pi}} e^{-x^2/2} ) over the interval ([-1, 1]) using the composite Simpson's 1/3 rule. The program is multithreaded and allows the user to specify the number of threads to use for computation.
- Java Development Kit (JDK) installed on your system.
- A terminal or command prompt to compile and run the program.
-
Save the Program:
- Save the program in a file named
SimpsonIntegration.java.
- Save the program in a file named
-
Compile the Program:
- Open a terminal or command prompt and navigate to the directory where the program is saved.
- Compile the program using the following command:
javac SimpsonIntegration.java
-
Run the Program:
- Run the program by specifying the number of threads as a command-line argument. For example, to use 8 threads:
java SimpsonIntegration 8
- Run the program by specifying the number of threads as a command-line argument. For example, to use 8 threads:
- The program requires one command-line argument:
<number_of_threads>: The number of threads to use for computation (e.g., 4, 8, 16).
- The program will output the approximate value of the integral computed using the specified number of threads and the time taken to do so.
javac SimpsonIntegration.java
java SimpsonIntegration 8Output:
Integral value: 0.6826894921370761
Execution time: 50.3498 milliseconds
- The program uses the composite Simpson's 1/3 rule for numerical integration.
- The number of points used for integration is fixed at ( 10^6 ).
- The program demonstrates how multithreading can be used to parallelize numerical computations.
This Java program performs matrix multiplication ( C = A \times B ) for two square matrices ( A ) and ( B ) of size ( 1000 \times 1000 ). The matrices are initialized with random values between 0 and 10. The program is multithreaded and allows the user to specify the number of threads to use for computation.
- Java Development Kit (JDK) installed on your system.
- A terminal or command prompt to compile and run the program.
-
Save the Program:
- Save the program in a file named
MatrixMultiplication.java.
- Save the program in a file named
-
Compile the Program:
- Open a terminal or command prompt and navigate to the directory where the program is saved.
- Compile the program using the following command:
javac MatrixMultiplication.java
-
Run the Program:
- Run the program by specifying the number of threads as a command-line argument. For example, to use 8 threads:
java MatrixMultiplication 8
- Run the program by specifying the number of threads as a command-line argument. For example, to use 8 threads:
- The program requires one command-line argument:
<number_of_threads>: The number of threads to use for computation (e.g., 8, 10, 50, 100, 500).
- The program will print the time of execution of code.
javac MatrixMultiplication.java
java MatrixMultiplication 8Output:
Matrix multiplication completed.
Execution time: 844.9204 milliseconds
- The program demonstrates how multithreading can be used to parallelize matrix multiplication.
- The matrices are initialized with random values between 0 and 10.
- Only the first ( 10 \times 10 ) portion of the matrices is printed to avoid overwhelming the console with output.