Create Sparse Finite Difference Matrix without Loop

조회 수: 6 (최근 30일)
Saeid
Saeid 2017년 4월 7일
댓글: Saeid 2017년 4월 7일
In dealing with a finite difference problem over a 1-D domain composed of i nodes, I am trying to create a sparse matrix of elements H(2) to H(i-1) of the following form:
How can I do this without using a loop?

채택된 답변

KSSV
KSSV 2017년 4월 7일
You can create your matrix something like this:
d1 = 1:5 ;
d0 = 1:6 ;
d2 = 1:5 ;
A = diag(d2,-1)+diag(d0)+diag(d1,1) ;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by