How can I set certain entries in a matrix to be 0?
Given an $m\times n$ matrix with specified values:
mat = Table[1/i, {i, n}, {j, m}]
I want to make some entries 0: I will replace row $i$ with zeros when the greatest prime factor of $i$ exceeds the greatest prime factor of $n$:
GreatestPrimeFactor[1] := 1
GreatestPrimeFactor[n_Integer?Positive] := FactorInteger[n][[-1, 1]]
ReplacePart[m, {i_,j_}/; GreatestPrimeFactor[i]>GreatestPrimeFactor[n]-
>0]
I also want to set additional entries to 0, but before I do that, I want to record something to recall later; e.g., the column sums.
Total[mat, {1}]
Then I also set the $(i,j)$ entry to be $0$ when $j/\gcd(i,j)$ is composite:
ReplacePart[m, {i_,j_}/;compositeQ[j/GCD[i,j]]->0]
How can this be done in the table environment? I will consider using Array
instead of Table
.