Tag Info

New answers tagged

4

The below approach seems to work efficiently. First, generate a list q of vertex degrees that are each at least 2.0. You can make the graphs more complex by changing the RandomInteger[{2, 5}], below, to RandomInteger[{2, 6}] or whatever, so long as you don't make the degree greater than the number of nodes - 1 (which would force a self-loop). From the ...


6

For something somewhat different, I've elected to use BSplineCurve[] + FilledCurve[] to render each annular sector: sector[{r1_?NumericQ, r2_?NumericQ}, {θ1_?NumericQ, θ2_?NumericQ}] /; r1 < r2 := Module[{cc = Cos[(θ2 - θ1)/2], p1, p2, pm, sk = {0, 0, 0, 1, 1, 1}, sw}, sw = {1, cc, 1}; p1 = Through[{Cos, Sin}[θ1]]; p2 = ...


9

Second trial. The following seems to work. The only restriction so far is that it only works on the first path. I will be looking into that. ClearAll[x, fun1, fun2, ff, gg] μ = 1; σ = 0.3; fun1[x_, t_] := If[ If[x < 0.5, gg = False; If[ff, gg = True]; False, ff = True ] && ff || gg, -x, x ] fun2[x_, t_] := If[ ...


4

I misunderstood and commented only about computing the Cesaro means as per the question In s I have all partial sums, but I do not know how to divide them by corresponding n. The desired scatter plot of 500 Monte Carlo attempts with samples of increasing length could be obtained with something like ticks = Range[-0.06, 0.06, 0.02]; s = Table[u = ...


4

In your example plot the Monte-Carlo integral is computed afresh for each new amount of sampling points: s[n_] := Total[Sqrt[1 - #^2] & /@ RandomReal[1, n]]/n Then take one random point, find the mean, take two new random points, find their mean, and so on until 500. The result is: ListPlot[Table[s[n], {n, 500}], PlotRange -> {0.7, 0.9}] The ...


2

It is valuable to look at the properties of these complex objects, e.g. in your example: data["Properties"] To do your own variance: val = First@data["ValueList"]; Variance[val] Total[(val - Mean[val])^2]/(Length[val] - 1) You can compare results of Variance and your mimic.


2

The specific approach is as follows. Convert data to an ordinary list, eliminate an extra set of {}, and insert the list into your formula: dta = First@Normal@data; Last@Total[(dta - Last@Mean[dta])^2]/(Length[dta] - 1) which gives the same result as Variance[data] namely 102.245 for the particular set of random numbers used.


14

Update Silvia proposed a much faster algorithm that I believe produces I uniform distribution. Here is my implementation of it. pointsInMask2[mask_Image, n_Integer, range : {_, _} : {0, 1/2}] := Reverse @ ImageData @ Binarize[mask, range]\[Transpose] // SparseArray[#]["NonzeroPositions"] & // RandomChoice[#, n] + RandomReal[{-1, 0}, {n, 2}] ...


10

Following up on my comment and borrowing a method from Vectorizing an image like "Trace Bitmap" in Inkscape: mask = Binarize @ Import["http://i.stack.imgur.com/yoPNX.png"]; {row, col} = ImageDimensions[mask]; intf = ListInterpolation @ Reverse @ ImageData @ mask; region = DiscretizeGraphics @ RegionPlot[intf[c, r] < 1/2, {r, 1, row}, {c, ...


1

You can also use the function Graphics`Mesh`GenerateUniformPointsInTriangle gupiTriF = Graphics`Mesh`GenerateUniformPointsInTriangle; Graphics[{Polygon[{{0, 0}, {0, 1}, {1, 0}}], White, Point[gupiTriF@500]}] For an arbitrary triangle tri you can use FindGeometricTransform to map the random points in the unit right triangle to points in tri: fgt2DF = ...


2

The general 2D case was discussed in this question, but a more robust version can be written randomFromRegion2D[ region_ /; RegionDimension[region] == 2, trials_Integer /: trials > 0] := Module[{bounds, randPts}, bounds = RegionBounds @ region; randPts = Transpose @ {RandomReal[bounds[[1]], trials], ...


4

In version 10.1 the undocumented function Random`RandomPointVector is useful: region = DiscretizeRegion@RegionUnion@ Table[Disk[RandomReal[4, {2}], RandomReal[1]], {10}]; Graphics@Point@ Random`RandomPointVector[region, 1000, Automatic, Automatic] The two Automatic arguments appear to be working precision and a method option - other allowed values ...


5

Following the advice of @Guess who it is. to use http://math.stackexchange.com/questions/18686/uniform-random-point-in-triangle randPt[tri_Triangle] := Module[{a, b, c, r1 = Sqrt[RandomReal[]], r2 = RandomReal[]}, {a, b, c} = Identity @@ tri; (1 - r1)*a + r1*(1 - r2)*b + r1*r2*c]; triangle = Triangle[RandomReal[{0, 5}, {3, 2}]] ...


3

I post this answer just as exploiting some other functions. Barring transcriptional, interpretational and indexing errors: func[s0_, m_, s_, t_, h_] := Module[{d = Sqrt[h], n = t/h, rv, x}, rv = {0}~Join~RandomVariate[NormalDistribution[0, d], n]; x = Accumulate[rv]; MapIndexed[{(#2[[1]] - 1) h, s0 Exp[(m - s^2/2) (#2[[1]] - 1) h + s #1]} &, ...


3

You can do this in very many ways. Probably one of the simplest conceptually could be to wrap your repeating code in a Table with a constant iterator: Table[ Module[ {data}, data = RandomVariate[NormalDistribution[RandomReal[], RandomReal[]], 100]; Histogram[data] ], {6} ] Alternatively, you could use control structures instructions ...


4

You can generate a random signal, if that is indeed what you mean, using a random walk. For example, 1000 samples would look something like this: (* Generate the samples and plot *) samples = Accumulate[RandomReal[{-1, 1}, 1000]]; ListLinePlot[samples] (* And to export them to CSV *) Export["\\path\\to\\file\\randomsamples.csv", samples, "CSV"]; And ...


4

You need to ask yourself a few more questions about what you want. If you want your random numbers to be uniformly distributed in the $(a,b)$ interval, the easiest functions to use are RandomReal to get real numbers, or RandomInteger to get integer values. These functions are similar to the RAND() function in Excel or similar spreadsheets. RandomVariate is ...



Top 50 recent answers are included