How to write diagonal matrix in deep learning array
Mostra commenti meno recenti
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 Commenti
"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
il 17 Gen 2024
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Deep Learning Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!