Eigen value of 100*100 Symbolic Matrix

조회 수: 13 (최근 30일)
SHUBHAM PATEL
SHUBHAM PATEL 2019년 12월 5일
댓글: Steven Lord 2020년 9월 23일
I am constructing a symbolic matrix and want to get eigen values and eigen vectors. Using following code I got error.
syms E t
Na = 100;
Nb = 100;
H =zeros(Na,Nb);
H =sym(H);
% E=1;t=1;
for i = 1:Na
for j = 1:Nb
if (i==j)
H(i,j)= E;
elseif (i-j==1|| i-j==2||i-j==3 )
H(i,j)= -t;
elseif (i-j ==-1|| i-j==-2||i-j==-3 )
H(i,j)=(-t);
end
end
end
If i would have used
[V,D]=eig(H)
it was taking too long. I don't know when it's gonna stop. Why is that? Then I tried to calculate only Eigenvalue, but an error occured:
"Error using symengine
Column index out of range."
How to sort it out?

채택된 답변

Shashank Gupta
Shashank Gupta 2019년 12월 11일
Hi Patel,
Matrix computations which involvs many symbolic variables can be slow. In your case we have 100x100 symbolic matrix which makes the speed slower. To increase the computational speed, you can reduce the number of symbolic variables by substituting the given values for some variables. Also the “symengine error” is arising because of the similar reason, it is taking more time to evaluate the eigenvalue, you can check this by reducing the matrix size and see weather the same error arise.
I hope this helps you.
  댓글 수: 4
Allan Walstad
Allan Walstad 2020년 9월 23일
Thanks! I feel like the sorcerer’a apprentice with the sorcerer out of town. Just trying to solve a physics problem to get energy levels. In principle I need an infinite matrix, but hoping to get by with 400x400. I thought I was just identifying all my variables with syms at the start, but apparently it’s more involved than that. So I eliminated the syms statement and 100x100 worked, then 121x121 took 23 minutes. Going up in steps, maybe 400x400 is attainable before they send me to the nursing home.
Steven Lord
Steven Lord 2020년 9월 23일
I recommend that you profile the 100-by-100 case (or an even smaller case, if that takes too long in the Profiler) to identify the bottlenecks and focus on those sections that take the most time. If you're not sure how or if you can improve the performance of those sections, post them (with information about classes and sizes of the variables used in the sections) as a separate question and ask for suggestions. Generally people on Answers are more than willing to help investigate interesting problems where the poster provides enough information for them to sink their teeth into.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by