How to write diagonal matrix in deep learning array
Mostrar comentarios más antiguos
I have this matrix
D = zeros(M, M + 1);
D(1:end-1, 1:end-2) = diag((1/(2*h)) * ones(M-1, 1));
D(1:end-1, 3:end) = diag((-1/(2*h)) * ones(M-1, 1));
D(end, end-1:end) = (1/h) * [1,-1];
and I am writing this in a deep learning dlarray. But I am getting this below error
Undefined function 'diag' for input arguments of type 'dlarray'.
what is the best or another way to write this diagonal matrix for dlarray?
2 comentarios
"what is the best or another way to write this diagonal matrix for dlarray?"
Simply define the array first as you have and then convert using dlarray. No need of using a for loop.
M = 10;
h = 5;
D = zeros(M, M + 1);
D(1:end-1, 1:end-2) = diag((1/(2*h)) * ones(M-1, 1));
D(1:end-1, 3:end) = diag((-1/(2*h)) * ones(M-1, 1));
D(end, end-1:end) = (1/h) * [1,-1];
D
E = dlarray(D)
Muhammad
el 17 de En. de 2024
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Deep Learning Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!