<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # 檢查冪等矩陣的程序 > 原文: [https://www.geeksforgeeks.org/program-check-idempotent-matrix/](https://www.geeksforgeeks.org/program-check-idempotent-matrix/) 給定一個 N * N 矩陣,任務是檢查矩陣是否為等冪矩陣。 [**等冪矩陣:**](https://en.wikipedia.org/wiki/Idempotent_matrix) 如果矩陣與自身相乘返回相同的矩陣,則稱該矩陣為等冪矩陣。 當且僅當 **M * M = M** 時,矩陣 M 才是等冪矩陣。 在冪等矩陣中,M 是平方矩陣。 ![idempotent matrix](https://img.kancloud.cn/6d/66/6d6622dc03baeb33725b9aa6abafb223_588x163.png) 例子: ``` Input : mat[][] = {{3, -6}, {1, -2}}; Output : Idempotent Matrix Input : mat[N][N] = {{2, -2, -4}, {-1, 3, 4}, {1, -2, -3}} Output : Idempotent Matrix. ``` ## C++ ```cpp // Program to check given matrix? // is idempotent matrix or not. #include<bits/stdc++.h> #define N 3 using namespace std; // Function for matrix multiplication. void multiply(int mat[][N], int res[][N]) { ????for (int i = 0; i < N; i++) ????{ ????????for (int j = 0; j < N; j++) ????????{ ????????????res[i][j] = 0; ????????????for (int k = 0; k < N; k++) ????????????????res[i][j] += mat[i][k] * mat[k][j]; ????????} ????} } // Function to check idempotent // property of matrix. bool checkIdempotent(int mat[][N]) {??? ????// Calculate multiplication of matrix ????// with itself and store it into res. ????int res[N][N]; ????multiply(mat, res); ????for (int i = 0; i < N; i++)???? ????????for (int j = 0; j < N; j++)???????? ????????????if (mat[i][j] != res[i][j]) ????????????????return false; ????return true; } // Driver function. int main() { ????int mat[N][N] = {{2, -2, -4}, ????????????????????{-1, 3, 4}, ????????????????????{1, -2, -3}}; ????// checkIdempotent function call. ????if (checkIdempotent(mat)) ????????cout << "Idempotent Matrix"; ????else ????????cout << "Not Idempotent Matrix."; ????return 0; } ``` ## Java ```java // Java program to check given matrix? // is idempotent matrix or not. import java.io.*; class GFG? { ????static int N = 3; ????// Function for matrix multiplication. ????static void multiply(int mat[][], int res[][]) ????{ ????????for (int i = 0; i < N; i++) ????????{ ????????????for (int j = 0; j < N; j++) ????????????{ ????????????????res[i][j] = 0; ????????????????for (int k = 0; k < N; k++) ????????????????????res[i][j] += mat[i][k] * mat[k][j]; ????????????} ????????} ????} ????// Function to check idempotent ????// property of matrix. ????static boolean checkIdempotent(int mat[][]) ????{? ????????// Calculate multiplication of matrix ????????// with itself and store it into res. ????????int res[][] = new int[N][N]; ????????multiply(mat, res); ????????for (int i = 0; i < N; i++) ????????{? ????????????for (int j = 0; j < N; j++) ????????????{ ????????????????if (mat[i][j] != res[i][j]) ????????????????????return false; ????????????} ????????} ????????return true; ????} ????// Driver code. ????public static void main (String[] args)? ????{ ????????int mat[][] = {{2, -2, -4}, ???????????????????????{-1, 3, 4}, ???????????????????????{1, -2, -3}}; ????????// checkIdempotent function call. ????????if (checkIdempotent(mat)) ????????????System.out.println( "Idempotent Matrix"); ????????else ????????????System.out.println("Not Idempotent Matrix."); ????} } // This code is contributed by vt_m. ``` ## Python 3 ``` # Python Program to check given matrix? # is idempotent matrix or not. import math # Function for matrix multiplication. def multiply(mat, res): ????N= len(mat) ????for i in range(0,N): ????????for j in range(0,N): ????????????res[i][j] = 0 ????????????for k in range(0,N): ????????????????res[i][j] += mat[i][k] * mat[k][j] # Function to check idempotent # property of matrix. def checkIdempotent(mat): ????N= len(mat) ????# Calculate multiplication of matrix ????# with itself and store it into res. ????res =[[0]*N for i in range(0,N)] ????multiply(mat, res) ????for i in range(0,N): ????????for j in range(0,N):????? ????????????if (mat[i][j] != res[i][j]): ????????????????return False ????return True # driver Function mat = [ [2, -2, -4], ????????[-1, 3, 4], ????????[1, -2, -3] ] # checkIdempotent function call. if (checkIdempotent(mat)): ????print("Idempotent Matrix") else: ????print("Not Idempotent Matrix.") # This code is contributed by Gitanjali. ``` ## C# ```cs // C# program to check given matrix? // is idempotent matrix or not. using System; class GFG? { ????static int N = 3; ????// Function for matrix multiplication. ????static void multiply(int [,]mat, int [,]res) ????{ ????????for (int i = 0; i < N; i++) ????????{ ????????????for (int j = 0; j < N; j++) ????????????{ ????????????????res[i,j] = 0; ????????????????for (int k = 0; k < N; k++) ????????????????????res[i,j] += mat[i,k] * mat[k,j]; ????????????} ????????} ????} ????// Function to check idempotent ????// property of matrix. ????static bool checkIdempotent(int [,]mat) ????{? ????????// Calculate multiplication of matrix ????????// with itself and store it into res. ????????int [,]res = new int[N,N]; ????????multiply(mat, res); ????????for (int i = 0; i < N; i++) ????????{? ????????????for (int j = 0; j < N; j++) ????????????{ ????????????????if (mat[i,j] != res[i,j]) ????????????????????return false; ????????????} ????????} ????????return true; ????} ????// Driver code ????public static void Main ()? ????{ ????????int [,]mat = {{2, -2, 4}, ????????????????????{-1, 3, 4}, ????????????????????{1, -2, -3}}; ????????// checkIdempotent function call. ????????if (checkIdempotent(mat)) ????????????Console.WriteLine( "Idempotent Matrix"); ????????else ????????????Console.WriteLine("Not Idempotent Matrix."); ????} } // This code is contributed by vt_m. ``` Output ``` Idempotent Matrix ``` * * * * * *
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看