How to write diagonal matrix in deep learning array
Ältere Kommentare anzeigen
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 Kommentare
"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
am 17 Jan. 2024
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Deep Learning Toolbox finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!