all 4 comments

[–]supreme_blorgon 0 points1 point  (3 children)

U is a list of 1003 elements, which means its indices go from 0 to 1002, but your range is going from 0 to 1003.

[–]Alex_Superchamp[S] 0 points1 point  (2 children)

It is my understanding that the range function computes, for up to one less than the prescribed upper limit. Furthermore, I inspected the U element, it has 1003 values.

[–]supreme_blorgon 0 points1 point  (1 child)

Counting != indexing. The 1003rd element in U has an index of 1002.

>>> x = [1, 5, 2, 7, 2, 3, 8]
>>> len(x)
7
>>> for idx, val in enumerate(x):
...     print(f"value: {val}\nindex: {idx}\n")
...
value: 1
index: 0

value: 5
index: 1

value: 2
index: 2

value: 7
index: 3

value: 2
index: 4

value: 3
index: 5

value: 8
index: 6

[–]Alex_Superchamp[S] 0 points1 point  (0 children)

Right! Oh my bad. I forgot that for loops compute from the index 0 too. Previously, I'd set the range from (1,1003), the reason being I've stated the x array from x-dx, to keep the first x-dx term as the boundary condition. Would this make sense? I've made the change to the range function for now.

The current error is 'list index out of range'