Tag Info

New answers tagged

3

It is a little known fact and probably not well documented, but since version 9 one can use just strings as variables (dependent and independent) in NDSolve, which in this case helps to solve the memory problem in a rather elegant way: mpl=1/Sqrt[6.70837*10^-39]; gsT=106.75; Sup[LamdaI_?NumericQ,GammaI_?NumericQ]:=Module[{ a,rhor,Trad,tf,s,t }, ...


0

From the comments that Szabolcs gave, Clear and ClearAll are ineffective, but using Remove works. So now the module reads: Sup[\[CapitalLambda]I_?NumericQ, \[CapitalGamma]I_?NumericQ] := Module[{a, \[Rho]r, Trad, tf, s, t, result}, tf = 10/\[CapitalGamma]I; s = NDSolve[{a'[t] ==a[t]*Sqrt[(8 \[Pi])/(3 mpl^2) (\[Rho]r[t] + ...


3

You can also use RandomVariate with DiscreteUniformDistribution: rW[a_, b_, n_] := Accumulate[Prepend[ RandomVariate[DiscreteUniformDistribution[{{-a, a}, {-b, b}}], n]], {0,0}] dt = rW[10, 20, 100]; Graphics[{PointSize[Large], Red, Point@#, Thick, Blue, Line@#} &@dt, Frame -> True, Axes->True, AspectRatio -> 1/GoldenRatio] We get the ...


1

a = 3; b = 5; randomWalk = NestList[# + {RandomInteger[{-a, a}], RandomInteger[{-b, b}]} &, {0, 0}, 100] (* {{0, 0}, {2, 2}, {1, -3}, {-2, 2}, {1, 4}, {1, 3}, {1, 2}, {4, 0}, {4, 0}, {3, -4}, {4, -1}, {2, -5}, {0, 0}, {0, 0}, {2, -3}, {3, -6}, {2, -11}, {4, -10}, {4, -5}, {7, -3}, {9, \ -3}, {6, -8}, {9, -12}, {7, -16}, {5, -11}, {6, -16}, {4, ...


5

The problem is that trajectory[f] passes the Symbol f to Manipulate, so that the Manipulate updates to the new f whenever the definition of f is changed. The trick is to somehow to evaluate f so that the symbol f is replaced by its definition before it is injected into the Manipulate code. Method 1: ClearAll[soln]; soln[f0_, y0_] := Function[t0, y[t0] ...



Top 50 recent answers are included