Message Boards Message Boards

0
|
133 Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Matrix, the elements of which is a function

Posted 9 days ago

I wrote down this code in mathematica:

A = {{1, 2}, {2, 1}};
A // MatrixForm
L = Eigenvalues[A]
V = Eigenvectors[A]

Do[If[L[[i]] < 0, {L[[i]] = -L[[i]], V[[i]] = -V[[i]]}], {i, 
  Length[L]}]

L
V

And it simply gives the correct outputs:

Out:{{1,2},{2,1}}
Out:{3, -1}
Out:{{1, 1}, {-1, 1}}
Out:{3, 1}
Out:{{1, 1}, {1, -1}}

But if I write the matrix as a function of some variable and do the same, it's not giving the same answer:

In: A[a_] = {{a, 2}, {2, a}};

(*Compute eigenvalues and eigenvectors*)
S[a_] = Eigenvalues[A[a]];
T[a_] = Eigenvectors[A[a]];

(*Loop to modify eigenvalues and eigenvectors*)
Do[If[S[a][[i]] < 0, {S[a][[i]] = -S[a][[i]], 
   T[a][[i]] = -T[a][[i]]}], {i, Length[S[a]]}]

S[1]
T[1]


Out:{-1, 3}
Out: {{-1, 1}, {1, 1}}

Can anyone resolve the issue?

POSTED BY: Subhajit Paul
2 Replies

You call the condition S[a][[1]] < 0 before S[a][[1]] has a numerical value, so the Do does nothing. How about this:

S[a_] = Abs[Eigenvalues[A[a]]];
T[a_] = Eigenvectors[A[a]]*Sign[Eigenvalues[A[a]]];
POSTED BY: Gianluca Gorni
Posted 9 days ago

Okay, understood. Thank you.

POSTED BY: Subhajit Paul
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract