New answers tagged

2

I am posting the answer based on taking the phrase "the example is without importance" on face value (i.e. not a homework or similar). I am not exactly I understand the aim. So, with these caveats and to motivate clarification: f[a_, b_, x_, y_] := {a, b}.{x^2, y^2} /; a + b > 0 f[a_, b_, x_, y_] := Null Manipulate[ Column[{ Row[{"a+b= ", a + b}, ...


0

I just found another way : textStyle = Sequence[12, Italic, FontFamily -> "Times"]; Manipulate[ ParametricPlot[ {a Sin[b t + c], d Cos[f t + g]}, {t, 0, 6 Pi}, Frame -> True, PlotRange -> {{-5, 5}, {-5, 5}} ], {{a, 1, Style[a, textStyle]}, 0, 5, 0.01}, {{b, 1, Style[b, textStyle]}, 0, 10, 0.01}, {{c, 1, ...


4

You can use the option LabelStyle: labelstyle = Directive[12, Italic, FontFamily -> "Times"]; Manipulate[ParametricPlot[{a Sin[b t + c], d Cos[f t + g]}, {t, 0, 6 Pi}, Frame -> True, PlotRange -> {{-5, 5}, {-5, 5}}], {{a, 1}, 0, 5, 0.01}, {{b, 1}, 0, 10, 0.01}, {{c, 1}, 0, 2 Pi, 0.01}, {{d, 1}, 0, 5, 0.01}, {{f, 1}, 0, 10, 0.01}, ...


1

A few points and my version: Manipulate[DynamicModule[{f = Sin[x],... means whenever Manipulate updates itself, f etc. are reinitialized. (It does this only first time the calculate button is pushed.) I would suggest doing it all inside one DynamicModule or one Manipulate. I show the Manipulate approach below. I constructed the controls in the standard ...


0

Thank you for the answers. I made a little change to avoid the Null from the if statement. I carried the If statement in front of the InputField for the plot. by using the suggestions: to get the FullSize plot, fixed the " " marks in the result section. Create a function DGL to make the calculation. Next step is to create a package and use the package ...


2

Here is some code that will let you vary the shape you are rendering fairly easily but does not use Manipulate. It might be useful to you in the short term. I will put more work in this problem, and try to build a useful interactive version with Manipulate. I will update this answer when I have such code. With[{n = 100}, z = Subdivide[0, 2 Pi, n]; x = ...


1

You can use Row[{"xL", InputField[Dynamic[xL], Number]}, Spacer[5]] or Labeled[InputField[Dynamic[xL], Number], "xL", Left] to label the input fields. Manipulate[DynamicModule[{f = Sin[x], xR = 1, xL = 0, Res = 0.4596976941}, Column[{Row[{"xL ", InputField[Dynamic[xL], Number]}, Spacer[5]], Row[{"xR ", InputField[Dynamic[xR], Number]}, ...


3

I would memoize sol[a]. The Evaluate in position does nothing if it does not wrap the entire expression after the :=. It's not that important, so I would just drop it. The issue with [[1]] (or First) can be handle in sol. Here are the changes I've described: sol[a_] := sol[a] = First@NDSolve[{x''[t] == -2 x[t], x[0] == a, x'[0] == 1}, {x}, {t, 0, 10}] ...


0

This helps to get rid of that [[1]] as per your request, however without having the code that is really slowing this down, I cannot be sure it would help improve your performance. If it does, great! If not, you have eliminated one possible cause. You state the performance glitch is with position[t,a] function. However, can you remove the 0.01 timesteps in ...


3

I remember playing around with clear plastic sheets with grid lines. Here's a way to simulate the real-time moving around of the sheets. Starting with gpap's function, change this to an image and set the alpha channel so that the white area is actually transparent. Then use GraphicsGrid to display multiple copies. Now you can move them around and rotate ...


0

this is an answer also a question at the same time. I am simply trying to avoid using sliders and predefined functions to increase the capacity of the CDF file. I changed my example to taking integral and use inputfield for the function and upper and lower limit. It completely functional but not best presentation and controls. Here is the code ...


12

I like to keep things simple, so I'll skip the letter labels, but include the lines overhanging from the grid: m = 30 (* number of mesh lines *); h = 2 (* overhang *); lins = Join[#, Map[Reverse, #, {2}]] & @ Outer[{##} &, ArrayPad[Range[-1, 1, 2/m], h, "Extrapolated"], {-1, 1}]; Table[Graphics[{AbsoluteThickness[1/100], ...


5

g = Graphics@GraphicsGroup[ Table[{Line[{{x, -5}, {x, 5}}], Line[{{-5, x}, {5, x}}]}, {x, -5, 5, .25}] ]; Manipulate[ Overlay[ Table[ Rotate[g, i θ], {i, -2, 2}], Alignment -> Center ], {θ, 0, π/12}] or g = Graphics@GraphicsGroup[ Table[{Line[{{x, -5}, {x, 5}}], Line[{{-5, x}, {5, x}}]}, {x, -5, 5, .25}] ]; ...


4

Without diving into your code too much, everything will run a LOT more smoothly if you use ParametricNDSolve to solve your differential equations with the parameter a: pfun = ParametricNDSolveValue[{x''[t] == -2 x[t], x[0] == a, x'[0] == 1}, x, {t, 0, 10}, {a}] position[t_, a_] := {Sin[#], Cos[#]} &@pfun[a][t] You can keep everything else the same. ...


31

I feel that once you start with Moire patterns, there's no ending. The way I would replicate these is by making a grid into a function (like @JasonB) but also parametrise the angle of rotation into it: lines[t_, n_] := Line /@ ({RotationMatrix[t].# & /@ {{-1, #}, {1, #}}, RotationMatrix[t].# & /@ {{#, -1}, {#, 1}}} & /@ ...


23

Something like this: nlines = 30; Table[ Overlay[ Rotate[ Graphics[{ Table[{ Line[{{0, n}, {nlines, n}}], Line[{{n, 0}, {n, nlines}}]}, {n, 0, nlines}], Text[Style[#1, 18], {0, 0}, {-1, -1}, Background -> White] }, AspectRatio -> 1, PlotRangePadding -> None, ImageSize -> ...


1

Here's another simple modification of your code that allows you to specify the function, Manipulate[ DynamicModule[{f = Sin}, Column[{InputField[Dynamic[f]], Dynamic[Plot[f[o x + p], {x, -5, 5}]]}]], {o, 1, 10}, {p, 2, 10}] Now you can change Sin to any built-in function that takes a single argument, and still modify o and p. You can even ...


2

Hope I understood your question correctly. I might require to modify the code if I misinterpreted your OP. Example: Manipulate[ Plot[f[x], {x, min, max}], {{f, Sin, "Function"}, {Sin, Cos, Tan}}, {{min, 0, "Min."}, 0, 2 Pi}, {{max, 2 Pi, "Min."}, 0, 2 Pi} ] Output:


7

I don't think you can change the compositing operator but you can dynamically change the appearance. A simple example: im = LinearGradientImage[]; DynamicModule[{pt = {10, 10}}, LocatorPane[Dynamic[pt], im, Appearance -> Graphics[{ Dynamic @ GrayLevel[1 - PixelValue[im, pt]], Disk[]}, ImageSize -> 20]]]


0

There's a very nice (and more complete) solution here : http://community.wolfram.com/groups/-/m/t/490130 However, I don't understand that code. Maybe someone could built another solution from it, to be exposed here ?


2

Wrap p and Plot[...] in the last row of your grid with Dynamic: Manipulate[pltrng = {{-2, 2}, {-2, 2}}; Grid[{{Graphics[{col, Rectangle[]}], LocatorPane[Dynamic@p, Graphics[{Red, Rectangle[{-l/2, -1}, {l/2, 1}]}, PlotRange -> pltrng], LocatorAutoCreate -> True]}, {Dynamic@Column@p, Dynamic@Plot[p. {1, x}, {x, 0, 1}, ...


9

You can use FoldList to generate evolution of your system. You need a function that propagates your particles in time. Every time you apply your function to state at time $t$ you obtain your state at time $t+dt$. Let's make such function for one particle in 1D. Tr1D[{x_, v_}, dt_, L_] := Module[{u, w}, u = x + v dt; {u, w} = If[u < L, {u, v}, {L - ...


1

Manipulate is HoldAll and the body isn't evaluated till it is displayed. That's because effectively there is Dynamic[body]. I once explained that a little in Manipulate in Manipulate. So inside the package it won't do anything, as no output is generated. You can see this here: ClearAll[x]; Manipulate[x = 5, {y, Null}]; Pause[1]; x Manipulate[x = 5, {y, ...


9

ok, this is cheating but since your gas is non-interacting it works. 3 dimensions or 1 dimensions is the same since the collisions only change momentum in the normal direction, ie we assume point particles and no friction. A collision with a wall the only thing it does is to invert the velocity. So you can think of the particle moving at a constant speed ...


0

Both Edmund's and Kuba's answers provided the key, which was just to substitute a different variable (like var or xp) that Manipulate won't touch. With that key, I created something more modular, using a Module structure to specify just once at the top which plots to make: ClearAll[f]; Module[{vars, varsAsPattern, varsToPlot, varFnSeq}, vars = {x, y, z}; ...


4

From the OP comments the slices (or contours) of a multi-dimensional function is what is being sought. A way to do this is the have each Plot in Manipulate set as Dynamic on the variables not on the x-axis. Such that, as these variables are adjusted the contour in the variable on the x-axis updates. For example, for $f(x,y,z) =z\sin(x)-y$ the contours in ...


3

I post this for illustration in the event it may be useful. In the following a=1. Manipulate[ Show[ParametricPlot[f[p, loc[[1]], loc[[2]], t], {t, 0, 50}, PlotRange -> {{0, 6}, {0, 6}}, PlotStyle -> Red, PerformanceGoal -> "Quality"], StreamPlot[{1 - (p + 1) x + x^2 y, p x - x^2 y}, {x, 0, 6}, {y, 0, 6}]], {p, 1, 4}, {loc, {0, 0}, ...


3

pndsol = ParametricNDSolve[{x'[t] == 1 - (b + 1) x[t] + x[t]^2*y[t], y'[t] == 1*x[t] - x[t]^2*y[t], x[0.1] == 1, y[0.1] == 0}, {x, y}, {t, 0, 50}, {b}]; ParametricPlot[Evaluate@Table[{x[b][t] , y[b][t]} /. pndsol, {b, 0, 1, .1}], {t, 0, 50}, AspectRatio -> 1] pndsol2 = ParametricNDSolve[{x'[t] == 1 - (b + 1) x[t] + x[t]^2*y[t], y'[t] == ...


2

As you've noticed both Plot and Manipulate are scoping constructs. And the problem is that you want to manipulate expressions that contain variables which are meant to be scoped and where is a naming conflict. What you want probably is possible but I think the fastest solution is just to avoid naming conflicts: With[{ exprsToPlot = {xp^y, x^yp}, ...


2

pndsv = ParametricNDSolveValue[{u''[t] + 5*u'[t] + 6*u[t] == 0, u[0] == 2, u'[0] == b}, u, {t, 0, 5}, {b}]; delta = .3 Range[0, 10]; Manipulate[ Plot[Evaluate[Table[pndsv[b][t], {b, a - delta}]], {t, 0, 5}, PlotRange -> {0, 3}, ImageSize -> 400, PlotStyle -> (Opacity /@ Range[0, 1, .1])], {{a, 3}, 0, 5}]


2

From Button documentation: By default, button functions are evaluated on a preemptive link and time out after 5 seconds Use Method->"Queued" to evaluate button functions on the main link, which never times out: So try something like this: Manipulate[ file, {{file, file}, None}, Button["...", file = SystemDialogInput["FileSave"], Method ...


0

While not an histogram, this Manipulate is mostly fun ! Clear["Global`*"] r = 1; Amplitude[k_, r_] := Amplitude[k, r] = If[k == 0, 1, RandomReal[{0.5, 1}]] Frequency[k_, r_, fmin_, fmax_] := Frequency[k, r, fmin, fmax] = If[k == 0, 1, RandomReal[{fmin, fmax}]] Manipulate[ ListPlot[ Table[{Frequency[k, r, fmin, fmax], Amplitude[k, r]}, {k, 0, ...



Top 50 recent answers are included