Tag Info

New answers tagged

1

After some further experimentation it turns out that the sluggishness of the locators in the LocatorPane can be overcome by eliminating the explicit Return statement from the PlotLabelerFunction. I changed the code as follows: (* updated Dynamic Overlay Code *) Dynamic[ Which[ (* this Which statement is used for responding to toggling of label ...


0

This undocumented error appeared as a pop-up on a red-boxed control (in this case, an iterator [but not a float iterator!]) where the setting for the control depended on an initialization section which timed out because of a non-terminating computation.


1

Here's my attempt at achieving what you describes. 1) I define a display function that takes n as the number of randomly generated locators (initLoc). It also takes a list of speeds v between those locators. The rest of the function is figuring out at what time a particle will reach a particular locator (locatorTimes) given its average speed and the locator ...


2

I apologize for the quality of this answer: unlike Jens I did not bother to correct errors. I would like to illustrate that even when the first argument of Graphics is invalid the layout engine can still render the size and aspect ratio the expression of these are given: Graphics["foo", ImageSize -> {50, 200}] Graphics["bar", ImageSize -> {200, 50}] ...


4

One of the difficulties in your first approach is that you're trying to use Plot to dynamically generate rectangles. It would be easier to use graphics primitives for that. However, I'll assume that you have a reason to use Plot, so let's simulate the two plotting functions more clearly (one of them with a Pause to indicate its delay). I define two plotting ...


1

Another apporach is to make a Manipulate that does what you want. For example, here is one that draws a polygon. Whenever you move the points of the left polygon, the one on the right moves in mirror symmetry. Manipulate[Graphics[{Polygon[p], Red, Polygon[ConstantArray[{10, 0}, 4] - p]}], {{p, {{1, 1}, {2, 2}, {-1, 1}, {-2, -2}}}, Locator}]


4

This solution may generate a storm of criticisms but may also give you an idea of a path to follow to get where you want. Note that this solution works perfectly in Mathematica 9 but in Mathematica 10 there is a problem that is preventing the last Graphics object added to copy to the right side with the right colors. g = Graphics[{Yellow, Disk[]}, ...


1

Use SetDelayed ( := ) to define x. n = 4; Row[{SetterBar[Dynamic @ n, Range[10]], "Length of x"}, Spacer[20]] x := Table[ToExpression["x" <> ToString @ i], {i, 0, n}] Dynamic @ x


0

Applying Mathematica's functional programming tools to your problem makes the definition of your function f a one-liner. Note that I give the function argument x a real semantic role in f. n = 1; f[x_] := Nest[Append[#, #[[-1]] + 2 #[[-2]]]&, {x, x}, n + 2] SetterBar[Dynamic @ n, Range[10]] Dynamic @ f[1] {1, 1, 3, 5, 11, 21, 43} If you were ...


3

As mentioned in the comment by Pickett, you have to wrap Dynamic around the expression that is to be displayed. You also forgot to return a value from your function f. Here is a modification of your code that works: Clear[f] f[x_] := Module[{y}, y = Table[0, {i, 1, n + 4}]; For[i = 3, i <= n + 4, i++, y[[i]] = y[[i - 1]] + 2 y[[i - 2]]]; y] n = ...


4

This can be done more cleanly by localizing curve to the manipulate, which in turn is done by making curve an invisible control. This also obviates the need for the Initialization option, because controls take optional initializers. Manipulate[ Graphics[{ {Red, PointSize @ .02, Point@pt}, Line @ AppendTo[curve, pt]}, Axes -> True, ...


2

Replacing the Set in Initialization by a SetDelayed solved the problem, TrackedSymbols should be set also. Conjecture: It seems Clear before Manipulate produces problems, I can't believe it. It can be used in a separate cell, but not in the same cell. Experiences? Manipulate[ curve = Append[curve, pt]; Graphics[{{Red, PointSize@.02, Point@pt}, ...


2

Pardon me if this is unjustifiably curt but I don't see how this problem is different from many others that result from placing Dynamic too deep within an expression. Move the Dynamic to the outside and the element in question updates just fine: on = True; Row@{Checkbox@Dynamic@on, Spacer@10, ExpressionCell[ Dynamic@RawBoxes@ RowBox@{"Block", ...


2

The last three locals are actually String, i.e. "\"local\"" at the box level. The fourth from the end, however, should be due to lacking of syntax highlight at the FrontEnd. For this problem, I guess you'll have to force the FrontEnd re-render the ExpressionCell after each update of the on. Usually this can be done by changing an option of the cell (like ...


6

An alternative approach using CurrentValue["MouseOver"]: Button[Panel["Print", FrameMargins -> {{4, 4}, {4, 4}}, Background -> Dynamic@If[CurrentValue["MouseOver"], Green, Red]], Print["Print"], Appearance -> None] or, without the Panel, Button["Print", Print["Print"], Background -> ...


3

Another method which doesn't really use Mouseover but the EventHandler: DynamicModule[{col = Red}, EventHandler[ Button[ Panel["Print", FrameMargins -> {{4, 4}, {4, 4}}, Background -> Dynamic[col]], ...


3

The Plot has to be within Dynamic, as the Plot needs to be updated when z is changed. You can't just update the content of Plot without making a new Plot. {Slider[Dynamic[z], {1, 4, 1}], Dynamic@Plot[Evaluate[Table[Sin[i*t], {i, 1, z}]], {t, 0, 2 Pi}]} The syntax highlighting is due to the Head of your command inside Plot being Dynamic ...


1

There are lots of ways to do what you want. I would not use Module. Here are three, all of which use methods other than Module to localize variables: SeedRandom @ 42; With[{rand = RandomInteger[10, {5, 5, 2}]}, Manipulate[ ListPlot[rand[[i]], PlotRange -> {{-1, 11}, {-1, 11}}], {i, 1, Length[rand], 1, Appearance -> "Labeled"}]] SeedRandom @ ...


1

if you need to keep the definition of l inside manipulate, I think you can try this Manipulate[l = RandomInteger[10, {3, 5, 2}]; ListPlot[l[[i]], PlotRange -> {{-1, 11}, {-1, 11}}], {i, 1, Dynamic@Length@l, 1}] you need to know that for every i, l will be computed again and again. if you want to do 3 plot per each l then you can do it like this ...


1

I found an answer to my own question by reading the answer to Make dynamic controls from existing list. So I guess the answer to my question is to define the functions internally in the dynamic module with the HoldFist attribute. DynamicModule[{controlGenerate, ruleslist = ruleslist, ruleslist2 = ruleslist2, result, controlfromList}, ...


0

This is a good case to demonstrate how inefficient could the magic of Dynamic be. Evaluating the code below shows how many times Dynamic refreshes your plot. Click on the buttons to see. p1 = {{0.98, 1.02}, {1.29, 1.46}, {1.45, 1.8}, {1.69, 1.83}, {2.01, 2.43}, {2.07, 2.43}, {2.39, 2.5}, {2.71, 2.99}, {3.03, 3.51}, {3.33, 3.54}, {3.9, 3.91}, ...


6

Here's one solution that meets the criterions. I'll walk through the main ideas step by step. First I started by creating a list of circles and a list of lines. Then I formed a region from those elements, which I called grid. I also added the gridlines that were used originally and so recreated the plot: circles = Table[Circle[{0, 0}, r], {r, 1, 14}]; ...


0

The following lines copied from the documentation system seem to point at what you need to solve your problem: FrontEndDynamicExpression->Dynamic[expr] causes the expression to be tracked and updated in the usual way, except that expr is not displayed anywhere. FrontEndDynamicExpression can be set using ...


1

The example below shows the effects of forcing a unitary step size in the manipulator in the application you created. The table is filled as expected but there is an uncomfortable lag in the manipulator. I created this example to support the following statements. I think that Manipulator really doesn't need a new option but that programmers need to adjust ...


3

Here is some code to get you started. I say "started" because this isn't a fool-proof solution. For one thing, it doesn't provide a way to retract a segment should the user make an bad drag. There are also some refresh issues to be dealt with. A full solution will a fair amount of additional work, and I don't have time to work it out right now. cnt[p_] := ...


7

This is a very common problem for people who work on data analysis. Here as a solution to the problem using LocatorPane and a few other functions and tricks. TooltipListPlot[data_, tipFunction_, listPlotOptions___] := DynamicModule[ {displayQ = False, yRange , xRange, pt, minX, maxX, minY, maxY, tip, threshold, tipPosition, nf, dataPoints, ...


0

Maybe this is also an acceptable approach depending on your needs. asd=1; {Slider[Dynamic[asd, (asd = If[# <= 10, #, Round@#]) &], {1, 50}], Dynamic@asd}



Top 50 recent answers are included