Tag Info

Hot answers tagged

34

The only reason I am attempting to answer this is to perhaps get a Reversal badge. There you go... We will go slowly and this answer is the basis for what comes next. Let's start with two dimensions. You'll see why. We create a rectangular region: Needs["NDSolve`FEM`"] mesh = ToElementMesh[FullRegion[2], {{0, 5}, {0, 1}}, "MeshOrder" -> 1, ...


13

The printed version of the 2002 edition was printed 3 times and sold out 3 times; Springer and Google recently started selling it (book only) as a PDF eBook (no software) on the Springer and Google sites for $79. I know other authors (e.g. here) have gone to some trouble to make their books available here on stack exchange ... We are delighted to be able ...


13

The separation-of-variables solution you quoted has two indices appearing in it: n and j (the subscripts of the coefficient $A_{nj}$). Here, n is azimuthal mode order, i.e. it counts the number of nodes along the direction in which the polar-angle $\theta$ varies (divided by 2). The index j is needed because the wave is supposed to satisfy the boundary ...


8

A couple things: You don't update velocity (obx and oby appear to be unused?). You do your timestep wrong (you want x+=velocity*timestep, not x=velocity*time!). You also have your direction of your force wrong. You should take the negative gradient of potential. The gradient of 1/r is -1/r^2. The negative of that is 1/r^2. So you get the common sense result ...


7

With eqn[{k_, r_, H0_, P0_}] := {H'[t] == r (1 - H[t]/k) - d H[t] P[t], P'[t] == -s P[t] + e H[t] P[t], H[0] == H0, P[0] == P0} d = 0.01; s = 0.3; e = 0.02; I would define one simulation as sim := Module[ {k = RandomVariate[NormalDistribution[150, 20]], r = RandomVariate[NormalDistribution[0.4, 0.003]], H0 = RandomVariate[UniformDistribution[{50, ...


6

You can do this without a NDSolve by calculating the distance from the follower cranks joint to the end of the driving cranks end. Then use this distance with law of cosines to calculate the deviation angle. This is also pretty easy to implement on ANY hardware capable of doing a ArcCos and Atan2 operation (note that in c atan2 parameters are swapped). ...


5

For loop is always slow. You may try this: f = Compile[{{x, _Real}, {y, _Real}}, If[y >= 12. Cos[x] && y >= 10 + x^3, 1, 0]]; vol[n_Integer /; n <= 10^6] := 3.* Total[f@@@Transpose@{RandomReal[{0, 1}, n], RandomReal[{10, 13}, n]}]/n; The calculation of 1000000 samples takes 1.1 s on my i5-3210M.


5

With f[a_, {x_, y_}] := Piecewise[{{a x, x < y}, {x, x == y}, {1 - a + a x, x > y}}, 0] one simulation can be defined by sim[length_] := Module[{rv = RandomVariate[BetaDistribution[3, 1], length], y, yBar}, y[1] = First@rv; yBar[t_Integer] := yBar[t] = 1/t * Sum[y[i], {i, 1, t}]; y[t_Integer] := y[t] = f[0.5, {rv[[t]], yBar[t - 1]}]; ...


4

With 1. notes in the answer of your latter question, 2. initial values for FQout and RQout(the values are carelessly chosen real numbers because it's bound to be overlaid), the modified code is about 40 times faster now: f = With[{dx = 1/6, n = 48, m = 300, p = 36, capacity = 2500, A = 18., B = 0.1, L = 3., RML = 30, Vf = 100, Kj = 150, w = 20, ...


4

You can display zero crossing using MeshFunctions. Here is a clumsy exploitation from created graphic. The half-periods (difference between consecutive points) are displayed below with mean in red. x1plot = ListPlot[x1data, AxesLabel -> {"t", "x1"}, Joined -> True, MeshFunctions -> (#2 &), Mesh -> {{0.}}, MeshStyle -> {Red, ...


4

It looks like I'm late to the party but here is my approach. Common functions and data: trinarize[a_List, γ_?NumericQ] := UnitStep[a - γ] + UnitStep[γ + a] labels = {0 -> "bottom", 1 -> "middle", 2 -> "top"}; SeedRandom[1] sampleSimulation = RandomChoice[{-1, 0, 1}, 20] {0, -1, 0, 0, -1, -1, -1, 0, -1, -1, -1, -1, 1, -1, 0, 1, -1, -1, 0, 0} ...


4

I think your core idea about post-processing the splittings is a good one. It can be expressed somewhat more elegantly (although elegance is a subjective matter) with the help of linked lists rather than Reap/Sow: ClearAll[ll]; SetAttributes[ll,HoldAllComplete]; toLinkedList[l_List]:= Fold[ll[#2,#1]&,ll[],Reverse[l]] and ClearAll[process]; ...


4

I do not know why, but the following are much faster than Walk: ClearAll[walkF,walkF2]; walkF[x_List, a_List, b_List, sigma_] := With[{f = TruncatedDistribution[Transpose[{a - x, b - x}], ProductDistribution @@ ConstantArray[NormalDistribution[0, sigma], Length[x]]]}, x + RandomVariate[f]] walkF2[x_List, a_List, b_List, sigma_] := ...


3

data10 = RandomVariate[f[13, 0.5], {10, 25}]; (* 10 data sets from distribution f *) lls= LogLikelihood[EstimatedDistribution[#, f[a, b], {{a, 1}, {b, 1}}], #] & /@data10 (*{-32.4994, -25.2268, -21.9671, -26.8963, -25.9164, -22.8958, -26.5247, -24.9622, -33.9319, -28.6512}*) maxll=Block[{k=1}, MaximalBy[Last][ With[{dist = ...


3

I would build your simulation with a DynamicModule showing a table made with a Grid and controlled by a Trigger. First I would define a function that calculates distance when given time and acceleration. dist[a_, t_] := a t^2/2 Next I would get the basic functionality right. A grid showing time and distance with a trigger to control it. With[{a = -9.8, ...


3

Edited I don't like this much because what I take are intended to be the osculating circles don't have a radius equal to the radius of curvature. I used your formula, but it appears to be wrong. Nevertheless, what I've worked out does install a popup menu into a Manipulate expression which will select which parametric function will be displayed. It will ...


3

I don't understand your original code very well (particularly the definitions of listadj1 and listadj2), but here's my naive translation for your description, I only rewrote the simulation part: densitytest = With[{dis2 = idx^2, limit = adjLimit}, Compile[{{pos, _Real, 2}}, Times @@ UnitStep@(limit + 1 - Max /@ Transpose[Total /@ ...


3

Looks like a glitch, however you can invert the CDF to get the desired result (not as fast, of course): InverseCDF[HyperbolicDistribution[1, 59.428`, 18.441`, 3.428`*^-9, -0.00065`], RandomReal[1, 10]] (* {0.000448962, 0.0144836, 0.0481936, -0.0169342, 0.0445246, -0.0151702, 0.00316436, 0.00877931, 0.085059, 0.00880039} *)


2

I think using linked lists is usually the best way to proceed in cases like this. Start with coords = {}; Each time you generate a new point, r, add it with coords = {coords, r}; This is very fast, but will generate a deeply nested list. When all the points have been generated, flatten and re-partition the list, which is also very fast. coords = ...


2

Define a list large enough to hold your coordinates: coor = Table[Null, {100}]; Then, starting with i = 1; Let some program fill in the values coor[[i++]] = {0., 0., 0.}; coor[[i++]] = {0.1, 0.1, 0.003}; Finally, delete the remaining Null-values: DeleteCases[coor, Null] {{0., 0., 0.}, {0.1, 0.1, 0.003}} This should be significantly faster


2

Using sim[length_] := Module[{rv = RandomVariate[BetaDistribution[2, 1], length], y, yMed}, y[1] = First@rv; yMed[t_Integer] := yMed[t] = Median[y /@ Range[t]]; y[t_Integer] := y[t] = f[0.5, {rv[[t]], yMed[t - 1]}]; yMed /@ Range[length] ] results in plots like Here Median[y /@ Range[t]] calculates the median for y[1] to y[t], as stated ...


2

SeedRandom[1]; sampleSimulation = RandomChoice[{-1, 0, 1}, 20] rplcR = {(0) -> "middle", {beg___, mid : Alternatives @@ PatternSequence @@@ {{"top", "bottom"}, {"bottom", "top"}}, end___} :> {beg, Sequence @@ Riffle[{mid}, "jump"], end}}; jtsrcF = Composition[Join @@ # &, Tally /@ # &, Split, # //. rplcR &, ...


1

Based on the comments appended to the question, I believe that what you are looking for is: mvBeta[myrating, #, myR] & /@ RandomReal[{0,1},100] where you can change 100 to be any length vector you like, and myrating and myR have already been defined.


1

Using ManToGif by Vitaliy Kaurov ManToGif[man_, name_String, step_Integer] := Export[name <> ".gif", Import[Export[name <> Which[$OperatingSystem == "MacOSX", ".mov", $OperatingSystem == "Windows", ".avi"], man], "ImageList"][[1 ;; -1 ;; step]]]; Now write SetDirectory[NotebookDirectory[]]; r = 1; backgroundAxes ...


1

Manipulate[ Plot[Evaluate[ x[t] /. NDSolve[{m x''[t] + b x'[t] + k x[t] == Fo Sin[\[CapitalOmega] t], x[0] == x0, x'[0] == v0}, x, {t, tmin, tmin + deltaT}]], {t, tmin, tmin + deltaT}], {{m, 0.75}, 0.5, 2}, {{b, 0.05}, 0, 1}, {{k, 5}, 1, 10}, {{Fo, 0.75}, 0, 2}, {{x0, 0}, -2, 2}, {{v0, 0}, -1, 1}, {{tmin, 0}, 0, 100}, {{deltaT, ...


1

In lieu of a working example in the current OP to work with, yes, this can be done. An example of two bouncing balls with differing velocity retention on bounce: eventtab = Table[With[{n = n}, WhenEvent[y[n][t] == 0, y[n]'[t] -> (-0.95 + n/100) y[n]'[t]]], {n, 2}] NDSolve[{y[1]''[t] == -9.81, y[1][0] == 5, y[1]'[0] == 0, y[2]''[t] == -4, ...


1

Manipulate can be tricky, and it's sometimes hard to answer questions without simply doing a full implementation for the OP. In this case, it is possible to adapt the OP's initial structure, but there are several issues that makes a simple fix elusive. They are primarily related to the scope of symbols. (The side issue of an incorrect formula for ...


1

With the function f[a_, {x_, y_}] := Piecewise[{{a x, x < y}, {x, x == y}, {1 - a + a x, x > y}}, 0] you can define a new function, that will perform a single simulation sim[a_Real, n_Integer] := Module[{data = Partition[Riffle[#, Accumulate[#]/Range[n]], 2] &@ RandomVariate[BetaDistribution[3, 1], n]}, f[a, #] & /@ data ] where the ...



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