3

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

enter image description here

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.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
D. Andrew
  • 423
  • 2
  • 8

3 Answers3

6

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.}} *)
aardvark2012
  • 5,424
  • 1
  • 11
  • 22
5

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

LinearAlgebra`VandermondeMatrix[{0, 0.5, 1}, Transpose -> True]
   {{1., 0., 0.}, {1., 0.5, 0.25}, {1., 1., 1.}}

Edit 7/19/2022

In the current version, the following should be evaluated instead:

StructuredArray`VandermondeMatrix[{0, 0.5, 1}, List]
J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
4

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)$

kglr
  • 394,356
  • 18
  • 477
  • 896