Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Jul 01, 2019
06:18 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 01, 2019
06:18 PM

Problem with defining index

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.

Labels:

1 ACCEPTED SOLUTION

Accepted Solutions

Jul 02, 2019
05:40 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 02, 2019
05:40 AM

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?

8 REPLIES 8

Jul 01, 2019
09:39 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 01, 2019
09:39 PM

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?

Jul 01, 2019
09:44 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 01, 2019
09:44 PM

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

Jul 01, 2019
09:54 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 01, 2019
09:54 PM

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

Jul 02, 2019
12:11 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 02, 2019
12:11 AM

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

Jul 02, 2019
05:40 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 02, 2019
05:40 AM

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?

Jul 02, 2019
06:10 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 02, 2019
06:10 AM

Thank you very much. I think this is the one I needed

Jul 02, 2019
08:52 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 02, 2019
08:52 AM

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

Jul 02, 2019
10:26 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Notify Moderator

Jul 02, 2019
10:26 AM

Thank you again