Azzera filtri
Azzera filtri

How to create a special diagonal matrix with 2 vectors together?

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Stephen23
Stephen23 il 30 Gen 2018
CodeElinesa's "Answer" moved here:
Also, I want to know the way to use loop. So you could deal with both scalar and vector example for a and b...
Stephen23
Stephen23 il 30 Gen 2018
Modificato: Stephen23 il 30 Gen 2018
@CodeElinesa: it helps us if you post comments as comments, not answers.

Accedi per commentare.

Risposta accettata

Walter Roberson
Walter Roberson il 30 Gen 2018
hint 1:
diag(b(1:end-1), -1)
hint 2: you can add matrices together.
  5 Commenti

Accedi per commentare.

Più risposte (1)

Andrei Bobrov
Andrei Bobrov il 30 Gen 2018
Modificato: Andrei Bobrov il 30 Gen 2018
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)');

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by