parsed matrix not deleting elements in adjusted matrix

I have a matrix that has been parsed to delete certain rows and columns, as well as delete certain elements on the diagonal on the matrix. The problem is that it does this in theory when i take the elements in terms of w[i,j]. However, when I put in an equation for w[i,j], it does not actually delete the elements. Here is the code in theory where it works M = 10; initselect = 5; secselect = 6; k[i_] := Sum[w[i, j], {j, 1, M}]; V[i_, j_] := Piecewise[{{w[i, i] – k[i], i == j}, {w[i, j], i > j}, {w[i, j], i < j}}] matrix = Table[V[i, j], {i, M}, {j, M}]; (This generates the original matrix that is unparsed) (MatrixForm[matrix]) stay = Join[Range[initselect], Range[secselect, M, 2]]; TrueMatrix = matrix[[stay, stay]]; (This generates the matrix that has parsed the selected rows and \ columns) MatrixForm[TrueMatrix]

(delete=Complement[Range[M],Join[Range[5],Range[6,M,2]]];) delete = Complement[Range[M], stay]; TrueMatrix /. w[_, Alternatives @@ delete] -> 0 // MatrixForm

It initially deletes the appropriate rows and columns to get the TrueMatrix, then the last line it also deletes the appropriate elements on the diagonal.

Now here is the code with an equation for w[i,j] M = 10; initselect = 5; secselect = 6; k[i_] := Sum[w[i, j], {j, 1, M}]; w[i_, j_] := i*j^2 V[i_, j_] := Piecewise[{{w[i, i] – k[i], i == j}, {w[i, j], i > j}, {w[i, j], i < j}}] matrix = Table[V[i, j], {i, M}, {j, M}]; (This generates the original matrix that is unparsed) (MatrixForm[matrix]) stay = Join[Range[initselect], Range[secselect, M, 2]]; TrueMatrix = matrix[[stay, stay]]; MatrixForm[TrueMatrix] (This generates the matrix that has parsed the selected rows and \ columns) (MatrixForm[TrueMatrix];)

(delete=Complement[Range[M],Join[Range[5],Range[6,M,2]]];) delete = Complement[Range[M], stay]; TrueMatrix /. w[_, Alternatives @@ delete] -> 0 // MatrixForm

Here when I print the TrueMatrix and when it computes the last line to get the final matrix, they are identical which shouldn’t be the case and isn’t the case when I just use w[i,j] without and expression.

Thank you for your help

This entry passed through the Full-Text RSS service – if this is your content and you’re reading it on someone else’s site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.
Want something else to read? How about ‘Grievous Censorship’ By The Guardian: Israel, Gaza And The Termination Of Nafeez Ahmed’s Blog

Recent Questions – Mathematica Stack Exchange