Eigen value of 100*100 Symbolic Matrix

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?

 Risposta accettata

Shashank Gupta
Shashank Gupta il 11 Dic 2019
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 Commenti

I got the same error message on a 100x100 matrix. But why wouldn’t it just keep running until it finished? 81x81 only took about 10 minutes. I need to get to at least 400x400 and had every expectation of letting it run a couple days if needed. Is there any way to keep it working?
Steven Lord
Steven Lord il 23 Set 2020
Modificato: Steven Lord il 23 Set 2020
I modified the code from the original problem statement to collect some additional data. On my laptop here are some results.
For Na = 3, V is 29 characters long, D is 41 characters long, and it took 0.010913 seconds to compute V and D.
For Na = 4, V is 51 characters long, D is 66 characters long, and it took 0.028619 seconds to compute V and D.
For Na = 5, V is 162 characters long, D is 115 characters long, and it took 0.086737 seconds to compute V and D.
For Na = 6, V is 5011 characters long, D is 845 characters long, and it took 0.241859 seconds to compute V and D.
For Na = 7, V is 188305 characters long, D is 5205 characters long, and it took 0.969121 seconds to compute V and D.
For Na = 8, V is 207069 characters long, D is 4790 characters long, and it took 1.200179 seconds to compute V and D.
For Na = 9, V is 4652 characters long, D is 795 characters long, and it took 0.564672 seconds to compute V and D.
For Na = 10, V is 260309 characters long, D is 4675 characters long, and it took 1.639271 seconds to compute V and D.
For Na = 11, V is 92454 characters long, D is 4358 characters long, and it took 2.438073 seconds to compute V and D.
For Na = 12, V is 167262 characters long, D is 2670 characters long, and it took 4.053420 seconds to compute V and D.
For Na = 13, V is 1198084 characters long, D is 10266 characters long, and it took 31.828999 seconds to compute V and D.
For Na = 14, V is 1609293 characters long, D is 6426 characters long, and it took 46.291133 seconds to compute V and D.
For Na = 15, V is 2393158 characters long, D is 7827 characters long, and it took 109.184640 seconds to compute V and D.
Those character lengths are for versions of V and D that I passed through simplify. It can be dangerous to extrapolate, but I think it's safe to assume based on this data that you're not going to be able to solve the 400-by-400 symbolic eigenvalue problem in "a couple days".
If you don't need the more than 1 million character long representation of the eigenvectors for Na = 13, substituting numeric values (E = 1 and t = 1) into that symbolic matrix but leaving it symbolic required about 2 seconds to compute the eigenvectors and eigenvalues. Making the matrix a double precision matrix cut that time down to 0.03 seconds.
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.
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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Just for fun in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by