Last active
August 29, 2015 14:00
-
-
Save codenameyau/eb8cdaf92f6730778012 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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