Effective matrix defining (diagonals)

1 visualización (últimos 30 días)
Nitzan Haviv
Nitzan Haviv el 4 de Ag. de 2021
Respondida: Nitzan Haviv el 4 de Ag. de 2021
hi, i would like to get some help with defining the next matrix in the easiest way. i know the diag() function but i didnt find a way the define the non-main diagonals.

Respuesta aceptada

Stephen23
Stephen23 el 4 de Ag. de 2021
N = 7;
M = toeplitz([-2,1,zeros(1,N-2)])
M = 7×7
-2 1 0 0 0 0 0 1 -2 1 0 0 0 0 0 1 -2 1 0 0 0 0 0 1 -2 1 0 0 0 0 0 1 -2 1 0 0 0 0 0 1 -2 1 0 0 0 0 0 1 -2
  2 comentarios
Nitzan Haviv
Nitzan Haviv el 4 de Ag. de 2021
thanks a lot!
Stephen23
Stephen23 el 4 de Ag. de 2021
@Nitzan Haviv: my pleasure! Remember to click the accept button if my answer helped you!

Iniciar sesión para comentar.

Más respuestas (1)

Nitzan Haviv
Nitzan Haviv el 4 de Ag. de 2021
btw i found another way
when N is the dimention of the square matrix
d_sec = ones(1,N-1);
d_main= ones(1,N).*-2;
H = diag(d_main)+diag(d_sec,-1) + diag(d_sec,1);

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by