×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

LOOPING

LOOPING

(OP)
I need some assistance with looping. Specifically I would like to interrogate an array to list the values in it and number of occurrences of each one. Say my array was (0.980 0.982 0.971 0.976 0.977 0.976 0.976 0.975 0.969 0.968), I would like to get a list of the form:-

    0.968 1
    0.969 1
    0.971 1
    0.975 1
    0.976 3
    0.977 1
    0.980 1
    0.982 1
    
The problem for me is that I am having difficulty with understanding Mathcad looping; my Mathcad knowledge is entirely self-taught.

Thanks in anticipation.


 

RE: LOOPING

(OP)
Thanks, Greg. I guess hist is a Mathcad function I'm not familiar with. I'll check it out.

RE: LOOPING

Do so.

But, creating the interv vector automatically is going to be tricky without loops. And the only way I've thought of creating it obviates the need to use hist...

here's what i've got in pseudocode as i don't have Mathcad with loops. untested. Things may need initialising.

sx:=sort(x)

binptr:=0


for xptr:0..(length(x)-1)
 if sx[xptr=interv[binptr
    n[binptr:=1+n[binptr
 else
    binptr:=binptr+1
    interv[binptr:=sx[xptr
    n[binptr:=1
 endif
endfor

This creates an entry in interv for each unique value in x, and then counts the number of occurences of each value.

There is a bit of ugliness for the first bin. It is valid if there is a zero present in x, not otherwsie.

    




 

Cheers

Greg Locock

SIG:Please see FAQ731-376: Eng-Tips.com Forum Policies for tips on how to make the best use of Eng-Tips.

RE: LOOPING

(OP)
Thanks once again Greg. I'll try it at work tomorrow; I don't have Mathcad at home. It's a work matter anyway...

RE: LOOPING

Incidentally this is a nice algorithm for exploring the "Birthday paradox"  

Cheers

Greg Locock

SIG:Please see FAQ731-376: Eng-Tips.com Forum Policies for tips on how to make the best use of Eng-Tips.

RE: LOOPING

(OP)
Hi Greg & "Occupant":

Thanks for taking the time to help. I now have a solution.

Regards,
Louis

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources