This matrix represents a square surface of side N². The utltimate goal of my exercise is to approximate the solution of the heat equation on this surface, and for this I am using the finite difference method. This whole part is actually rather easy. A couple of loops in and the job is done. Only thing is that, as I said, I am quite new at Python and there stil are stuff that confuse me (like first element of a matrix starts at 0 and not 1). So I'm getting there but it takes time. Python on top of it seems more rigid than the other languages I used to use.
Maybe in the end I only have syntax issues. I tried to concatenate the matrices. That sort of works but it only gives me a "line of matrices", and not a proper array. I also tried to think of it as a list of lists, which totally make sense, but as I said in my first post, I have no idea how to initialize such array; filling it would be no problem.
So maybe there are some more dedicated functions and tools in numpy that I'm not aware of. Thus my thread.
To answer your question, there is "theoretically" no limits on N. And given my exercise, it's going to be rather large.
Cheers!
And... Actually thanks to your help and to the links you posted, I finally found the solution!
Maybe in the end I only have syntax issues. I tried to concatenate the matrices. That sort of works but it only gives me a "line of matrices", and not a proper array. I also tried to think of it as a list of lists, which totally make sense, but as I said in my first post, I have no idea how to initialize such array; filling it would be no problem.
So maybe there are some more dedicated functions and tools in numpy that I'm not aware of. Thus my thread.
To answer your question, there is "theoretically" no limits on N. And given my exercise, it's going to be rather large.
Cheers!
And... Actually thanks to your help and to the links you posted, I finally found the solution!
u=-1*ones(Ns-1) D=4*eye(Ns)+diag(u,1)+ diag(u,-1) E=-eye(Ns) N=Ns*Ns A=array([0]*N*N).reshape(N,N) for i in range (0,N,Ns): A[i:i+Ns,i:i+Ns]=D A[i:i+Ns,i+Ns:i+2*Ns]=E A[i+Ns:i+2*Ns,i:i+Ns]=E A[N-Ns:N,N-Ns:N]=D print('A = ', A)For Ns=3:
Output:A = [
[ 4 -1 0 -1 0 0 0 0 0]
[-1 4 -1 0 -1 0 0 0 0]
[ 0 -1 4 0 0 -1 0 0 0]
[-1 0 0 4 -1 0 -1 0 0]
[ 0 -1 0 -1 4 -1 0 -1 0]
[ 0 0 -1 0 -1 4 0 0 -1]
[ 0 0 0 -1 0 0 4 -1 0]
[ 0 0 0 0 -1 0 -1 4 -1]
[ 0 0 0 0 0 -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