How to create a special diagonal matrix with 2 vectors together?
3 次查看(过去 30 天)
显示 更早的评论
my problem is those vectors are given,but you have to put them like image shown below I dont know how to change the dimension of B so that it can fit into the matrix A = linspace(1,6,6) B = linspace(11,16,6) P.S the question asked us to use diag...
4 个评论
Stephen23
2018-1-30
Also, I want to know the way to use loop. So you could deal with both scalar and vector example for a and b...
采纳的回答
更多回答(1 个)
Andrei Bobrov
2018-1-30
编辑:Andrei Bobrov
2018-1-30
full(gallery('tridiag',B(2:end),A,B(1:end-1)));
or
n = numel(A);
out = full(spdiags([B(:),A(:),B(:)],-1:1,n,n)');
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
