Java Program to Implement Sparse Matrix Operations

In the sub field of numerical analysis, a sparse matrix is a matrix populated primarily with zeros as elements of the table. By contrast, if a larger number of elements differ from zero, then it is common to refer to the matrix as a dense matrix. The fraction of zero elements (non-zero elements) in a matrix is called the sparsity (density). Include methods to store a sparse matrix, display a matrix, perform operations such as OR, AND on two sparse matrices and store the results and print .

Matrix 1

1 0 0 
0 1 0 
1 0 0 

(1,1), (2,1), (3,1) //input

Matrix 2

1 0 0 
0 1 1 
0 0 1 

(1,1), (2,2), (2,3), (3,3)//input

Matrix 1 AND Matrix 2

1 0 0 
0 1 0 
0 0 0 


Sparse Matrix Operations

When you run the program, the output will be:

Enter the Matrix Size Row ,Column : 
Like Row,Column : 4,2
Get Matrix A,B
Stop entering type End command 
Get Matrix A
Enter Address Like Row, Column
0,0
1,1
2,2
Entering address not inside the matrix !!!! 
1,3
Entering address not inside the matrix !!!! 
0,4
Entering address not inside the matrix !!!! 
End
Get Matrix B
Enter Address Like Row,Column 
1,1
0,0
1,2
Entering address not inside the matrix !!!! 
End
Select Perform Operations
Such as
1. OR
2. AND
Type the Number
1
Print Matrix A
1    0    
0    1    
0    0    
0    0    
Print Matrix B
1    0    
0    1    
0    0    
0    0    
Output Matrix C
1    0    
0    1    
0    0    
0    0    

Post a Comment

Thank you for vising

Previous Post Next Post