cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

vector selection by increments

NSizzle-disable
1-Newbie

vector selection by increments

A new problem!

I wish to create a program which takes a user inputted increment and variable, say p, which is the index number of an x-value af a dataset, X.

The program should then create an array from a start point to (and including) an end point. The start point should be the index number of the corresponing x-value that is displaced half the increment before p and the end point is the index number of the corresponding x-value displaced half the increment after p.

Again, the information is technically confidential but I'll try and mock up some fake data and show you what I've tried so far.

(I'll attach it to a second post)

Thanks,
Neil
49 REPLIES 49

On 8/20/2009 9:32:03 AM, NSizzle wrote:
>Al: for that program, on my pc
>it claims that
>ExtractWindow2(X,5,0.5)= needs
>to be a scalar (an error in
>red)

No idea, it works fine in my computer.

>The lengthier looking
>program you submitted before,
>ExtractWindow I think, worked
>fine though.
>Maybe you could
>re-submit the new revised
>edition in the other
>format?

>Also do you know a
>way of resolving the issue
>mentioned in my previous
>post?

Nope, I don't know what kind of error it can be. I tested that little routine with all the extreme conditions I could imagine and it works fine. Sorry, without a sheet showing the error I can't help you. Please check:

- Data vector X is actually a vector, not a matrix nor a scalar.
- Point "middle" is an integer. The routine does not check that.
- Value of window is positive.

Try tracing the error. I don't think that little routine uses any instruction incompatible with newer versions of Mathcad.

Saludos,

Al

>- Point "middle" is an integer. The routine does not check that <<br> ==> Does not meet Al's specifications.
==> The Mathcad auctioneer does not care.
==> At least: do you understand my work sheet ?

jmG

>I meant a SINGLE column vector as the X data - not two columns<<br>
==> You had a two columns vector in your post, so I reproduced same
==> don't read my post, only the work sheet..
==> please scope your project, what you intend to do.
==> If you have vector from foreign source, post it.

jmG

OK, I think I MAY have it - a massive emphasis on may - but I haven't checked enough to be sure.

I've used the program that Al posted (post 19 of 34) which wasn't working when the window 'went past' the last point in the dataset, X.

However, I looked over it thoroughly - not an easy task for someone as terrible as me at programming - and I think I have traced the (extremely minor) error.

I have changed the line
> while (m <= N) /\ (Xm < Xhigh)

to

> while (m < N) /\ (Xm < Xhigh)

Does this seem correct?


Loads of thanks,

Neil

On 8/20/2009 10:22:07 AM, NSizzle wrote:


...

>I have changed
>the line
> while (m <= N) /\
>(Xm < Xhigh)
>
>to
>
> while (m
>< N) /\ (Xm < Xhigh)
>
>Does
>this seem correct?

In fact there is a bug in that line, but not what you think. It should read:

while (m <= N) /\ (Xm <= Xhigh)

Notice the last relational, it should be 'less that or equal to'.

Please make this test in your machine and tell me the result. Type this statement:

(1>2) /\ last(1) =


^^^^
edited

If you get 0 (zero), your version of Mathcad don't check all the conditional because if the first clause is false then there's no need.

If you get an error, then your version is evaluating the second clause.

In my version of Mathcad the behavior is the first, so the while loop don't give error when it tries to check past the last element, because the condition (m <= N) ends the while loop before the program tries to evaluate Xm.

Saludos,

Al
PhilipOakley
5-Regular Member
(To:Al2000)

Another trick is to use the 'on error' programming construct to catch the issue. (guessing from the description 😉

For example; On Error is commonly used with match() for the cases when nothing is found.

Philip Oakley

On 8/20/2009 9:32:03 AM, NSizzle wrote:
>Al: for that program, on my pc
>it claims that
>ExtractWindow2(X,5,0.5)= needs
>to be a scalar (an error in
>red)

Neil, the only reason I can think for that error is that newer versions of Mathcad don't vectorize relational tests. In Mathcad 2001 one can do:

a <= X <= b

where 'a' & 'b' are scalars and 'X' is a vector, i.e. the test is done in an element by element basis and one ends with a vector of 0's & 1's.

In the attached version of ExtractWindow the test is explicitly vectorized (unnecessary in my machine). Please test it.



Good luck...

Al

P.S. If you still get the error, then probably you are passing a matrix instead of a vector.

>Neil, the only reason I can think for that error is that newer versions of Mathcad don't vectorize relational tests. In Mathcad 2001 one can do:<<br> ---------------------
Such a basic operator that makes up for a great part of Mathcad, that it had been scraped in 14 ... I don't think so, the first time it is supposed in this collab. Here is a hard test for you both, left in that blue discussion. Consider this real life data set V, not consecutive values and some replicated values. Should work for all versions 2001 ... 14.

jmG
RichardJ
19-Tanzanite
(To:Al2000)

On 8/20/2009 12:01:29 PM, Al2000 wrote:

>Neil,
>the only reason I can think for that
>error is that newer versions of Mathcad
>don't vectorize relational tests.

I've been too busy to have followed this thread, but that is indeed the problem. Your new program works in all versions, and appears to do exactly what Neil wants.

Richard

On 8/21/2009 8:41:23 AM, rijackson wrote:
>On 8/20/2009 12:01:29 PM, Al2000 wrote:
>
>>Neil,
>>the only reason I can think for that
>>error is that newer versions of Mathcad
>>don't vectorize relational tests.
>
>I've been too busy to have followed this
>thread, but that is indeed the problem.
>Your new program works in all versions,
>and appears to do exactly what Neil
>wants.
>
>Richard
___________________________________

My reply does not concern what Neil wants or might want as we don't know the original and eventual full scope. What I'm saying is that it fails miserably my simple test passed previously for those interested in the "working tool". I don't pretend that the original Mathsoft will not get hurt eventually, but it has been used in all sorts of soup mostly by myself and passed dozens of times in about all possible variants and has never failed. Repeated values and their location are certainly important for any kind of application.

Enjoy this "QED ad absurdum" ... end of it.

jmG

On 8/22/2009 12:39:23 AM, jmG wrote:

...
>Enjoy this "QED ad absurdum" ... end of
>it.

Jean, sometimes I wonder if you really understand some of the things you post in the collaboratory. Do you really understand what you are doing in this routine? I can understand how confused is Neil (assuming he's really a novice in programming). C'mon, you even confused me and I have programmed for 30+ years in a dozen of different programming languages.



- First you're doing the test defined in the function 'c(x)'. So you're getting a vector of 0's & 1's that means which elements of 'V' falls within the range 'base +- n'. So far so good, that's what Neil asked, even when you had not extracted the value of 'base' from the desired element in vector 'V'.

- Then you multiply 'c(V)' by 'V'. By doing this you set all the "undesired" values of 'V' to zero to be dropped later. Notice that this procedure will fail if the value zero is a valid value.

- Finally you pass the resulting vector 'w' to the routine 'Drop' where you apply another selection, filtering again the data with the condition set in 'q(x)'.

Do you really think this is what Neil asked? Don't you think you better do simply 'vx:=Drop(V,c)'?

Please don't take this as a personal attack, I'm just trying to tell you that you must settle down and think a little in your 'auctioneer' routine and what it really does.

With respect to my routine failing with unsorted data, just remember that every program is a SISO queue, if you know what I means...

Saludos,

Al

"So far so good, that's what Neil asked"
That ends your long comments. Conserve preciously as is in case it fails in unknown situations, yet. Just render the "home project part" that gets good marks "as asked so far so good".

jmG
PS: 30 years programming in dozens of languages should make easy to correct your primes.

On 8/22/2009 6:22:31 PM, Al2000 wrote:
>Jean, sometimes I wonder if you really
>understand some of the things you post
>in the collaboratory. ...
>Saludos,
>
>Al
__________________________

I surely do, with few more examples constructed around the "vectorize operator" and the "conditional statement" that "so far so good as asked" solves the project proposed. Mathcad is not a programming language, rather an oriented hybrid CAS. Unfortunately, your version 2001 does not have much adepts anymore in this collab. If anything turns red in the attached, then no point to show you more about using Mathcad.

jmG

... below Marlett,
another most precious tool: the adjacent extractor.

jmG

On 8/23/2009 12:43:16 AM, jmG wrote:
>... below Marlett,
>another most precious tool:
>the adjacent extractor.
>
>jmG
___________________________

Forgot you don't have the slider,
set p:=128 (typical)

jmG



On 8/23/2009 12:59:44 AM, jmG wrote:
>On 8/23/2009 12:43:16 AM, jmG wrote:
>>... below Marlett,
>>another most precious tool:
>>the adjacent extractor.
>>
>>jmG
>___________________________
>
>Forgot you don't have the slider,
>set p:=128 (typical)
>
>jmG
>..........................

Again, for this last example, whereas you don't have the slider, set FRAME some integer values within the range of X and see where the prescribed 't' locates between the two nearest values of X. You have to set "Backward compatibility" and maybe plug in a blank work sheet. I think that should end this lavish tutorial about using the Mathcad native and most versatile functionalities.

jmG

On 8/23/2009 12:43:16 AM, jmG wrote:
>... below Marlett,
>another most precious tool:
>the adjacent extract

I appreciate your efforts to showing me the best of Mathcad.

Here a couple comments from a programer to a CAS user 🙂

Saludos,

Al

On 8/23/2009 3:51:31 AM, Al2000 wrote:
>On 8/23/2009 12:43:16 AM, jmG wrote:
>>... below Marlett,
>>another most precious tool:
>>the adjacent extract
>
>I appreciate your efforts to showing me
>the best of Mathcad.
>
>Here a couple comments from a programer
>to a CAS user 🙂
>
>Saludos,
>
>Al
________________________________________

My comments over your comments. Through the years, I have adapted 1000's Mathsoft/collabs proposals, you are at liberty to adapt and use any of mines as they are. Just be careful when detracting a collab that you don't detract yourself as demonstrated in the attached ... and that's what you did as a programmer who need understand more how to mingle/merge the Mathcad structure as applicable.

Saludos amigo.

Jean

Back to your 1rst thread that generated 48 replies,

http://collab.mathsoft.com/read?127437,21e#127437

you have a very long explanation that is at most confusing or maybe not feasible (?) or does not make sense. Please read carefully this last attachment as my last visit unless you need some specific supplementary details and you have made your mind.

jmG

... in this collab, your project "by selection" is the 4th major one done (?). The other 3 ones were called "by exception". All done correct with as great elegance as yours, except that yours is not clear as you have described and illustrated. Understanding a project goes by what prints in mind paralleled with Mathcad. Not so easy sometimes.

jmG
Top Tags