# Tag Info

0

Welcome user3523464... There is a lot to do with the code. First you may notice that "c" in your for-loop ist in black color and not in blue. This is du to "C" is a reserved word in Mathematica. So you have to use characters here. Also you will run into trouble with the Partition command, since there will be lists of different length and you´ll get problems ...

3

There are a bunch of Region functions that just showed up in 10. This uses RegionDistance[] to make a function that computes the shortest distance from a point to a region. The generated function runs faster than just checking all the circles. Though the creation of the function in the first place has to look at all the circles. So this still runs in ...

2

Here's one way to approach this: generate a collection of random circles and then throw out all those that are too close to another. For example, generate 20 centers with a box of size {-5,5} and with radius 1. Then throw out those that overlap others. n = 20; rad = 1; centers = RandomReal[{-5, 5}, {n, 2}]; allCircles = Table[near = Nearest[centers, ...

6

d1 = RandomVariate[ExponentialDistribution[.1], 2000]; d2 = RandomVariate[TruncatedDistribution[{20, 40}, ExponentialDistribution[.1]], 2000]; GraphicsColumn[{Histogram[d1, {1}, PlotRange -> {{0, 72}, {0, 250}}], Histogram[d2, {1}, PlotRange -> {{0, 72}, {0, 250}}, AxesOrigin -> {0, 0}]}]

3

Alternative 2D Solution A simpler and more readily generalizable alternative to the solution presented in my previous Answer can be obtained by noting that a UniformDistribution on the curve shown in the first figure is equivalent to a ProbabilityDistribution in p weighted by dsdp, ProbabilityDistribution[dsdp/arcmax, {p, 0, 1}] as can be can be ...

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

Solving the one-dimensional problem is a first step toward solving the three-dimensional problem described in the question and comments. Without loss of generality, it can be written after renormalization as 1 == p^2 + Sqrt[x^2/4] Noting that phase space is mirror-symmetric about both axes, we solve for the phase curve in the quadrant p > 0, x > 0. ...

0

This has been fixed in version 10.0.2. On windows 7, 64 bit try with small list and

0

Sorry for the horrible coding practices, but I couldn't get it to work otherwise. First I initialize a list: LifetimeList1 = {} I then use a For loop to append the total lifetime of each "path" to LifetimeList1 For[i = 1, i <= Length[data1["Paths"]], i++, AppendTo[LifetimeList1, 0.1*Length[ TakeWhile[ Table[Last[data1["Path", ...

4

If you have version 10 or higher you can use a combination of TimeSeriesMap and TimeSeriesThread. bool = TimeSeriesMap[Boole[# > 0] &, data1]; tot = TimeSeriesThread[Total, bool]; ListPlot[tot] The total tot is a TemporalData object so we could use the "SliceData" property to obtain the number of paths at a time t that have positive state. ...

3

Theoretically, for any continuous distribution ... which includes your Uniform distribution ... $P(X=3) = 0$. So, theoretically, your question leaves you with nothing to worry about. Practically, for RandomReal to hit a perfect 3 ... should be equally impossible. Perhaps, as a matter of machine-precision, you are worried about whether mma might ...

6

I do not believe that belisarius's answer, as written, is correct, at least in Mathematica 10.0.1 under Windows. In a simplified example we can see that in machine precision a three is still generated despite subtracting $MachineEpsilon from 3 in the range. I narrow the range make this readily apparent: ϵ =$MachineEpsilon; SeedRandom[1] First /@ ...

10

Plot[PDF[MixtureDistribution[{6, 3}, {UniformDistribution[{-3, 3 - $MachineEpsilon}], UniformDistribution[{3 +$MachineEpsilon, 6}]}], x], {x, -3, 6}, Filling -> Axis] To generate your data: RandomVariate[ MixtureDistribution[{6,3}, {UniformDistribution[{-3, 3 - \$MachineEpsilon}], ...

2

data = DeleteCases[Range[-3, 6], 3]; l = RandomChoice[data, {1000}]

0

Similar to the one in the documentation. I just made it into a function so that you can specify the number of vertices. randomTree[n_, opts___] := Graph[Range@n, # + 1 <-> RandomInteger[{1, #}] & /@ Range[n - 1], opts]

Top 50 recent answers are included