C 矩陣乘法

2021-07-28 04:04:52 字數 869 閱讀 7363

用慣了數學庫,有的時候有些基本的運算,像矩陣求逆,轉置矩陣什麼的,寫起來突然感覺有些生疏了,這裡算是對一些基本線性代數的複習。用c寫矩陣乘法;

注意點:

(1)二維陣列與二級指標的區別;

(2)矩陣乘法的要點,新的結果矩陣的第i行第j列是矩陣a的第i行與矩陣b的第j列的乘積,這一點不熟悉,寫程式就會有點吃力;對程式結構思路就會存在不清晰的地方;

(3)有很多可以完善的地方,由於時間問題,先記於此;

#include "stdafx.h"

#include#include#include#include#includeusing namespace std;

void matrixmul(int matrixa[2][2], int rowa, int cola, int matrixb[2][2], int rowb, int colb, int result[2][2])

for (size_t i = 0; i < rowa; i++)

for (size_t j = 0; j < colb; j++)

result[i][j] = sum;

} }int _tmain(int argc, _tchar* argv)

,}; int b[2][2] = , };

int result[2][2];

matrixmul(a, 2, 2, b, 2, 2,result);

cout << "相乘以後的結果為:" << endl;

for (size_t i = 0; i < 2; i++)

cout << endl;

} while (true);

return 0;

}

矩陣乘法 C

using system using system.collections.generic using system.text namespace exe03 static void main string args int martixb new int int martixc new int m...

c 模板 矩陣乘法

想起編寫這個程式是複習線代備考的時候看到了乙個這樣的問題 同濟線性代數 第五版 p30 例 2 四個城市的單向航線如圖所示 1,從 i 市到 j 市有1條單向航線 aij 0,從 i 市到 j 市沒有單向航線 則上圖可用乙個矩陣表示 a aij 0 1 1 1 1 0 0 0 0 1 0 0 1 0...

C語言 矩陣乘法

問題描述 給定乙個n階矩陣a,輸出a的m次冪 m是非負整數 例如 a 1 23 4 a的2次冪 7 10 15 22 輸入格式 第一行是乙個正整數n m 1 n 30,0 m 5 表示矩陣a的階數和要求的冪數 接下來n行,每行n個絕對值不超過10的非負整數,描述矩陣a的值 輸出格式 輸出共n行,每行...