将上三角矩阵变换为全矩阵 C++
将上三角矩阵转换为完整矩阵的代码会是什么样子。 矩阵位于向量中,而不是二维数组中...
因此该数组
[ 1 2 3 4
0 5 6 7
0 0 8 9
0 0 0 10 ]
将变成一个数组,例如:
[ 1 2 3 4
2 5 6 7
3 6 8 9
4 7 9 10 ]
您能否提供一些想法,我正在考虑应用一种模块或其他东西...
有一个限制,< strong>我没有使用二维数组 我使用的是向量,所以是一维数组
How would look the code that can transform an upper triangular matrix into a full matrix.
The matrix is in a vector, not in a bidimensional array...
so the array
[ 1 2 3 4
0 5 6 7
0 0 8 9
0 0 0 10 ]
would become an array like:
[ 1 2 3 4
2 5 6 7
3 6 8 9
4 7 9 10 ]
could you provide some ideas, I was thinking in applying a kind of module or something...
There is one restriction, I am not using bidimensional arrays
I am usng a vector, so is a unidimensional array
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,您必须了解反射矩阵的基本性质。对于任何
i
、j
,以下断言为真:因此,您需要某种算法来使其成立。我可以建议:
注意第二个循环的情况。通过确保
j
始终小于i
,我们将活动限制在左下三角形。接下来,您必须了解如何在一维数组中实现二维矩阵。看来你已经确定了身份:
替代的话,我们有:
First, you must understand the fundemtnal nature of a reflected matrix. For any
i
,j
, the following assertion is true:So, you need some algorithm to make that true. May I suggest:
Note the condition of the 2nd loop. By ensuring that
j
is always less thani
, we restrict our activity to the bottom-left triangle.Next, you must understand how you have implemented a two-dimensional matrix in a one-dimensional array. It appears that you have established the identity:
Substituting, we have: