anderkve / FYS3150

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

still a little confused about indices #12

Closed nevlunghavn closed 3 years ago

nevlunghavn commented 3 years ago

closing this since it was obviously too silly!

reneaas commented 3 years ago

It's simply a convention. From the perspective of a mathematician, it's irrelevant which number we start numbering elements of a matrix from. That we denote the first element on the first row of a matrix by the indices (1,1) is simply a choice.

From the perspective of a programmer, identifying the same element as with the indices (0,0) makes more sense because that's how the many popular programming languages such as C++ and Python works by default.

Matlab, on the other hand, starts indexing elements by 1 and upwards, which is more in line with the mathematical framework. But there's no deep reason behind it.

If you're a bit unconfortable with the translation between mathematics and programming, that's ok. You'll get used to it. You could always develop the mathematical formalism differently, i.e start indexing of elements from 0. This is easier to translate to code, but means that the index of your final element is always n-1 if you are dealing with n elements. There's nothing wrong with this and translation to the most popular coding languages is straight forward. But your matrix becomes (n-1) x (n-1), so describing the matrix mathematically becomes more tedious.

Bottom line: it doesn't matter.