如何在 MATLAB 中基于向量创建三角矩阵?
假设我有一个像这样的向量:
A = [101:105]
这实际上是:
[ 101, 102, 103, 104, 105 ]
我只想使用向量/矩阵函数和运算符来生成矩阵:
101 102 103 104 105
102 103 104 105 0
103 104 105 0 0
104 105 0 0 0
105 0 0 0 0
或以下矩阵:
101 102 103 104 105
0 101 102 103 104
0 0 101 102 103
0 0 0 101 102
0 0 0 0 101
有人有什么想法吗?
(我在 MATLAB 方面是个新手,但我一直背负着这些东西......)
Let's say I've got a vector like this one:
A = [101:105]
Which is really:
[ 101, 102, 103, 104, 105 ]
And I'd like to use only vector/matrix functions and operators to produces the matrix:
101 102 103 104 105
102 103 104 105 0
103 104 105 0 0
104 105 0 0 0
105 0 0 0 0
or the following matrix:
101 102 103 104 105
0 101 102 103 104
0 0 101 102 103
0 0 0 101 102
0 0 0 0 101
Any ideas anyone?
(I'm very much a novice in MATLAB, but I've been saddled this stuff...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
hankel(A)
将为您提供第一个矩阵triu(toeplitz(A))
将为您提供第二个矩阵。——洛伦
hankel(A)
will get you the first matrixtriu(toeplitz(A))
will get you the second one.--Loren
最佳解决方案由 洛伦。 还可以使用 SPDIAGS 创建这些矩阵:
我记得在发现 Loren 提到的一些内置函数之前,我曾创建过这样的带状矩阵。 它并不像使用它们那么简单和干净,但它确实有效。 =)
The best solutions are listed by Loren. It's also possible to create these matrices using SPDIAGS:
I recall creating banded matrices like this before I found out about some of the built-in functions Loren mentioned. It's not nearly as simple and clean as using those, but it worked. =)
我的方法是创建一个矩阵
A
:然后找到一个矩阵
B
,这样当您乘以A*B
时你会得到你想要的结果。 基本上是先在纸上做线性代数,然后让 Matlab 进行计算。The way I'd go about it is to create a matrix
A
:And then find a matrix
B
such that when you multiplyA*B
you'll get the result you want. Basically do the linear algebra on paper first and then have Matlab do the calculation.要生成具有这种规则模式的三角矩阵,请使用 toeplitz 函数,例如,
对于其他情况,请使用 rot90(m)
For generating such triangular matrices with such a regular pattern, use the toeplitz function, e.g.
for the other case, use
rot90(m)