write this following matrix
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Zeynep Toprak
il 7 Mag 2020
Commentato: Gokberk Yildirim
il 16 Mag 2020
How can I write the following matrix
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/291292/image.png)
I define n=100
And I generate the following code
D= toeplitz ([0 1 zeros(1, n-2) -1]/ (2*h))
but I get wrong matrix. How can I correct it?
6 Commenti
Gokberk Yildirim
il 16 Mag 2020
Actually, it can be done with this Zeynep.
c = [0 -1 zeros(1,n-3)];
r = [0 1 zeros(1,n-3)];
D = toeplitz(c,r) / (2*h)
Risposta accettata
John D'Errico
il 7 Mag 2020
Modificato: John D'Errico
il 7 Mag 2020
Try this:
n = 100;
D = (diag(ones(n-1,1),1) - diag(ones(n-1,1),-1))/(2*h);
You can also use spdiags. or sparse, or many other tools. But diag as I did it above is about the simplest way.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!