How to build the scoring matrix for global sequence alignment?

Your scoring matrix is incorrect. If you print the matrix you will see that it looks like this:

    A  T  C  A
A [3, 0, 0, 1, 0]
G [3, 0, 0, 1, 0]
C [3, 0, 0, 1, 0]
A [3, 0, 0, 1, 0]
  [3, 0, 0, 1, 0]

The problem is you are comparing v[i] to every w[j] when it should only be compared to at most 2 adjacent positions (i and i+1).

You will also notice that the last column is all 0s when it should be the first row and first column are considered to be the terminal value (which is why the matrix is length+1).

finally, I believe during the traceback for a global alignment, you should start at the final position in the matrix and walk backwards (hence the term trace-back. When you walk forward over your alignment you compare the sequence similarity in the sequence, not the scores in the matrix which I don't think is correct.

You should look at the wikipedia article on Needleman-Wunsch http://en.wikipedia.org/wiki/Needleman-Wunsch_algorithm or read one of the algorithm books; Durbin et al's Biological sequence analysis is the classic (but very hard to understand) book that covers pairwise alignments.