# How to Override a Calculated Value in a Matrix with an Assigned Value

How do I override a calculated value within a matrix with an assigned value? Here is an example of what I mean. Consider matrix Y,

Y = MatrixForm[Table[i^j,{i, 0, 1, 0.5}, {j, 0, 2, 1}]]


with the output Of course, the Indeterminate in Y[1, 1]is due to 0^0. How do I override the Indeterminate output with say Y[1, 1] = 1 while creating the matrix? Thank you.

• A few things, 1) MatrixForm is a wrapper, you probably want MatrixForm[ Y = Table[ .... ] ]  2) Parts are taken and assigned with Part which has an alias in [[ ]] so what in a more classic C-derived language would be Y[1, 1] in Mathematica is Y[[1, 1]]. So all together you want Y = Table[ ... ]; Y[[1,1]]=1; MatrixForm[Y]. – b3m2a1 Sep 11 '17 at 4:36
• If[i==j==0,1,i^j] – Algohi Sep 11 '17 at 4:50
• @b3m2a1 Thank you for the tweak. Your suggestion works pretty fine. – D. Andrew Sep 11 '17 at 4:51
• Related, perhaps duplicate: (10977), (60575), (64179), (102007) – Mr.Wizard Sep 11 '17 at 12:36

In general, if you don't know in advance where Indeterminate entries are going to appear, you can use /. (ReplaceAll) to replace them with whatever you like. So

Y = Table[i^j, {i, 0, 1, 0.5}, {j, 0, 2, 1}];
(* {{Indeterminate, 0., 0.}, {1., 0.5, 0.25}, {1., 1., 1.}} *)


Then

Y /. {Indeterminate -> 1}
(* {{1, 0., 0.}, {1., 0.5, 0.25}, {1., 1., 1.}} *)


FWIW, there is some undocumented functionality for generating Vandermonde matrices:

LinearAlgebraVandermondeMatrix[{0, 0.5, 1}, Transpose -> True]
{{1., 0., 0.}, {1., 0.5, 0.25}, {1., 1., 1.}}


Also

Block[{Indeterminate = 1}, Quiet@Table[i^j, {i, 0, 1, 0.5}, {j, 0, 2, 1}]]
// MatrixForm // TeXForm
`

$\left( \begin{array}{ccc} 1 & 0. & 0. \\ 1. & 0.5 & 0.25 \\ 1. & 1. & 1. \\ \end{array} \right)$