# Unable to grasp the concept of Sparse Matrix - Kindly help me understand the following code.

2 views (last 30 days)
Hamza Shafiq on 21 Sep 2021
% Sparse Matrix Indexes: S(i,j)=0 if dF(i)/dy(j)=0, else S(i,j)=1
diagonal = diag(ones(bins,1));
dcidci = diag(ones(bins,1),0)+diag(ones(bins-1,1),-1)+diag(ones(bins-1,1),+1);
dcidcj = diag(ones(bins,1))+diag(ones(bins-1,1),-1)+diag(ones(bins-2,1),-2);
dcdc = [dcidci dcidci dcidci; dcidci dcidci dcidci; dcidci dcidci dcidci];
dcdq = diag(ones(nspecies*bins,1));
dcdT = repmat(dcidci,[nspecies,1]);
dqdq = diag(ones(nspecies*bins,1));
dqdc = repmat(diagonal,nspecies);
dqdT = repmat(diagonal,[nspecies,1])
dTdc = repmat(dcidci,[1,nspecies]);
dTdq = repmat(diagonal,[1,nspecies]);
dTdT = dcidci;
S = [dcdc dcdq dcdT; dqdc dqdq dqdT; dTdc dTdq dTdT];

### Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

R2020b

### Community Treasure Hunt

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

Start Hunting!

Translated by