Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.7K Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How do I apply boolean test to each entry / matrix element?

Posted 12 years ago
POSTED BY: Jack Dough
2 Replies
Posted 12 years ago
POSTED BY: Jack Dough

I follow your code up to MultiValuedTest. In MultiValuedTest what is the purpose of diff (which is simply 0 there, so MultiValuedTest could just be defined to be state>0) and where is a dependency of MultiValuedTest on x on the right hand side? Also--just a quick comment on coding--you should define MultiValuedTest in terms of a delayed evaluation (:=) instead of immediate evaluation(=). And Return is never necessary: Mathematica returns the final result of a sequence of expressions.

However, if your question is how to apply a function to the elements of a matrix you can use Map.

For example, here is a random 5x5 matrix:

mat = RandomReal[{0, 1}, {5, 5}]

And you can use Map to apply a function f to all its elements individually in this way:

Map[f, mat, {2}]

If this is not your question could you clean up your code so that it works and then rephrase?

POSTED BY: David Reiss
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard