# How can I evaluate a matrix for a set of values?

I'm trying to evaluate a system, that depends on two variables, in a specific set of values. I will write an example, but my system is more complicated.

H = {{x^2, y}, {y^2, x}};
{val, vect} = Eigensystem[H];


I select an eigenvector

b = vect[];


Then I write new variables in terms of the eigenvector elements

A = b[];
B = b[];


Finally, a new matrix is built.

M = {{A, B}, {A*A, B}};


x and y must be evaluate for the following list of data:

x={1,2,3,4};
y={0,1,2,5};


The thing is that I need to find the matrix M for each pair of coordinates [x,y]:

{{1,0},{2,1},{3,2},{4,5}}


with the help of a loop, for example Do. This, because my system is more complicated and I can not do it manually (It will take me a lot of time). I was trying to use the loop Do with the iterator Thread, nonetheless I don´t know if this is possible .

I'm new using Mathematica. I really don't understand why this is happening. Some of you guys can help me? Thank you.

There are lots of possible way to do this; which is preferable is likely to depend on your specific needs. One method is to form a Function and then MapThread that across your values. Below Evaluate is used to get the definition of M into the held Function body instead of a verbatim M.

Clear[x, y]

MapThread[{x, y} \[Function] Evaluate[M], {{1, 2, 3, 4}, {0, 1, 2, 5}}] // Quiet

{{{Indeterminate, 1}, {Indeterminate, 1}},
{{1/2 (2 - 2 Sqrt), 1}, {1/4 (-2 + 2 Sqrt)^2, 1}},
{{1/8 (6 - 2 Sqrt), 1}, {1/64 (-6 + 2 Sqrt)^2, 1}},
{{1/50 (12 - 2 Sqrt), 1}, {(-12 + 2 Sqrt)^2/2500, 1}}}


Another method is to make a Listable function to handle the threading directly, as follows:

fn = Function[{x, y}, Evaluate[M], Listable];

fn[{1, 2, 3, 4}, {0, 1, 2, 5}] // Quiet   (* same output *)


Another possibility

ClearAll[x, y];
H = {{x^2, y}, {y^2, x}};
v = First@Eigenvectors[H];
A = v[]; B = v[];
M = {{A, B}, {A*A, B}};
xCoord = {1, 2, 3, 4};
yCoord = {0, 1, 2, 5};
coord = Partition[Riffle[xCoord, yCoord], 2];
data = {{#[], #[]}, Limit[M, {x -> #[], y -> #[]}]} & /@ coord;
data = {#[], MatrixForm[#[]]} & /@ data;
Grid[Join[{{"(x,y)", "M matrix"}}, data], Frame -> All] If you want numerical, change the line above to

 data = {#[], MatrixForm[N@#[]]} & /@ data; Two things to note are (1) different eigenvector normalization would lead to different M-matrices and (2) when $$(x,y)=(1,0)$$ we have two eigenvectors for the repeated eigenvalue, so which eigenvector do we call "first"? We let Mathematica choose the normalization and the eigenvector order in the following code:

H = {{x^2, y}, {y^2, x}};
allM = Table[
With[{v = First@Eigenvectors[
H /. x -> First@val /. y -> Last@val]},
{v, v*{First@v, 1}}],
{val, Thread[{{1, 2, 3, 4}, {0, 1, 2, 5}}]}];

Column[MatrixForm /@ allM]


$$\begin{array}{l} \left( \begin{array}{cc} 0 & 1 \\ 0 & 1 \\ \end{array} \right) \\ \left( \begin{array}{cc} 1+\sqrt{2} & 1 \\ \left(1+\sqrt{2}\right)^2 & 1 \\ \end{array} \right) \\ \left( \begin{array}{cc} \frac{1}{4} \left(3+\sqrt{17}\right) & 1 \\ \frac{1}{16} \left(3+\sqrt{17}\right)^2 & 1 \\ \end{array} \right) \\ \left( \begin{array}{cc} \frac{1}{25} \left(6+\sqrt{161}\right) & 1 \\ \frac{1}{625} \left(6+\sqrt{161}\right)^2 & 1 \\ \end{array} \right) \\ \end{array}$$

The reason these results differ from other methods is that this method puts the numbers in first so Mathematica can use numeric sort.

When $$(x,y)=(1,0)$$ the H-matrix is the identity matrix, so any finite, non-zero vector $${A,B}$$ is an eigenvector.