Skip to main content
48 votes

How to sample points randomly below a curve?

There is no need in filtering out random points in a rectangle that don't fall in the prescribed region. The sampling within a region can be done directly with ...
corey979's user avatar
  • 24k
25 votes
Accepted

How to sample points randomly below a curve?

As noted in my comment, one approach is as follows. First, generate thousands of pairs of random numbers in the range {0, 2 π}, ...
bbgodfrey's user avatar
  • 61.8k
19 votes

How to sample points randomly below a curve?

More of a first principles approach, use the function as a PDF to generate random x data, then for each ...
george2079's user avatar
10 votes

How to sample points randomly below a curve?

In case where only the plot is given: plot = Plot[1/π Cos[θ]^2, {θ, 0, 2 π}, Filling -> Bottom] ...
Kuba's user avatar
  • 137k
9 votes

How to implement the sample-point process like the built-ins of Mathematica?

Being highly astonished about all the very interesting answers, I only want to add an approach using NMinimize. Not very fast, but straightforward. The idea behind ...
Ulrich Neumann's user avatar
8 votes
Accepted

Sample over a matrix

Create a function that does this for exactly one entry. Then use this function on all your entries: ...
halirutan's user avatar
  • 113k
8 votes
Accepted

Random sample of big big numbers

You can use Span to avoid the blowup from Range: ...
7 votes

Sample over a matrix

Also f0 = Extract[#, {{1}, {2}, {RandomInteger[{3, 5}]}}] &; f0 /@ mat {{1, 1, 3}, {2, 2, 3}, {3, 3, 2}, {4, 4, 7}, {5, 5, 6}, {6, 6, 7}, {7, 7, 4},...
kglr's user avatar
  • 398k
7 votes

Why does plot not show where Piecewise function is not zero?

Try Plot[f[x], {x, 0, 1.0001}, PlotPoints -> {Automatic, { 1}}] Don't know why this workaround only works for extended plotrange.
Ulrich Neumann's user avatar
7 votes
Accepted

Plot, sampling, and why it does not display for some ranges

Your plots aren't empty: they have a line along the x axis. Plot uses PlotPoints -> 50 by default, and since you go from -30 ...
Brett Champion's user avatar
7 votes
Accepted

Finding the periodicity (or wavelength) in approximately periodic data irregularly sampled

This is something one can tackle using an irregular periodogram, and that happens to be available in the Wolfram Function Repository. Grab the data and separate into times and values. ...
Daniel Lichtblau's user avatar
6 votes

Plot, sampling, and why it does not display for some ranges

Brett's answer explains the why. To force sampling at specified points you can use an undocumented form of PlotPoints (see this answer by Ullrich Neumann) : ...
kglr's user avatar
  • 398k
6 votes
Accepted

Why does plot not show where Piecewise function is not zero?

You can use ParametricPlot to show the jumps at the boundaries of the domain without having to extend the domain. If jumps occur only at the boundaries using <...
kglr's user avatar
  • 398k
6 votes

Sample over a matrix

Here's a faster extractor using a single Extract and single RandomInteger call, although still with a minimally expensive ...
b3m2a1's user avatar
  • 46.9k
6 votes
Accepted

Sampling Implicit functions

The sampling is done by ContourPlot. To extract the data: ...
Nasser's user avatar
  • 146k
5 votes
Accepted

Sample the data with equal step size

Also TimeSeriesResample[data, {Range[1, data[[-1, 1]], τ]}] {{1, 0}, {2, 0}, {3, 3}, {4, 10}, {5, 17}, {6, 27}, {7, 43}, {8, 63}}
kglr's user avatar
  • 398k
5 votes

How to generate a matrix with certain conditions

Binary random variables are often modeled using the BernoulliDistribution. You can use the function RandomVariate to get a ...
bill s's user avatar
  • 69.2k
5 votes
Accepted

Is there a way to generate a data-driven Monte Carlo sample from a histogram?

You may do this using "SmoothKernelDistribution". Here is a simple example. We first create some data from a Normal Distribution: ...
Daniel Huber's user avatar
  • 53.1k
5 votes

Is there a way to generate a data-driven Monte Carlo sample from a histogram?

This is precisely what RandomChoice does: choosing numbers according to weights. For example, if your histogram is ...
Roman's user avatar
  • 48.3k
5 votes

Finding the periodicity (or wavelength) in approximately periodic data irregularly sampled

Maybe a nonlinear fit would work for you, but it needs a good starting point to converge: ...
Roman's user avatar
  • 48.3k
5 votes
Accepted

How to compile the following code (sampling from a distribution)?

Is UniformDistribution compilable? (Or maybe RandomReal?) If so, then making use of the fact that a ...
JimB's user avatar
  • 41.9k
4 votes

How to generate a matrix with certain conditions

Since all the simple answers have been given, here is a SparseArray[] solution that may be useful if you want to generate large matrices without storing unneeded ...
J. M.'s missing motivation's user avatar
4 votes

How to generate a matrix with certain conditions

You can use weight option in RandomChoice ...
OkkesDulgerci's user avatar
4 votes

Random sample of big big numbers

You could experiment a bit with the following function ...
Henrik Schumacher's user avatar
4 votes

Filtering data with timestamps

...
kglr's user avatar
  • 398k
4 votes

Sampling Implicit functions

How to sample points on f[x, y] == c without explicitly solving for y? In old versions of Mathematica, Nasser's method is what ...
J. M.'s missing motivation's user avatar
4 votes

Sampling Implicit functions

For random sampling, one can use regions and RandomPoint: ...
Michael E2's user avatar
  • 238k
4 votes

Finding the periodicity (or wavelength) in approximately periodic data irregularly sampled

Try using Periodogram. See for more HERE. In short on an example, let's take temperature data - about 2 decades, sampling monthly: ...
Vitaliy Kaurov's user avatar
4 votes
Accepted

Speeding up RandomVariate with custom probability distribution

...
Bob Hanlon's user avatar
  • 160k
4 votes
Accepted

Pick random value based on list of probabilities

SeedRandom[1]; RandomChoice[WeightedData @@ Transpose[probabilities], 5] {12500, 4500, 12500, 5500, 5500} Alternatively, <...
kglr's user avatar
  • 398k

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