# What row do I change to make my determinant non zero?

I wish to make a matrix that has an inverse. I need rows that look like oscillating functions so I decided to base my matrix on ChebyshevT. This code makes an n by n matrix.

ClearAll[makeMat];
makeMat[nn_] :=
Table[Table[ChebyshevT[n, x], {x, -1, 1, 2/(nn - 1)}], {n, nn}]


An example with n = 7 is

mat = makeMat; mat // MatrixForm The determinate of this matrix is zero

Det[mat]


0

In fact all matrices with n odd are zero. It is not obvious by looking at the matrix which rows are linear combinations of others (or columns). If we do

Eigenvalues[mat] // N


{2.09478, 1.65033, -0.540451 + 1.45434 I, -0.540451 - 1.45434 I, 1.09427, -0.698129, 0.}

We can see that there is a zero entry indicating that the determinant is zero. For n = 5 there are two zero eigenvalues.

I would like to replace one row with random numbers, or possibly more appropriate values, so that the determinant is not zero.

Trying to do this in a crude manner does suggests I can change rows {1,3,5,7} but not {2,4,6}:

SeedRandom;
Table[mat1 = mat;
mat1[[n]] = RandomReal[{-1, 1}, 7];
Det[mat1],
{n, 7}]


{-43.7443, 0., -1.4494, 0., 1.06642, 0., 39.3547}

Is there a known way to do this? I would like to keep most of the rows unaltered because they can be interpolated nicely. I need n to be upto about 50. I have looked at other functions, e.g. Legendre and they also give zero determinants.

Any thoughts

• try mat=makeMat; mat2=MapAt[RandomReal[1, Length@mat] &, mat, {RandomChoice[ Range[1, Length[mat], 2]]}]? or mat3=MapAt[RandomReal[1, Length@mat] &, mat, {1}]? – kglr Aug 6 at 21:29
• why don't you include a constant shift, e.g., ChebyshevT[n, x + n] instead of ChebyshevT[n, x]? This should still look oscillating, but is non-singular. – AccidentalFourierTransform Aug 6 at 21:32