Tag Info

Hot answers tagged

13

Based on Mr.Wizard's answer and Szabolc's comments to it, I now understand that the code I posted does have undesirable side-effects and it should be avoided. Specifically, the scoping constructs Module and Block are meant to completely localize the variables in their first argument (for more information see this question). However, placing their scoped ...


11

One way is to create a Polygon and transform the vertices under the flow. I used NDSolve to solve the flow for initial points in a square containing the OP's disk. Then I made a listable Function that can be applied to a the vertices of the polygon. Since only the flow depends on the time t, I used a GraphicsComplex so that the vertices come first as a ...


10

Here's a fairly simple way to fix your Manipulate by applying Dynamic to ListPlot. Manipulate[ (* Beep[]; *) data = function @ Range[-Pi*10., Pi*10, Pi/1000]; Dynamic @ ListPlot[data, PlotRange -> {{start, stop}, Automatic}], {function, {Sin, Cos, Tan}}, {start, 1, Length[data]}, {{stop, 300}, 1, Length[data]}, {data, ControlType -> None}] ...


10

Thanks to Michael E2's comment, the following approach is successful. The method sets up a scheduled task that (at certain resolution res) monitors the elapsed $time and compares it to the dynamic $max. If $time is more than allowed by $max, it calls the front-end "EvaluatorAbort". Attributes[dynamicTimeConstrained] = {HoldAll}; ...


10

Dynamic has this build into it. You can take advantage of the Dynamic second and third arguments. The second argument of evaluate as the dynamic is being updated. The third argument is evaluated when the mouse is released. Which is what you want. To illustrate, here is an example, where f[r] and g[r] are inside the arguments of the slider itself. This is ...


9

I would approach this problem a bit differently. I would provide each such notebook with an initialization button at its top, right under its title, if any. By pressing this button, the dynamic apdating would be enabled. How to do it technically, is already in the comment of belisarius. The further is only a question of a design. The latter should be ...


9

ControlActive is useful for this purpose: DynamicModule[{r = 1, old = 1} , Grid[ { {Slider[Dynamic[r]], SpanFromLeft} , {Dynamic[f[r]], Dynamic[g[ControlActive[r, old = r]; old]]} } ] ] The variable old has been introduced to hold the "old" value of r. The key expression is ControlActive[r, old = r]; old, which always returns the value of ...


8

Yes, it is a bug. I am quite confident it will be fixed in an upcoming release.


8

Note that you've defined t as a Dynamic expression. A relational operator like GreaterEqual (>=) works with numeric expressions like the result of Clock. You could try something like this to get a displayed output that eventually switches from False to True: step = .1; Dynamic[{t, t = Clock[{0., 5., step}, 5., 1]; t >= 2}]


7

In such cases, you can get better flexibility by switching to a DynamicModule and building up the GUI yourself. Then, you can pull the data generating step out of the plotting dynamic, so that the latter can be manipulated freely without regenerating the data. DynamicModule[{function = Sin, start, stop = 300, x = Range[-10 Pi, 10 Pi, Pi/100]}, ...


7

This is good reason to use the second argument of dynamics. Manipulate[ function; (*just to allow tracking, since not explicity in the command*) ListLinePlot[data, PlotRange -> {{start, stop}, Automatic}, ImageSize -> 300, ImagePadding -> 30, Frame -> True, FrameLabel -> {{None, None}, {"x", function}} ], Grid[ { ...


7

I believe that Mathematica feeds the input string in free-form linguistic input to the function WolframAlpha. Try something like Manipulate[ If[in =!= "", WolframAlpha[in], "Enter input"], {{in, ""}, InputField[Dynamic[in], String] &} ] Response to comment I can't find a definitive statement in the documentation that an internet connection is ...


7

Here's a trivial example of the method in my comment. I've used total absolute difference for error (you can use whatever you please), and I put in a Pause so you can observe the effect for this trivial problem that would be blink-of-an-eye fast. In reality, you'd want to use UpdateInterval or equivalent, or Sow if you want the "history" post-run. Doing ...


7

The reason for this behaviour is that as soon as the cursor gets away from a particular vertex marker it leaves the associated EventHandler. Here's a work-around, let's associate the event handler with the whole Graph. We just need to take care of updating the proper pos. DynamicModule[{ind = 1, pos1 = {1, 0}/2, pos2 = {1, 1}/2, pos3 = {-1, 0}/2}, ...


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, ...


6

This should work: rows = 3; cols = 4; data = RandomInteger[{1, 100}, {rows, cols}]; names = {"First", "Second", "Third", "Fourth"}; sortBy[data_, idx_] := If[idx == 0, data, Sort[data, #1[[idx]] < #2[[idx]] &]]; Dynamic@Grid@Prepend[data, Array[Button[names[[#]], data = sortBy[data, #]] &, cols]]


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}]; ...


6

What I really wanted to post was an alternative way of generating the grid. In my humble opinion, it's better to do it with Table without Partition as it looks better in code. But since Animate has already been dealt with, three times over, let me also use an alternative method for that: color[n_] := Style[n, Which[100 Clock[1, 10] < n, Black, PrimeQ@n, ...


6

You don't have repeat yourself. You can map a pure function defining the button over a list of the background colors and then apply Mouseover Like so: Mouseover @@ (Button[Panel["Print", FrameMargins -> {{4, 4}, {4, 4}}, Background -> #], Print["Print"], Appearance -> None] & /@ {Red, Green})


6

Expanding a little over rasher's answer: data = Table[{x, Log[3.5 + 2.5 x^2] + RandomReal[{-1, 1}]}, {x, 0, 10}]; r = {}; s = {}; u = {}; Dynamic[ GraphicsGrid[{{ Plot[Log[r[[-1]] + s[[-1]] x^2], {x, Min@data[[All, 1]], Max@data[[All, 1]]}, PlotLabel -> "Fitting", Frame -> True, Epilog :> {Red, PointSize[Medium], ...


6

Perhaps something like this? text = ""; EventHandler[ InputField[Dynamic@text, String, ContinuousAction -> True], {"ReturnKeyDown" :> Paste["\n"]} ]


6

The problem seems to be that a TagBox that is generated is handled incorrectly by the front end. The TagBox has the form TagBox[bigExpr, Deploy, DefaultBaseStyle -> "Deploy"]. In this expression the second argument Deploy is quite meaningless. I couldn't trace any further than this TagBox as I cannot see how the front end handles it. How the kernel ...


6

In your example the resolution of image is going to zero with number of points and you will see the scattered field after addition of some dozens of thousands of points.. What is the sense of such drawing and moreover the sense of dynamic updates of such graphics? May be it is better to use something like this, with pre-defined size: data = Table[0, {i, ...


6

This appears to be a front-end bug involving the evaluation of arrays and built-in functions within a DynamicBox. The original example can be made to work by defining max = Max; and using the user function max in place of the built-in functionMax: max = Max; DynamicModule[{s = 1, q = {{False}}}, {Checkbox[Dynamic[q[[1, 2 - max[s, 0]]]]], Dynamic[q[[1, 2 ...


6

I believe that highlighting is there specifically to encourage you to use DynamicModule rather than Module: DynamicModule[{A = 1}, Manipulate[Plot[A Sin[k x], {x, 0, 20}], {k, 1, 10}]] One reference: http://forums.wolfram.com/mathgroup/archive/2011/Sep/msg00198.html Also related: Table function with Part[] call misbehaving, but only after initial ...


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 -> ...


5

Starting with a styling funtion: st = Style[#, If[PrimeQ@#, {Bold, Blue}, Gray]] &; For fast operations and small tables you can use MapAt: Animate[ MapAt[st, Range@100, List /@ Range@i] ~Partition~ 10 // Grid, {i, 0, 100, 1} ] In version 9 you can use Span for better performance: Animate[ MapAt[st, Range@100, ;; i] ~Partition~ 10 // Grid, {i, ...


5

The descriprion of the problem seemed to me similar to other issues I've faced in the past. ContinuousAction->True option for InputField helped me then and OP confirms that it helps in his case too. So at the end, MWE introduced by Simon Woods should be expanded to: Column[{ InputField[Dynamic[test[[1]]], String, ContinuousAction -> ...


5

Quick fix to your code would be to add Row and Spacer[0]. a=0; DynamicModule[{x}, Row@{Slider[Dynamic[x]], Dynamic[If[x>.5,a=1;, Spacer[0]]]}] Instead of Spacer[0] you can use empty string: "", or Invisible[""]. Those braces are in output because you put them there. To know more about organizing an output, take a look at documentation: tutorial / ...


5

Where exactly do you run into problems? Maybe I don't understand your question, but you can 1. just substitute the expression DynamicModule[{c = 11}, Grid[Map[Button[ToString@#, c = #, Background -> Dynamic[If[Mod[#, c] == 0, Green, White]], ImageSize -> {32, 32}, Appearance -> "Frameless"] &, ...



Only top voted, non community-wiki answers of a minimum length are eligible