MATLAB Answers

0

I need to have eigenvalues of this matrix including symbols "m" and "n"

Arooj Ibrahim 님이 질문을 제출함. 29 Oct 2019
최근 활동 John D'Errico 님이 편집함. 2 Nov 2019
clear all
m=sym('m')
n=sym('n')
A=sym([0 1/sqrt(3*n*m) 1/sqrt(3*n*m) 1/sqrt(3*n*m) 1/sqrt(3*n*m) 1/sqrt(3*n*m) 1/sqrt(3*n*m) 1/sqrt(3*n*m) 1/sqrt(3*n*m); 1/sqrt(3*n*m) 0 1/3 0 1/3 0 0 0 0; 1/sqrt(3*n*m) 1/3 0 1/3 0 0 0 0; 1/sqrt(3*n*m) 0 1/3 0 1/3 0 0 0 0; 1/sqrt(3*n*m) 1/3 0 1/3 0 0 0 0 0; 1/sqrt(3*n*m) 0 0 0 0 0 1/3 0 1/3; 1/sqrt(3*n*m) 0 0 0 0 1/3 0 1/3 0; 1/sqrt(3*n*m) 0 0 0 0 0 1/3 0 1/3; 1/sqrt(3*n*m) 0 0 0 0 1/3 0 1/3 0] )
eig(A)

  댓글 수: 5

표시 이전 댓글 수: 2
I have faced the same problem that you talked about, just to solve a 4x4 matrix symbolic math is taking indefinite amount of time. Do not know what to do, can you suggest something to sort it out.
Sometimes what is most efficient is to create a second matrix that has a letter for each unique expression (but you can leave the 0's and 1's in place.) Take the eigenvalue of that, and then substitute for the values of the variables.
For example,
syms T q
A = [0 q q q q q q q q; %length 9
q 0 T 0 T 0 0 0 0; %length 9
q T 0 T 0 0 0 0 0; %length 8 !!
q 0 T 0 T 0 0 0 0; %length 9
q T 0 T 0 0 0 0 0; %length 9
q 0 0 0 0 0 T 0 T; %length 9
q 0 0 0 0 T 0 T 0; %length 9
q 0 0 0 0 0 T 0 T; %length 9
q 0 0 0 0 T 0 T 0]; %length
[Vs, Es] = eig(A);
syms m n
qs = 1./sqrt(3*m*n);
Ts = sym(1)/3;
V = subs(Vs, {q, T}, {qs, Ts});
E = subs(Es, {q, T}, {qs, Ts});

로그인 to comment.

답변 수: 2

Steven Lord 님의 답변 29 Oct 2019

For this particular case, it looks like the structure of the problem actually makes this not too bad to compute. I tried both with m and n as separate variables and with a substitution, z = m*n, since they never appear separately. Based on the pattern of A I assumed the missing element in the third row was a 0. You can see the pattern more easily once I replaced those longer expressions with just q and T (T for one third.)
syms z m n
q = 1./sqrt(3*z);
% q = 1./sqrt(3*m*n);
T = sym(1)/3;
A = [0 q q q q q q q q; %length 9
q 0 T 0 T 0 0 0 0; %length 9
q T 0 T 0 0 0 0 0; %length 8 !!
q 0 T 0 T 0 0 0 0; %length 9
q T 0 T 0 0 0 0 0; %length 9
q 0 0 0 0 0 T 0 T; %length 9
q 0 0 0 0 T 0 T 0; %length 9
q 0 0 0 0 0 T 0 T; %length 9
q 0 0 0 0 T 0 T 0]; %length 9
[V, E] = eig(A);
But I agree with Walter. For a larger matrix A or for a more complicated pattern, the symbolic eigenvalue and eigenvector calculation may take a while and the expressions involved may become very, very long. For example, computing the eigenvalues and eigenvectors for a general 3-by-3 took about a tenth of a second and resulted in decently long expressions.
>> B = sym('B', [3 3]);
>> tic; [V, E] = eig(B); toc
Elapsed time is 0.095462 seconds.
>> strlength(char(V))
ans =
30929
>> strlength(char(E))
ans =
7301
Going to a 4-by-4 took a bit longer and resulted in much longer expressions.
>> B = sym('B', [4 4]);
>> tic; [V, E] = eig(B); toc
Elapsed time is 227.022771 seconds.
>> strlength(char(V))
ans =
6586984
>> strlength(char(E))
ans =
712104
It's dangerous to extrapolate based on only two data points, but if the 5-by-5 takes 2270 times as long as the 4-by-4 case, like the 4-by-4 case took 2270 times as long as the 3-by-3, it would take my machine about six days to generate that answer. Even if I just asked for E (not E and V) that would still run to about 7 million characters (again extrapolating based on the growth from the 3-by-3 to the 4-by-4 case.)
Consider substituting numbers for m and n (or z) and calling the numeric eig function instead. You can do this for many different numeric values of m*n in the time it would take you to solve the general problem symbolically and substitute.

  댓글 수: 0

로그인 to comment.


John D'Errico 님의 답변 2 Nov 2019
John D'Errico 님이 편집함. 2 Nov 2019

Actually, it is pretty easy, and the solution arrives almost immediately.
A=[0 1/sqrt(3*n*m) 1/sqrt(3*n*m) 1/sqrt(3*n*m) 1/sqrt(3*n*m) 1/sqrt(3*n*m) 1/sqrt(3*n*m) 1/sqrt(3*n*m) 1/sqrt(3*n*m);...
1/sqrt(3*n*m) 0 1/3 0 1/3 0 0 0 0;...
1/sqrt(3*n*m) 1/3 0 1/3 0 0 0 0 0;...
1/sqrt(3*n*m) 0 1/3 0 1/3 0 0 0 0;...
1/sqrt(3*n*m) 1/3 0 1/3 0 0 0 0 0;...
1/sqrt(3*n*m) 0 0 0 0 0 1/3 0 1/3;...
1/sqrt(3*n*m) 0 0 0 0 1/3 0 1/3 0;...
1/sqrt(3*n*m) 0 0 0 0 0 1/3 0 1/3;...
1/sqrt(3*n*m) 0 0 0 0 1/3 0 1/3 0];
First of all, this is not a problem where n and m enter independently. They always act together. We can arbitrarily substitute
u = 1/sqrt(3*n*m)
If a solution exists that we can find, then later on, substitute in the value for u. I'll even use v instead of 1/3 there, just to reduce my typing.
syms u
v = sym(1)/3;
A=[0 u u u u u u u u;...
u 0 v 0 v 0 0 0 0;...
u v 0 v 0 0 0 0 0;...
u 0 v 0 v 0 0 0 0;...
u v 0 v 0 0 0 0 0;...
u 0 0 0 0 0 v 0 v;...
u 0 0 0 0 v 0 v 0;...
u 0 0 0 0 0 v 0 v;...
u 0 0 0 0 v 0 v 0];
Now, the first question is, will we even be able to compute the eigenvalues of A analytically? That comes down to a rootfinding operation, on a degree 9 symbolic polynomial, with non-constant coefficients. I would immediately conjecture this will be difficult, since we know that is in general impossible for degree 5 polynomials or higher.
cp = charpoly(A)
cp =
[ 1, 0, - 8*u^2 - 8/9, -(16*u^2)/3, (32*u^2)/9 + 16/81, (64*u^2)/27, 0, 0, 0, 0]
Those are the coefficients, with the highest order term first. You can think of this as a polynomial in the unkown eigenvalue lambda.
The 4 zeros at the end mean we can factor out lambda^4. So there is an eigenvalue of multiplicity 4 at lambda==0. But that still leaves a degree 5 polynomial, so in general I still expect the problem to have no analytical solution.
syms lambda
reducedcp = sum(cp(1:6).*lambda.^(5:-1:0))
reducedcp =
lambda*((32*u^2)/9 + 16/81) - lambda^3*(8*u^2 + 8/9) + lambda^5 + (64*u^2)/27 - (16*lambda^2*u^2)/3
Can we solve it? Anything is possible, and sometimes we find an unexpectedly pleasant surprise.
EV = solve(reducedcp,lambda)
EV =
-2/3
-2/3
2/3
1/3 - (27*((32*u^2)/729 + 4/6561)^(1/2))/2
(27*((32*u^2)/729 + 4/6561)^(1/2))/2 + 1/3
Add on the multiplicity 4 eigenvalue at lambda==0, and we have the eigenvalues.
EV = [EV;zeros(4,1)]
EV =
-2/3
-2/3
2/3
1/3 - (27*((32*u^2)/729 + 4/6561)^(1/2))/2
(27*((32*u^2)/729 + 4/6561)^(1/2))/2 + 1/3
0
0
0
0
Now, you can even replace u with its value, in terms of n and m. As I said, the solution does not have m and n enter independently. They will always be together as a product.
Given the eigenvalues, now you can recover the associated eigenvectors. But you asked only for the eigenvalues.

  댓글 수: 0

로그인 to comment.



Translated by