Skip to main content
14-Alexandrite
July 1, 2019
Solved

Problem with defining index

  • July 1, 2019
  • 8 replies
  • 3321 views

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

Best answer by Werner_E

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?


B.png

 

8 replies

25-Diamond I
July 2, 2019

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?

21-Topaz II
July 2, 2019

Hi Faisal

 

First get rid of the equal sign.

Capture.PNG

 

Program needs as defined at least two remaining values i+1 and i+2

You may need to refine the logic.

Capture-2.PNG

 

Cheers

Terry

25-Diamond I
July 2, 2019

@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.

b.png

fahmed-214-AlexandriteAuthor
14-Alexandrite
July 2, 2019

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