Community Tip - Did you know you can set a signature that will be added to all your posts? Set it here! X
Hello,
I am trying to generate a vector based on certain conditions but I face with a problem that says as" This range should be defined in sequential values". In my understanding, I think I have done that but I do not know why it is showing the error. Please help me with it. My version is prime 4.0
Thanks,
Faisal
Solved! Go to Solution.
Sorry, that explanation is not clear to me, especially he "negative domain" in 4).
Your program ignores the first value of your vector I, sets result to a1.
Then it sets result to a1 as long as the value of the next I's is positive.
If an I is negative, result is a3 and then the next values of I are looked at in the for-loop EVERY TIME a value in I is negative.
So results already assigned are overwritten again and again.
Can you explain which output vector you expect using your sample data I (and maybe a few more I's to make it clearer) and why?
BTW, is this something near to what you are looking for?
In your example last(I) = 5.
Si i runs from 1 to 5.
If i=4 the you define j € 5,6 .. 5 which seems to be wrong but it works in Prime and gives you just i=5
But if i=5 you define j € 6,7 .. 5 and this is it what throws that error because "6,7" means to count upwards but the end value 5 is lower than the start value.
A workaround could be to let i run from 1 to i-1 but I fear that your routine has some other errors, too as the nested loops incessantly overwrites values in "result" which dies not make much sense to me.
What is the routine intended to do?
Hi Faisal
First get rid of the equal sign.
Program needs as defined at least two remaining values i+1 and i+2
You may need to refine the logic.
Cheers
Terry
@terryhendicott wrote:
First get rid of the equal sign.
Not really necessary as he is defining a simple variable, not a function. Nonetheless is generally a good advice to avoid inline evaluations as Mathcad/Prime had some problems with that in the past (especially in combination with matrices).
Program needs as defined at least two remaining values i+1 and i+2
No need to decrement the end value by 2, running i from 1 to last(I)-1 is all thats needed. As I explained above the routine/range works OK if i = last(I)-1
But I fear that there's more wrong with this program because it overwrites values in a manner which I suspect is not intended hat way.
My intent from the program is as follows :
1) First, it will assign the first result as a1
2) Second, it will assign the results based on the sign of "I"
3) If the sign of "I" is positive it will assign a1 and will continue till the last "I", if not then it will assign a3.
4) Once the condition enters the negative "I" domain, it will continue inside the negative "I" domain with the given condition that is given there. This will continue till the last "I".
So, finally, if "I" has n values then the result will have n+1 values
Sorry, that explanation is not clear to me, especially he "negative domain" in 4).
Your program ignores the first value of your vector I, sets result to a1.
Then it sets result to a1 as long as the value of the next I's is positive.
If an I is negative, result is a3 and then the next values of I are looked at in the for-loop EVERY TIME a value in I is negative.
So results already assigned are overwritten again and again.
Can you explain which output vector you expect using your sample data I (and maybe a few more I's to make it clearer) and why?
BTW, is this something near to what you are looking for?
Thank you very much. I think this is the one I needed
@fahmed-2 wrote:
Thank you very much. I think this is the one I needed
I love my Crystal ball 😉
To make it clear, the logic behind my function is:
.) First element in result vector always is a1
.) Now we go through the whole vector I. If the element there is positive, we add an element a1 to our result, otherwise a3
.) The above is true until we come to the first negative Element in I. From then on, the game changes a little bit as positive elements in I result in a2 (and not a1) to be added - negative element still yield a3.
You may get rid of the variable "negative" in my function and use a3 instead. And of course you don't have it to be a function if you don't like that but turn it into a simple variable as you had it originally.
Thank you again