필터 지우기
필터 지우기

How to make a tridiagonal matrix (N-1)*(N-1), with different values in the first row?

조회 수: 2 (최근 30일)
Ilyan Njim
Ilyan Njim 2023년 5월 15일
답변: Steven H 2023년 5월 15일

답변 (2개)

Torsten
Torsten 2023년 5월 15일
Change the two values manually after you created A with the "standard" diagonal vectors.
A = ...;
A(1,1) = A(1,1) + 4/3;
A(1,2) = A(1,2) - 1/3;
...

Steven H
Steven H 2023년 5월 15일
A = (-2 + 16*h^2)*eye(n-1); % Create the diagonal
I = [2:n:numel(A), n:n:numel(A)]; % Indices of off-diagonal elements
A(I) = 1; % Set values to one
A(1,1:2) = A(1,1:2) + [4/3, -1/3]; % Change values in first row

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by