Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X
Hello community
I request your help please with the following problem:
I need to run a for or similar loop that allows me to build a 1x (2N) array, where N is an input value.
That is, the array will always have an even number of rows. On each odd row the routine should place "Px" and on each even row the routine should place "Py".
Thanking you in advance for your help
Solved! Go to Solution.
I made a mistake. You've set ORIGIN t0 1. My program needs a tweak.
Success!
Luc
It seems that the results are not obtained in the positions that it should. For example, 45 would have to be in row 5 and -20 in row 6 and the array should have only 2*N=2*12=24 rows
I made a mistake. You've set ORIGIN t0 1. My program needs a tweak.
Success!
Luc
@QS_10727930 wrote:
I have tried this, pero it doesnt work....
Because your inner j-loop assigns N times an element of one of the input vectors to the very same element P[i,1 of the result vector. So at the end every P[i,1 ends up with the same last element of the input vector.
To fix this you would make the index of the assigned element in Px and Py dependent on i.
You don't need the j-loop. Its also not necessary to initially create the result vector P though doing so may speed up calculation for very large input vectors (which you sure won't provide via a Prime table).
I also like to define O <-- ORIGIN at the top of my programs. But I only do this when creating a utility function which might also be used in worksheets which have the system variable ORIGIN set to different values. Your program does not use O anywhere so you can omit that assignment.
For column vectors its not necessary to provide the second matrix index (column index), you can omit it
So one possible fix would be
Nonetheless I sure would prefer using an utility function like the one which Luc had provided and it sure makes sense making it ORIGIN independent as he did (see his corrected version).
There are many ways to skin a cat and so here are a few more variants of such a function for you to chose from
Feel free to assign O<--ORIGIN in the front of the programs and use O instead of ORIGIN to save some typing and space 😉
Prime 9 worksheet attached