Skip to content

Instantly share code, notes, and snippets.

@codenameyau
Last active August 29, 2015 14:00
Show Gist options
  • Save codenameyau/eb8cdaf92f6730778012 to your computer and use it in GitHub Desktop.
Save codenameyau/eb8cdaf92f6730778012 to your computer and use it in GitHub Desktop.
function A = generate_a( N )
% Generates matrix A
% N: Integer of size of mesh
n = N-1;
meshsize = n*n;
% Build matrix D
D_block = triu(tril(ones(n), 1), -1) - 5*eye(n);
D_repeat = repmat({D_block}, n, 1);
D_matrix = blkdiag(D_repeat{:});
% Setup Identity matrix
I_vector = ones(meshsize-n, 1)';
I_lower = diag(I_vector, n);
I_upper = diag(I_vector, -n);
A = D_matrix + I_lower + I_upper;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment