Message Boards Message Boards

0
|
6776 Views
|
4 Replies
|
4 Total Likes
View groups...
Share
Share this post:

[collective thread] arbitrary WLDC example — Questions?

Most example codes in the WLDC are so well-chosen and instructive/didactic/educational/helpful that the one-liner is not accompanied by sufficient but concise or "none" explanation. And only on very rare occasions would we stumble over example code which we really "don't get" (the point/purpose/intention/reason d'etre/function) - basically these are examples which should have gotten improved code or better/more explanations in order to make the reader understand.

Maybe it is a good idea to question some arbitrary given example which you have come across while studying the WLDC? In a collective effort we could point out questionable examples (and comment on the post with the according Reply-button) and possibly suggest improvements to code or text. This thread is not primarily about reporting typos/errors/bugs but they could be part of the problem why we don't get the example, sometimes.

For easy reference, let's include the documentation reference URL of the function and also indicate the examples subsection where to find the referred example. I have bookmarked & memorized this thread URL for convenient access/future additions under:

https://tinyurl.com/wldcexample

POSTED BY: Raspi Rascal
4 Replies

Double click on the output to switch to editing/drawing mode and drag the point around.

Yes, that is not obvious.

POSTED BY: Kuba Podkalicki

Let me start with this example from the WLDC:

Dynamic[ ] > Applications > 1st example:

Constrain the coordinates of a point to lie on a circle:

DynamicModule[{p = {0, 1}}, Graphics[{
   Dashed
   , Circle[]
   , PointSize[0.1]
   , Point[ 
     Dynamic[p, (p = Normalize[#]) &] 
   ]
  }, PlotRange -> 1.2, Axes -> True, ImageSize -> Tiny]
]

Comments:

  1. The text is clear, it makes the intention clear. Or at least I think so. Well, I am understanding: We want to constrain a (given? any? dynamically given? interactively given?) point to lie on the circle (radius 1, center at {0,0}).
  2. Where can we observe the dynamics? Or where is the interactivity? The initial point is given with {0,1}. This point already lies on the unit circle! And the point cannot be moved or anything with my mouse. So i really don't see any dynamics or interactivity here.
  3. To constrain a point to lie on a circle with some dynamics, maybe the function Locator[ ] should have been used in the code?
  4. Maybe this example is not to demo interactivity with the mouse or any kind of dynamics? However, edit the code and use the point p = {-1, 1} in the module initialization. You will see that the point is drawn outside the circle, i.e. neither the function Dynamic[ ] nor Normalize[ ] do their job. Seems like.

At this point it is impossible for me to suggest an improved code and/or text which makes this example (input and output) clearer to the reader, because i clearly seem to be missing something. What am i missing here?

POSTED BY: Raspi Rascal

Hello Kuba, thanks for the pointer. Yes, now i can see what is happening there, the dynamics, the functionality of the code. Wow.

Many subtleties and implications regarding the Dynamic[ ] command are still half a mystery to me but i'll just have to re-read the respective documentation over and over again until it all falls into place, i hope ;-) .

POSTED BY: Raspi Rascal

Infix usage of Composition[]. Have you ever wondered what the difference between @ and @* is, when even the documentation shows that they have the same effect, see 'Different ways of entering compositions' in 'Properties & Relations', also 'Basic Examples'? Imho the documentation should show the opposite, the difference! It is true that in most instances the one can be replaced by the other so i always wonder (and the doc page wouldn't clarify).

However i found a useful example where you must use the Composition infix:

In[1]:= nx = {3, 2, 5, 3, 1};
ny = {1, 3, 2, 2};
Outer[Total@List, nx, ny] // Quiet(*doesn't return desired result*)

Out[3]= {{Total[List][3, 1], Total[List][3, 3], Total[List][3, 2], Total[List][3, 2]}, 
  {Total[List][2, 1], Total[List][2, 3], Total[List][2, 2], Total[List][2, 2]},
  {Total[List][5, 1], Total[List][5, 3], Total[List][5, 2], Total[List][5, 2]}, 
  {Total[List][3, 1], Total[List][3, 3], Total[List][3, 2], Total[List][3, 2]},
  {Total[List][1, 1], Total[List][1, 3], Total[List][1, 2], Total[List][1, 2]}}

In[4]:= Outer[Total@*List, nx, ny](*returns desired result*)

Out[4]= {{4, 6, 5, 5}, {3, 5, 4, 4}, {6, 8, 7, 7}, {4, 6, 5, 5}, {2, 4, 3, 3}}

Hope you found this tidbit yummy, thanks for looking!

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

Group Abstract Group Abstract