|
|
|
|
|
by princeb
3311 days ago
|
|
any kind of numerical method (RKs, FDs, CN) where the n-th step a_n = f(a_(n-1)) and hence you define NUM_STEPS and the the result is a[NUM_STEPS] where a is your numerical lattice. you could work in a 0-based index and your n-th step is a_(n-1) and so the final step is a[NUM_STEPS - 1] in numerical analysis I don't believe i've ever cared that much about slicing. if i wanted to look at a single element in a matrix a_(ij), then I call the matrix a[i,j]. if you had to implement a pivoting algorithm then it's quite useful to call the pivot element a[i,j] and pivot row a[i,:]. i believe most devs would prefer not to have to call elements everytime a[i-1,j-1]. guessing most math guys have worked with both 0 and 1 systems and honestly don't care that much. |
|
For an iterative method, you have an initial value a[0], then take your NUM_STEPS steps, so the final result is a[NUM_STEPS]. If it's one-based, the final result is a[NUM_STEPS+1]. This type of thing trips up my Matlab (one-based) students all the time.
In zero-based linear algebra, the indices i and j start at 0, so the top left entry of a matrix is a[0, 0], the pivot element is a[i, j] and the pivot row is a[i, :]. There isn't any adjustment needed.
Finite differences, Simpson's Rule, etc., seem more natural with zero-based too. x_0 is the left-most value, x_n is the right-most value, and the interval is divided into n pieces.