Tag Info

Hot answers tagged

6

Without a more complete example of your function all I can offer are bare guidelines to (hopefully) point you in the right direction. The first level is merely syntactical; you would use OptionsPattern, OptionValue etc., in a high level function simply for convenience, but pass all arguments as machine types to an inner compiled function. A second level is ...


6

One difficulty in using Manipulate is that it rewrites your code for you in ways that are not clearly explained in the documentation. The thinking is that this rewriting achieves the dynamic interactions described in the documentation without burdening the programmer with some of the tedious details involved. For instance, expressions that contain ...


5

I do this all the time, but use small buttons next to the slider. This is handy when one wants to jump to specific value, and sometimes it is hard to get the slider to go there exactly without few hits and misses and one ends up opening the slider using "+" and typing in the value in the small window which is not very efficient sometimes. Here is an example ...


4

Here is the simple method I use. I create a button (with label "[[?]]") that finds the position of the current selection in the last output. You can add the button to a custom utilities palette for easy access. Button["\[LeftDoubleBracket]?\[RightDoubleBracket]", Print@Position[%, ToExpression@CurrentValue@"SelectionData"]] Here's how to use it to grab ...


4

You can attach multiple controls to a variable: Manipulate[Graphics[{Polygon[{pt1, pt2, pt3}]}, PlotRangeClipping -> False, Frame -> True, PlotRange -> {{0, 10}, {0, 10}}], {{pt1, {0, 0}}}, {{pt2, {0, 1}}}, {{pt3, {1, 1}}}, Row[{Control@{{pt1, {0, 0}}, {0, 0}, {10, 10}, Slider2D}, Control@{{pt2, {0, 1}}, {0, 0}, {10, 10}, Slider2D}, ...


4

You need to do some initialization. Manipulate often behaves strangely when its controls are not initialized properly. f[u_] := If[u <= 1, 5, 0]; Manipulate[ Column[{ Row[{"x: ", x, " f[x]: ", f[x]}], Row[{"ang: ", ang, " f[ang]: ", f[ang]}]}], {x, 0, 2}, {{ang, x}, x, 2}] (* initialization added to control *)


3

Here's an approach using ParametricPlot, where ListAnimate permits smooth animation. testparaNew[α_] := Show[{ ParametricPlot[ {{Cos[θ], Sin[θ]}, {2 Cos[α] + Cos[θ], 2 Sin[α] + Sin[θ]}}, {θ, 0, 2 π}, PlotRange -> 3, Axes -> False, Frame -> False ], ParametricPlot[ {{2 Cos[α] + r Cos[2 α + π], 2 ...


3

I would localize the variables inside the DynamicModule created by the Manipulate by using the ControlType -> None (or simply None for short) specification. This use is discussed here: What does None mean in a control specification for Manipulate? ControlType -> None Vs. Module inside Manipulate (i.e. making everything local) Code: ...


2

This is not an answer but rather an extended comment to @kguler to demonstrate Appearance -> "Labeled" with Slider2D in version 10.1 $Version "10.1.0 for Mac OS X x86 (64-bit) (March 24, 2015)" Using @kguler answer Manipulate[ Graphics[{Polygon[{pt1, pt2, pt3}]}, PlotRangeClipping -> False, Frame -> True, PlotRange -> {{0, 10}, ...


2

There are two issues going on here, though only one of them is preventing your plot from working in the Manipulate. The first is, as noted by xzczd in comments, that you need to get Mathematica to see that the \[Beta] in the expression for x[t]/. s is the same one you are using as the variable to be manipulated. You can see this is an issue with a slight ...


2

Manipulate[a = Plot[x, {x, 0, 1}]; b = Plot[1 - z, {z, 0, 1}]; Show[If[cond1 == 1, a, Graphics[]], If[cond2 == 1, b, Graphics[]], Axes -> (cond1+cond2>=1), PlotRange -> {{0, 1}, {0, 1}}, AspectRatio -> 1/GoldenRatio], Grid[{{Control[{{cond1, 1, ""}, {0, 1}}], "a"}, {Control[{{cond2, 1, ""}, {0, 1}}], "b"}}]] Change Axes -> ...


2

ParametricNDSolveValue is made for such problems: sol = ParametricNDSolveValue[{y1'[t] == -k1*y1[t]*y2[t] + k11*y3[t], y2'[t] == -k1*y1[t]*y2[t] + k3*y5[t] + k11*y3[t], y3'[t] == k1*y1[t]*y2[t] - k2*y3[t]*y4[t] + k22*y5[t] - k11*y3[t], y4'[t] == -k2*y4[t]*y3[t] + k22*y5[t], y5'[t] == k2*y3[t]*y4[t] - k22*y5[t] - k3*y5[t], y6'[t] == ...


2

Here's a quick one. It'd be wise to solve the equations for a set of variables k1,...,k22 just once. This is possible with dynamic programming revised1[k1_, k2_, k3_, k11_, k22_] := revised1[k1, k2, k3, k11, k22] = NDSolve[{y1'[t] == -k1*y1[t]*y2[t] + k11*y3[t], y2'[t] == -k1*y1[t]*y2[t] + k3*y5[t] + k11*y3[t], y3'[t] == k1*y1[t]*y2[t] - ...


2

For the code to work without error messages, signa needs an initial value, for instance: Manipulate[Plot[PDF[NormalDistribution[mu, sigma], x], {x, -4*sigma, 4*sigma}], {mu, -10, 10}, {{sigma, .5}, 0, 10}] Alternatively, just tolerate the initial error messages, and move the sigma slider to obtain the desired results.


2

Might you be looking for this? The modifications are in the addition of the zeros table (though it would be much better to write down an analytical expression) and the rule for Epilog acts on it accordingly to generate the points. In my example, though, they are black for a small slope and become brighter red/green for larger negative/positive slopes. You ...


2

As in my comment, I feel, it's cleaner to use Show[(Pick[HoldComplete[{regionPlot, contourPlot}], {{True, showQPlane}}])[[1]]] Additionaly I use SetDelayed in the definition of contourPlot to prevent evaluation at definition and HoldComplete makes sure that first Pick is run, and only then what's left is evaluated. [[1]] strips the result of Pick of the ...


1

This is a minimal example of how to do something like this: Manipulate[ plot1 = Graphics3D@Sphere[{0, 0, 0}, 1.3]; If[x, Print@"Calculating plot2"; plot2 = Graphics3D@Cylinder[]]; Show[{plot1, If[x, plot2, {}]}] , {{x, True}, {True, False}} ] Body of the Manipulate is inside Dynamic so if you want to be able to control what is sent to ...


1

d[e_] = e/2; Manipulate[Row[{"d = ", d[e], Plot[2 x - 1, {x, -1, 4}, ImageSize -> 300]}, Spacer[5]], {e, 0, 5}] Perhaps a better alternative is to use Labeled and to wrap the label with Pane to avoid jittering of the plot as the size of the label changes: Manipulate[Labeled[Plot[2 x - 1, {x, -1, 4}], Pane[Row@{"d = ", d[e]}, ImageSize -> ...


1

Below is the answer: Manipulate[Plot[ Evaluate[x[t] /. NDSolve[{x''[t] + 2 \[Beta] x'[t] + 4 x[t]== 0, x'[0] == 0, x[0] == 1}, x, {t, 0, 4}]], {t, 0, 5}], {\[Beta], 0,4,0.1}] thank you for asking


1

There are two issues here. The first one can be explained easily because you simply forgot that your button needs to do something. Just evaluating your Manipulate is not going to do what you like, because you need to see it on screen when you want to interact with it. Therefore, you need to Print or CellPrint your Manipulate. The second issue arises when ...


1

I hate fiddly held expressions! But I managed to get this Dynamic construct to work. n = 4; left[x_, y_, z__] := Abs@Product[x + I y - Complex @@ zz, {zz, {z}}] right[z__] := Abs@Product[Complex @@ zz, {zz, {z}}] DynamicModule[{z = RandomReal[{-5, 5}, {n, 2}]}, Dynamic[Show[ ContourPlot[ left[x, y, Sequence @@ z] == right[Sequence @@ z], {x, ...


1

I don't know how to do what you ask, but here is an alternative approach that you might use. snapshots = {}; Manipulate[ Plot[ctrlVdc + ctrlVac ctrlgFunc[2 π ctrlf t + ctrlPhi], {t, 0, 0.4}], {{ctrlgFunc, Sin, ""}, {Sin, Cos, Tan, Cot}}, Delimiter, {{ctrlVac, 1.5, Subscript["V", "ac"]}, -10, 10}, {{ctrlVdc, 0.5, Subscript["V", "dc"]}, -1, 1}, ...



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