Message Boards Message Boards

3 Replies
2 Total Likes
View groups...
Share this post:

Questions about the code signs in Mathematica: @, #, / ?

Posted 11 years ago
checkIfOn := (Select[# < 0.1 & /@

      scaledTrajectory[[iterator ;; iterator +2]], # &] // Length) == 0
I am very confused by this code, what does "# < 0.1 & /@"
mean, here the scaledTrajectory[] just means a table of numbers. I could find "#" meaning, but just cann't figure this code's meaning out. I would appreciate it very much if anyone could help.  
POSTED BY: Sishen Chen
3 Replies
This is perhaps more easily seen as:
checkIfOn := (Select[Function[{x}, x < 0.1] /@ scaledTrajectory[[iterator ;; iterator +2]], Function[{x}, x]] // Length) == 0
That is, "select, from the True or False outputs we get on testing whether each of these three scaledTrajectories is less than 0.1, those which are identically the symbol True; find the length of what we just output; see whether it's equal to 0".

It is much more neatly phrased as:
MemberQ[scaledTrajectory[[iterator ;; iterator + 2]], _?(# < 0.1 &)]
POSTED BY: Patrick Stevens
Many of these cryptic characters are in the documentation. The descriptions can help,
or at least give suggestions for what to look under.
 In[1]:= ? /@                                                                           
 Map[f, expr] or f/@expr applies f to each element on the first level in expr.
       Map[f, expr, levelspec] applies f to parts of expr specified by levelspec.
 In[2]:= ? #                                                                           
 # represents the first argument supplied to a pure function.
     #n represents the n'th  argument.
In[3]:= ? &                                                                           
Function[body] or body &
       is a pure function. The formal parameters are # (or #1), #2, etc.
      Function[ x, body] is a pure function with a single formal parameter x.
     Function[{x1 , x2 , …}, body] is a pure function with a list of formal parameters.
POSTED BY: Bruce Miller
Posted 11 years ago
An expression containing # (and perhaps a few other special characters) and ending with an &
is a shorthand notation for definining a function without giving it a name. This tutorial might help
you begin to get an idea how this works, but it sometimes takes some study and practice to be
able to understand this notation when you see it used.
POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract