কম্পিউটার

জাভা প্রোগ্রাম একটি প্রদত্ত ম্যাট্রিক্সের ট্রেস এবং সাধারণ খুঁজে বের করতে


এই নিবন্ধে, আমরা বুঝতে পারব কিভাবে একটি প্রদত্ত ম্যাট্রিক্সের ট্রেস এবং স্বাভাবিক খুঁজে বের করতে হয়। একটি ম্যাট্রিক্সের স্বাভাবিক হল একটি ম্যাট্রিক্সের সমস্ত উপাদানের বর্গের সমষ্টির বর্গমূল। একটি ম্যাট্রিক্সের ট্রেস হল প্রধান তির্যক (উপরের বাম থেকে নীচের ডানদিকে) উপস্থিত সমস্ত উপাদানের সমষ্টি।

নীচে একই -

এর একটি প্রদর্শন রয়েছে৷

ধরুন আমাদের ইনপুট হল

The matrix is defined as:
2 3 4
5 2 3
4 6 9

কাঙ্খিত আউটপুট হবে

Trace value: 13.0
Normal value: 14.142135623730951

অ্যালগরিদম

Step 1 - START
Step 2 - Declare an integer matrix namely input_matrix
Step 3 - Define the values.
Step 4 - To compute trace value, iterate over each element of the matrix using two for-loops, add the diagonal elements and store the value.
Step 5 - To compute the normal value, iterate over each element of the matrix using two for-loops, compute the sum of square of each element, them compute the square root of the value and store the value.
Step 5 - Display the result
Step 6 - Stop

উদাহরণ 1

এখানে, আমরা 'প্রধান' ফাংশনের অধীনে সমস্ত ক্রিয়াকলাপ একসাথে আবদ্ধ করি।

public class NormalAndTrace {
   public static void main(String args[]) {
      int[][] input_matrix = {
         {2, 3, 4},
         {5, 2, 3},
         {4, 6, 9}
      };
      int i, j, matrix_size = 3;
      double trace = 0, square = 0, normal = 0;
      System.out.println("The matrix is defined as: ");
      for(i = 0; i < matrix_size; i++) {
         for(j = 0; j < matrix_size; j++)
         System.out.print(input_matrix[i][j]+" ");
         System.out.println(" ");
      }
      System.out.println("\nThe Trace value of the matrix is ");
      for(i = 0; i < matrix_size; i++) {
         for(j = 0; j < matrix_size; j++) {
            if(i == j) {
               trace = trace + (input_matrix[i][j]);
            }
         }
      }
      System.out.println(trace);
      System.out.println("\nThe Normal value of the matrix is ");
      for(i = 0; i < matrix_size; i++) {
         for(j = 0; j < matrix_size; j++) {
            square = square + (input_matrix[i][j])*(input_matrix[i][j]);
         }
      }
      normal = Math.sqrt(square);
      System.out.println(normal);
   }
}

আউটপুট

The matrix is defined as:
2 3 4
5 2 3
4 6 9

The Trace value of the matrix is
13.0

The Normal value of the matrix is
14.142135623730951

উদাহরণ 2

এখানে, আমরা ক্রিয়াকলাপগুলিকে অবজেক্ট-ওরিয়েন্টেড প্রোগ্রামিং প্রদর্শনকারী ফাংশনে অন্তর্ভুক্ত করি।

public class NormalAndTrace {
   static int matrix_size = 3;
   static void normal_trace(int input_matrix[][]){
      int i, j;
      double trace = 0, square = 0, normal = 0;
      System.out.println("\nThe Trace value of the matrix is ");
      for(i = 0; i < matrix_size; i++) {
         for(j = 0; j < matrix_size; j++) {
            if(i == j) {
               trace = trace + (input_matrix[i][j]);
            }
         }
      }
      System.out.println(trace);
      System.out.println("\nThe Normal value of the matrix is ");
      for(i = 0; i < matrix_size; i++) {
         for(j = 0; j < matrix_size; j++) {
            square = square + (input_matrix[i][j])*(input_matrix[i][j]);
         }
      }
      normal = Math.sqrt(square);
      System.out.println(normal);
   }
   public static void main(String args[]) {
      int i, j;
      int[][] input_matrix = { {2, 3, 4},
         {5, 2, 3},
         {4, 6, 9}
      };
      System.out.println("The matrix is defined as: ");
      for(i = 0; i < matrix_size; i++) {
         for(j = 0; j < matrix_size; j++)
         System.out.print(input_matrix[i][j]+" ");
         System.out.println(" ");
      }
      normal_trace(input_matrix);
   }
}

আউটপুট

The matrix is defined as:
2 3 4
5 2 3
4 6 9

The Trace value of the matrix is
13.0

The Normal value of the matrix is
14.142135623730951

  1. কিউবয়েডের সারফেস এরিয়া এবং ভলিউম খুঁজে পেতে জাভা প্রোগ্রাম

  2. জাভা প্রোগ্রাম একটি ট্রাপিজিয়াম এর এলাকা খুঁজে বের করতে

  3. একটি আয়তক্ষেত্রের পরিধি খুঁজে পেতে জাভা প্রোগ্রাম

  4. একটি ম্যাট্রিক্সের স্থানান্তর খুঁজে পেতে পাইথন প্রোগ্রাম