Linked Questions

36 votes
6 answers
7k views

Finding all elements within a certain range in a sorted list

Suppose we have a sorted list of values. Let's use list = Sort@RandomReal[1, 1000000]; for this example. I need a fast function ...
Szabolcs's user avatar
  • 235k
32 votes
1 answer
4k views

Gillespie Stochastic Simulation Algorithm

The Gillespie SSA is a Monte Carlo stochastic simulation algorithm to find the trajectory of a dynamic system described by a reaction (or interaction) network, e.g. chemical reactions or ecological ...
István Zachar's user avatar
15 votes
3 answers
2k views

Is there a built-in function to do binary search?

Is there a built-in function to do binary search? Say, given a list (sorted) and a number, find the position which keeps the listed sorted when the number is inserted. I know that ...
MMM's user avatar
  • 643
14 votes
8 answers
2k views

Given an ordered set S, find the points in S corresponding to another list

Given a sorted list of numbers $S$, I want to create a function that accepts a list of numbers $L$ and for each number $l \in L$ it returns the index of the largest number $s \in S$ such that $s<l$....
Carl Woll's user avatar
  • 131k
11 votes
7 answers
3k views

How to plot a list to look like step function?

Suppose I have the following simple list. l = {0,2,5,9,14}; I want to to make a plot that looks like the figure below. I.e. I want to have a horizontal line ...
Turbotanten's user avatar
9 votes
3 answers
694 views

ListPlot InterpolationOrder->0 datapoint centered

it is possible to get a histogram style in ListPlot using InterpolationOrder->0 ...
Markus Roellig's user avatar
7 votes
1 answer
103 views

Set user-defined uneven step size in ListStepPlot

I want to plot the following data as steps: Ydata={2,4,6,8,10}; Xdata={2,8,18,34,64}; halfbinsize={2,4,6,10,20}; I want to include the bin-size (or half-bin-size) ...
BabaYaga's user avatar
  • 1,846
6 votes
6 answers
297 views

Picking element from continnuous segment of list according to criteria

From list like: {1, 2, 3, 4, 5, 6, 20, 21, 22, 23, 24, 25, 26, 27, 28, 100, 101, 102, 103, 104} I need to pick position of number that is greatest in continuous ...
Dragutin's user avatar
  • 920
6 votes
2 answers
316 views

Adding a piece-wise function and its shifted version by list manipulations

I have a piecewise function represented by two lists, x= {0, 30, 60, 120, 150, 180}; y= {0, 1, 0, -1, 0}; and the plot of this function is . Now I would like ...
nanjun's user avatar
  • 1,297
5 votes
4 answers
5k views

How to make multiple if statements?

I know Mathematica's if format is If[test, then result, else alternative] For example, this ...
user12289's user avatar
  • 311
5 votes
3 answers
472 views

How to complete function which is not defined for all interval

I have a function testF22 like this ...
Zlelik's user avatar
  • 531
3 votes
3 answers
2k views

For-loop not working as I expect

I want to do this: When 10 <= t < 130, give t -> 1; When 130 <= t<300, give <...
Yuuhsing Tuan's user avatar
3 votes
3 answers
431 views

Zero-order interpolation not going fully around

Connected to this question, I want to do a zero-order interpolation of a bunch of datapoints which is periodic. The code I use is as follows: ...
Michiel's user avatar
  • 355
3 votes
3 answers
495 views

Find first position satisfying condition, which is true after a certain element

Can we find the first position of elements of a list satisfying a condition, with good performance, if the conditions is a tail condition of the list. What is tail condition ? (the term is informal, ...
imida k's user avatar
  • 4,285
3 votes
1 answer
1k views

List plot joined with stair steps instead of diagonal lines

What's a simple way to plot a list of points so that they're joined with stair steps instead of straight lines between the points? I'd imagine something like... ...
Sean's user avatar
  • 535

15 30 50 per page