如何在Matlab中制作三对角矩阵? [英] How to make tridiagonal matrix in matlab?

查看:1121
本文介绍了如何在Matlab中制作三对角矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何根据矢量[1 2 3 4 5]创建矩阵

How I create matrix below from vector [1 2 3 4 5]

1 0 0 0 0
2 1 0 0 0
3 2 1 0 0
4 3 2 1 0
5 4 3 2 1
0 5 4 3 2
0 0 5 4 3
0 0 0 5 4
0 0 0 0 5

推荐答案

这不是三对角线,而是五对角矩阵的变体.您可以使用diag,sparse或spdiags,所有这些都可以构建它.您可以阅读我的 blktridiag 代码,该代码位于

This is not tridiagonal, but a variant of pentadiagonal matrix. You can use diag, or sparse, or spdiags, all of which could build it. You could read my blktridiag code, as found on the File Exchange, to learn how I build such a matrix efficiently.

但是,也许最简单的解决方案是识别您的矩阵具有特殊形式,即toeplitz矩阵.

But perhaps the simplest solution is to recognize that your matrix is of a special form, a toeplitz matrix.

>> toeplitz([1:5,zeros(1,4)]',[1, zeros(1,4)])
ans =
     1     0     0     0     0
     2     1     0     0     0
     3     2     1     0     0
     4     3     2     1     0
     5     4     3     2     1
     0     5     4     3     2
     0     0     5     4     3
     0     0     0     5     4
     0     0     0     0     5

这篇关于如何在Matlab中制作三对角矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆