Creating a matrix using diag
조회 수: 6 (최근 30일)
이전 댓글 표시
Hi,
Would you please help me to write a script with "diag" command to create the matrix as shown in image. http://s1.postimage.org/5i4gd1esv/matrix.jpg By they way, it's a 99 X 99 matrix.
Thank you, John
댓글 수: 2
채택된 답변
Matt J
2013년 1월 27일
>> z=zeros(3,1); z(1)=2; z(2)=-1; A=toeplitz(z)
A =
2 -1 0
-1 2 -1
0 -1 2
댓글 수: 3
추가 답변 (2개)
Matt J
2013년 1월 27일
편집: Matt J
2013년 1월 27일
A small example
>> A=diag([1,1,1])-diag([1,1],1); A=A+A.'
A =
2 -1 0
-1 2 -1
0 -1 2
댓글 수: 4
Matt J
2013년 1월 27일
I don't know what more help I can give without just doing the whole thing for you. Are you aware that
>> help diag
or
>> doc diag
will display an explanation of the diag command? If you've read that documentation, it should be really easy. Some more examples:
>> diag([1 2 3 4]), diag([10 20 30], 2), diag([5 7 6],-1)
ans =
1 0 0 0
0 2 0 0
0 0 3 0
0 0 0 4
ans =
0 0 10 0 0
0 0 0 20 0
0 0 0 0 30
0 0 0 0 0
0 0 0 0 0
ans =
0 0 0 0
5 0 0 0
0 7 0 0
0 0 6 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!