How can i change the 1st row 1st column and last row last column values in a tridiagonal matrix
조회 수: 22 (최근 30일)
이전 댓글 표시
n=5;
A=zeros(n,n);
for i=1:n
if (i>1)
A(i-1,i)=-100;
end
A(i,i)=300;
if (i<n)
A(i+1,i)=-100;
end
end
I wrote the code above to create a tridiagonal matrix. I need to separate the 1st row 1st column variable and the last row last column variable, so that i can assign a different value for these two variable's but im not sure how to write a statement to do this task.
댓글 수: 2
채택된 답변
Are Mjaavatten
2018년 4월 22일
A(1,1) = 17;A(end,end) = 23;
You can create your original matrix without using a loop:
n = 5; A = diag(ones(1,n))*300-diag(ones(1,n-1)*100,-1)-diag(ones(1,n-1)*100,1);
댓글 수: 0
추가 답변 (1개)
Dhamotharan
2024년 7월 29일
Change the element in the first row and last column of data to 0.5.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!