How do I declare and call array in PARI/GP?
For example, I have the following in java:
int[] myArray = new int[5]; for(int i = 0; i < 5; i++){ myArray[i] = i + 5; }
How do I do the same thing while using PARI/GP?
The usual way is
myArray = vector(5, i, i+4);
where I have replaced i+5 with i+4 because GP vectors are 1-based, not 0-based.
i+5
i+4
You could also do
myArray = vector(5); for(i=1,5, myArray[i] = i+4);
if you prefer. (This is useful in some cases, e.g., when you want to refer to earlier values in the array.)
x = []; for (i=1,10, print("test " i ": " x[i]))
The usual way is
where I have replaced
i+5
withi+4
because GP vectors are 1-based, not 0-based.You could also do
if you prefer. (This is useful in some cases, e.g., when you want to refer to earlier values in the array.)