anderkve / FYS3150

https://anderkve.github.io/FYS3150
26 stars 14 forks source link

Is the analytical solution correct? #11

Closed nevlunghavn closed 3 years ago

nevlunghavn commented 3 years ago

I'm having problems getting values from the Armadillo calculation and the analytic solution to match up. Armadillo gives the matrix of eigenvectors:

-0.2319 -0.4179 0.5211 -0.5211 0.4179 -0.2319 -0.4179 -0.5211 0.2319 0.2319 -0.5211 0.4179 -0.5211 -0.2319 -0.4179 0.4179 0.2319 -0.5211 -0.5211 0.2319 -0.4179 -0.4179 0.2319 0.5211 -0.4179 0.5211 0.2319 -0.2319 -0.5211 -0.4179 -0.2319 0.4179 0.5211 0.5211 0.4179 0.2319

Now using the analytic solution. Note that this is NOT the same as what is given in the project. The numerator in each term is $i\pi$.

$$ \vec{v}^{(i)} = \left[\sin\left(\frac{i \pi}{N+1}\right), \sin\left(\frac{i \pi}{N+1}\right), \ldots, \sin\left(\frac{i \pi}{N+1}\right)\right]^T,\quad i = 1,\ldots,N $$

I get for the first vector (very quick and dirty Python)

0.4338837391175581 0.7818314824680298 0.9749279121818236 0.9749279121818236 0.7818314824680299 0.43388373911755823

which I expect to be a constant multiple of the first column in the above Armadillo matrix. So if I divide componentwise, I get

-0.5344749735762007 -0.5345141624136228 -0.5345010574513278 -0.5345010574513278 -0.5345141624136227 -0.5344749735762004

which to 4 significant figures seems reasonable.

I can't see what I've overlooked. Comments would be appreciated.

anderkve commented 3 years ago

Hi @nevlunghavn,

See the comment about scaling eigenvectors in the project description. (In short: if x is an eigenvector, then c*x with c some arbitrary constant is an equally good eigenvector -- and note that c can be negative.) The eigenvectors from Armadillo are typically scaled to have unit length, so to compare you should scale your eigenvectors accordingly.

nevlunghavn commented 3 years ago

Sorry, I'm surely being very slow on the uptake here, but the values I have calculated with Pyhton seem OK. After normalization they are:

0.23192061 0.41790651 0.52112089 0.52112089 0.41790651 0.23192061

which, to within a factor of -1 again seem reasonable. However to get these values I've not used the provided analytical solution, but one where only $i \pi$ appears in the numerator. Apologies, if I'm being painfully slow on the uptake (:

nevlunghavn commented 3 years ago

So I'll try and attach a couple of screenshots. The first is what I've used to calculate the above values and second is what is provided in the project.

Screenshot at 2021-09-20 20-18-02

Screenshot at 2021-09-20 20-18-21

anderkve commented 3 years ago

Sorry, I read your question very quickly as I was on my way out the door. Will have a closer look when I get back later tonight :)

nevlunghavn commented 3 years ago

I suspect that I'm doing something quite silly and symmetry of the matrix above is confusing me into thinking I've got the correct solution, but I can't see what I'm doing wrong.

I see now that the notation I HAVE USED is actually wrong. I've used the $i$ to calculate the different components of the first eigenvector. This is of course wrong since the $i$ here refers to the first eigenvector and not the components of the first eigenvector. I will do a quick and dirty calculation of the second vector and compare and report back.

nevlunghavn commented 3 years ago

OK. All is well. The second normalized vector, using the given analytic solution is:

0.417906505941275 0.5211208891696024 0.23192061392432992 -0.2319206139243298 -0.5211208891696024 -0.41790650594127504

Sorry for the confusion and thanks for taking the time to answer.

anderkve commented 3 years ago

Great that you found the mistake. The notation for eigenvectors can indeed become quite confusing -- there's always a lot of indices flying around. :)