Hot answers tagged

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


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


11

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


10

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


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


6

This version works: rl = {ρ[z_, ϕ_] :> 1/5 Sqrt[25 - 25 z^2 + 10 Sin[5 ϕ] + Sin[5 ϕ]^2]}; Manipulate[PolarPlot[Evaluate[ReplaceAll[ρ[z, ϕ], %]], {ϕ,0, 2 Pi}], {z, -1, 1}] Manipulate[PolarPlot[Evaluate[ReplaceAll[ρ[z, ϕ], rl]], {ϕ,0, 2 Pi}], {z, -1, 1}] The main change is in the way the rule is defined as a $RuleDelayed$ instead of $Rule$.


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


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


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


4

Others have explained why the version with rl does not work. But this does not explain the very weird phenomenon that the version with % does work. Why is % (which is just a notation for Out) special? It seems that Manipulate singles out Out (i.e. %) for special treatment. Observe: In[1]:= x Out[1]= x In[2]:= Manipulate[Hold[%1], {x, 0, 1}] Out[2]= ...


4

Thanks to ciao's and Kuba's explanation, I have thought of some little code to exemplify the scoping behaviour of Manipulate; I hope it will be helpful to people who are still not very familiar with the concept: a), Manipulate[Hold@x, {x,0,1}] b), p=x; Manipulate[2 p-x,{x,0,1}] c), rpl=q->x; Manipulate[(2 q/.rpl)-x,{x,0,1}]


3

You have to change your For loop to account for positive and negative regions, and make the box twice as big. First change the definition of A, A = 2 fmax*L; Then modify your For loop to be posinboxcount = 0; neginboxcount = 0; countmissed = 0; For[i = 1, i <= totalcountmax, i++, xrand = RandomReal[{xinit, xlast}]; yrand = RandomReal[{-fmax, ...


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


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


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


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:


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


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


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

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


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


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


1

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 ?


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



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