double s[3][3] = {-0.145, 0.784, 0.745,
0.214, 0.547, 0.547,
0.321, 0.254, 0.452 };
double g[3] = {0.124,0.245,0.657};
double result[3];
int i, j;
int main() {
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
result[i] += s[i][j] * g[i];
result[i];
printf("%d\t", result[i]);
}
}
}
请告诉我,我在程序中写的有什么问题?结果,您应该得到一个 3x1 的矩阵。
最佳答案
您需要像这样初始化结果:
double result[3] = {0.,0.,0.}
因为结果[i] += ...
正在增加现有值(value)。
和
result[i] += s[i][j] * g[j]; (g[j] instead of g[i])
关于c - 如何用 C 语言将矩阵 3x3 乘以 3x1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46594603/