How best and most efficient way to build this matrix
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Scott Banks
am 3 Sep. 2023
Kommentiert: Matt J
am 4 Sep. 2023
Hi guys,
I am wondering what is the best and most efficient way to build this matrix using loops and functions? Rather than inputting the numbers manually?
A = [-2 1 0 0 0 0 0 0 0 0
6 -4 1 0 0 0 0 0 0 0
-4 6 -4 1 0 0 0 0 0 0
1 -4 6 -4 1 0 0 0 0 0
0 1 -4 6 -4 1 0 0 0 0
0 0 1 -4 6 -4 1 0 0 0
0 0 0 1 -4 6 -4 0 0 0
0 0 0 0 1 -4 6 -4 1 0
0 0 0 0 0 1 -4 6 -4 1
0 0 0 0 0 0 0 0 1 -2]
Many thanks
3 Kommentare
Matt J
am 3 Sep. 2023
Has A(7,8) deliberately been made 0 instead of 1? If so, it is not clear what the pattern is supposed to be.
Akzeptierte Antwort
Matt J
am 3 Sep. 2023
[C,R]=deal(zeros(1,10));
C(1:4)=[-4 6 -4 1];
R(1:2)=[-4,1];
A=toeplitz(C,R);
A(1)=-2;
A(end,:)=flip(A(1,:))
3 Kommentare
Matt J
am 4 Sep. 2023
@Scott Banks for a full explanation, I suggest the documentation links provided by Walter.
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!