Getting a diag function
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi there im stuck with this problem and really would like help here
n=length(x) %Let says is 20
x=rand(n,1);
y=rand(n,1);
RHS_empty=ones(ny,1);
iter_h=0;
for i=1:n-1
h(i)=x(i+1)-x(i);
iter_h=iter_h+1;
Ma_Sp=diag(1 h(i)) 2(h(i+1)*h(i))
end
I like to create a diagonal matrix with the interval with the specific things,
The diagonal matrix size is depending on the h(i), meaning h19, i like to get the matrix to be 20x20 with 1 at the first lane and h1 2h2*h1 h2 2h3*h2 hn 2h(i+1)*h(i) for the second coloum and it goes on for the third coloum and the fourth all the way to the 20th column, i am stuck on this matter and would appreciate your help
3 commentaires
Jan
le 18 Mar 2021
Modifié(e) : Jan
le 18 Mar 2021
The shown matrix A is not diagonal. Diagonal matrices contaoin non-zero elements on the diagonal only. You can create them with the command diag() .
There is a large, if not infitine number of ways, to fill a 20x20 matrix with a 4x4 matrix.
Maybe you are looking for the kron() command:
x = [1,2;3,4]
x =
1 2
3 4
kron(eye(3), x)
ans =
1 2 0 0 0 0
3 4 0 0 0 0
0 0 1 2 0 0
0 0 3 4 0 0
0 0 0 0 1 2
0 0 0 0 3 4
Réponses (0)
Voir également
Catégories
En savoir plus sur Operating on Diagonal Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!