Message Boards Message Boards

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

Dynamic Module (book Paul Wellin - prog with Mathematica)

Posted 9 years ago

Hello, Maybe somebody can help me with a problem I encountered when studying the book of Wellin “Prog in Mathem”. In chapter 11 he explains Dynamic Modules and he gives a few examples. At the end of the chapter are the problems. This is one of the questions : Generate 20 random points in the unit square, find the shortest path (FindShortestPath) and plot it. If you click a new set of points is generated and plotted. If I build it static everything works, but not when I put in a Dynamic Module . I tried everything but I don’t have a clue where the problem is. See attach with (5 points)

Wellin gives a solution very different from mine, but I like to understand why mine is not working. Thank you in advance, Chiel Geeraert

POSTED BY: Chiel Geeraert
2 Replies
Posted 9 years ago

Yes , thank you for your answer. You are right, I still don't understand the finer workings of 'Dynamic Module' Best Regards, Chiel Geeraert

POSTED BY: Chiel Geeraert

First make sure you understand Module before using DynamicModule. Once you understand Module, understanding DynamicModule can thought of as a version of module that works with Dynamic.

The first argument to Module are the variables to be localized You'll also probably want to initialize them.

DynamicModule[{coordinaten = {}, kortsteTourIndex = {} , kortsteTour = {}},

If you run into a problem like this, first try solving a simpler version of the problem. The example below shows an Interface that records the points you click on it:

DynamicModule[{coords = {}},
   Graphics[{Point[coords], Line[coords]}, PlotRange -> {{-1, 1}, {-1, 1}}],
   {"MouseClicked" :>  (Print[coords]; AppendTo[coords, MousePosition["Graphics"]])}

For this kind of interface, you might also consider using ClickPane.

POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract