Tag Info

Hot answers tagged

17

Based on Mr.Wizard's answer and comments by Szabolcs and celtschk, 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 ...


15

If you interpret your geometric shape as NURBS of degree 1 (linear), you can proceed with the following, extremely simple code: pts={{0, 0},{1, 1},{0.5, 1.5}}; (* just an example *) s=BSplineFunction[pts,SplineClosed->True,SplineDegree->1]; Animate[ParametricPlot[s[t],{t,0,1},Epilog:>{Red,PointSize[Large],Point[s[t]]}],{t, 0., 1.}] This yields ...


13

The problem relates to the granularity of MachinePrecision numbers. The number 70.329862 is represented as an integer times a power of 2: x0 = SetPrecision[70.329862, Infinity] (* 4949024067128413/70368744177664 *) (The denominator is 2^46.) The machine numbers near this number do not allow for the representation of 70.329862 with $MachinePrecision ...


12

Update: Adding a button to print a snapshot: Manipulate[Module[{a = {{2, 3}, {3, 2}}, vp}, vp = VectorPlot[a.{x, y}, {x, -4, 4}, {y, -4, 4}, VectorScale -> {0.045, 0.9, None}, VectorPoints -> 16]; z = NDSolveValue[Thread[{x'[t], y'[t], x[0], y[0]} == Join[a.{x@t, y@t}, #]], {x@t, y@t}, {t, -2, 1}] & /@ u; plot = ParametricPlot[z, ...


11

My defined function next find {nextpoint, nextdirection} value from {startpoint, startdirection} using NSolve. next[{sp_, sd_}][δ_] := Module[{φ, sol, fp, fd}, sol = NSolve[{{x[φ, δ], y[φ, δ]} == sp + t sd, Abs[t] > 10^(-9), 0 <= φ < 2 π}, {t, φ}, Reals]// Quiet; sol = If[Length[sol] > 0, sol[[1]]]; fp = {x[φ, δ], y[φ, δ]} /. sol; ...


10

I have not fully diagnosed the problem, but it appears as if vv and vp are not initialized when you effectively wrap a Dyanmic module within a dynamic module (which is what you've done with the Manipulate. Changing your DynamicModule into the Manipulate seems to get the result you desire if you Initialize vv and vp: Clear[vv, vp] Manipulate[ With[{img1 = ...


9

By default, DynamicModule uses SynchronousInitialization -> True. This causes the initialization to be performed on the preemptive link, disabling any updates to the front-end. In particular, print statements, cell creation and dynamic box updates will all be deferred until the initialization completes. If we wish to monitor that initialization within ...


9

Just a kickstart to get the equations right (yours are wrong) and an idea of the system dynamics: With[{Pr = 10, a = 1.181, b = 0.675, v = 0.77, l = 8/3}, pfun = ParametricNDSolveValue[{ x'[t] == Pr v (y[t] - x[t]), y'[t] == R (b/v) x[t] - a y[t] - (b/v) (R - (a v)/b) x[t] z[t], z'[t] == a l (x[t] y[t] - z[t]), x[0] == y[0] == 0.8, ...


9

You can define a function that creates Manipulates with a "fake" SetterBar and a specific AutorunSequencing m[k_, seq_] := Manipulate[ Plot[{Sin[a*x] + b*Cos[3 a*x], k*x}, {x, 0, Pi}, ImageSize -> 400], {a, 1, 2}, {b, 0, 1}, Grid@{{"k", SetterBar[k, {0, .5, 1}]}}, AutorunSequencing -> seq, ContentSize -> {420, 270}] then create the frames ...


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


8

EDIT Input gets different rounding to machine-precision real if it's written in arbitrary precision! RealDigits[70.329862, 2] (* {{1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1}, 7} *) RealDigits[ SetPrecision[70.329862000000000000, ...


8

Thanks to kguler, I now know there is something like: LineScaledCoordinate. vertices = Table[{Cos[i], Sin[i]}, {i, 0, 2 Pi, 2 Pi/3.}]; Needs["GraphUtilities`"] Slider[Dynamic@t] Graphics[{ EdgeForm @ Thick, FaceForm @ None, Polygon @ vertices , AbsolutePointSize @ 12, Red, Dynamic[Point[LineScaledCoordinate[vertices, t]]] } ] Just in ...


8

You probably want a workflow similar to this. First locate one or more Excel files: files = SystemDialogInput["FileOpen", {NotebookDirectory[], {"Excel File" ->{"*.xlsx","*.xls"}}}, WindowTitle -> "Import Excel File"]; Then import the selected files and do something with the imported data (what that something is, we don't know so no point in ...


8

I wrote something to do something a little like what you wanted. Here I've adapted it so you can get a run through for each setting of the SetterBar. Some description of the functions. autolist[control_pattern] := list of manipulate settings for the animation specs is a pattern for culling variable specifications out of a Manipulate ...


8

Using the "almost new" feature of NDSolve[] that allows it to detect vector equations based upon the dimensions of the initial conditions. a = {{2, 3}, {3, 2}}; vp = VectorPlot[a.{x, y}, {x, -4, 4}, {y, -4, 4}, Axes -> True, AxesLabel -> {x, y}, VectorScale -> {0.045, 0.9, None}, VectorPoints -> 16]; ...


7

you could start with a simple hack of your code to extract the intersections; Something like {x1, y1} = Transpose[line]; {x2, y2} = Transpose[RotateLeft[line]]; gr2 = {(x1^2 - x1*x2 + y1*(-y1 + y2)), (y1 - y2)} // Transpose // Most; which can be encapsulated in the ellipseSimLowLevel as follows ellipseSimLowLevel[ellPos_, θ_, aimAt_, refls_, ...


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


7

SynchronousInitialization -> True causes dynamic evaluations to occur on the preemptive link. This locks up the notebook front-end for the duration of an evaluation. To avoid locking up the front-end indefinitely, there is a default timeout of six seconds: CurrentValue[EvaluationNotebook[], DynamicEvaluationTimeout] (* 6. *) The values we see for x ...


7

Try this: Solve[c == 0.0625 + 0.0008*X - 0.0232*Y - 0.0157*Z + 0.0059*X^2 + 0.0112*Y^2 + 0.0160*Z^2 - 0.0063*X*Y - 0.0243*X*Z + 0.0211*Y*Z // Rationalize, Z] (* {{Z -> 1/320 (157 + 243 X - 211 Y - \[Sqrt](-375351 + 6400000 c + 71182 X + 21289 X^2 + 82226 Y - 62226 X Y - 27159 Y^2))}, {Z -> 1/320 (157 + 243 X - ...


7

Here's a walkaround: Manipulate[ x, Row @ List @ EventHandler[ Checkbox[Dynamic[x]], {"MouseDown" :> (x = True), "MouseUp" :> (x = False)}] ]


7

Like Mike said in a comment, the key is to use the second argument of Dynamic. In this case I've built a function updateCurrencies which modifies a global variable currencies which holds an Association object with all the currency values in it. currencies = <| "USDollars" -> 0, "Euros" -> 0, "BritishPounds" -> 0, "SwedishKronor" ...


7

If you want full flexibility you should try EventHandler and graphics primitives. If you can decipher the following example you will get the idea: color = Black; positions = Position[DiskMatrix[5], 1]; disks = {color, Disk[#, 0.4]} & /@ positions; eventHandler[item : {c_, obj_: Disk[p_, _]}] := {c, EventHandler[obj, "MouseClicked" :> (disks = ...


7

While I wait for a more complete description of your needs please see: How to | Insert a File Path FileNameSetter SystemDialogInput And try: FrontEndTokenExecute["FileNameDialog"] Or: SystemDialogInput["FileOpen"]


7

This is just an idea how to prepare frames to export, don't have time for more now: f = Interpolation[ { {0, {1, 0, 0}}, {1, {2, 0, 0}}, {2, {2, 1, 0}}, {2.02, {1, 0, .5}}, {3, {1, 0, .5}}, {4, {2, 0, .5}}, {5, {2, 1, .5}}, {5.02, {1, 0, 1}}, {6, {1, 0, 1}}, {7, {2, 0, 1}}, {8, {2, 1, 1}} }, InterpolationOrder -> ...


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

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

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

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



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