×
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

New with MathCad

New with MathCad

New with MathCad

(OP)
Guys, I could use a little help.  I am trying to learn MathCad and have come up on something I need a little help with.  I have a matrix as shown below.

    A  =   1   1
           0   0
           0   0

I need to coun the number of "1"s and the number of "0"s.  I set variables named NumFree and NumRest to zero.  If A i,j is one, then I want to add 1 to NumRest.  If A i,j is zero, I want to add 1 to NumFree.

Any help would be greatly appreciated.

 

RE: New with MathCad

Possibly the simplest method is to use the summation and vectorize operators. Try

NumFree:=sum(vectorize(A=0))
NumRest:=rows(A)*cols(A)-NumFree

where
sum represents the vector sum operator ([ctrl]4)
vectorize(A=0) represents the vectorize operator ([ctrl]-) applied to the expression A=0, where = is the boolean equals ([ctrl]=)

RE: New with MathCad

ex - you are assuming that 0 and 1 are the only valid elements. The OP does not explicitly state this.

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: New with MathCad

For instance

0 1
0 2

Has too 0s, and one 1

your method would give the wrong answer

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: New with MathCad

Greg,

I'm guessing from the variable names that NumFree is meant to count something that is available, in the sense of 'not taken' (or doesn't cost anything!) and zero is the measure of that state.  NumRest I took to be 'The rest of them' in which case, what I propose should work - count the zeros (NumFree) and take that number away from the total number of elements to get the Rest.

However, you're quite right; without a full quantification it is simply guess work.

RE: New with MathCad

(OP)
Guys, thanks for the help.  The only numbers in the matrix will be 1's and 0's.

Thanks again

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