37 votes
Accepted

Modeling the spread of an infection in networked computers

If it is at all an option to represent the grid as a 2D list instead of a list of infected coordinates, I would model this is a cellular automaton. What you've essentially got is an outer totalistic ...
user avatar
  • 8,584
25 votes

Unexpected behaviour from Table[]

This is just a long comment trying to shed light on where the problem may be coming from. Since version 10.2, the following is valid syntax: Table[x, 5] Before ...
user avatar
  • 227k
18 votes
Accepted

multiple reflections of a laser beam in a triangle

Based on some geometric operations such as reflection and line-line intersection (LLI), I wrote up a small code. Hope this could be a starting point to build a more compact ...
user avatar
15 votes
Accepted

How to programmatically specify multiple iterators?

What you actually want is to create a Sequence from the Table to be used as your iterators. You can do this with ...
user avatar
14 votes
Accepted

Why can't I create {a,a,a,b,b,b,b,b,c,c} from x={a,b,c}; f={3,5,2}; Thread@Table[x,f]?

This is an evaluation order issue. x and f need to expand (evaluate) to {a, b, c} and ...
user avatar
  • 265k
13 votes

RecurrenceTable iteration variable not localized? Bug or user error?

As Bob Hanlon's answer points out, RecurrenceTable does not hold its arguments, but most especially, it does not hold its iterator arguments. This must surely be ...
user avatar
  • 67.3k
12 votes

Modeling the spread of an infection in networked computers

Non CellularAutomaton solution, using @MartinEnder's suggestion of FixedPointList as opposed to ...
user avatar
  • 7,769
12 votes

How can I use a loop with an iterator in order to evaluate a function?

x = {1, 2, 3, 4}; y = {0, 1, 2, 5}; Listable >> Properties and Relations: "A function implemented in terms of a listable operation may not need the Listable ...
user avatar
  • 350k
11 votes
Accepted

How to iterate over the columns of a Dataset?

Here an approach that uses some Dataset related functionality. Doesn't look too readable to me, but in its core it uses the column names to access the data-set and ...
user avatar
  • 111k
11 votes

RecurrenceTable iteration variable not localized? Bug or user error?

Unlike many other functions that use an iterator, RecurrenceTable does not have the attribute HoldAll. Presumably, this ...
user avatar
  • 123k
11 votes

multiple reflections of a laser beam in a triangle

Instead of thinking too hard, we can let NDSolve take care of it, using WhenEvent to handle the reflections. First, set up 3 ...
user avatar
  • 18.1k
9 votes

What is the correct way to perform the Gram-Schmidt process?

Well, as others have said, you could use Orthogonalize to solve this problem, and it will likely be the fastest way to do so, but let's assume that (for whatever ...
user avatar
9 votes

Changing iterator inside a Table?

Use the correct iterator for the job, in this case use While instead of Table: ...
user avatar
  • 63.5k
8 votes
Accepted

Procedural to functional style

...
user avatar
8 votes

How to get the current index during a Scan iteration?

A scan operation doesn't really have an index, but you can get the effect you want by introducing a counter. ...
user avatar
  • 106k
8 votes
Accepted

Basins of attraction of equilibrium points

I think there maybe be a sign error in the maths, bear with me. Given your V[x_, y_] := 1/2 (x^2 + y^2) - y (1/3 y^2 - x^2) we can find the partial ...
user avatar
  • 7,704
8 votes

What is the correct way to perform the Gram-Schmidt process?

As Michael Witt has mentioned this is mainly interesting as a learning exercise as there is Orthogonalize. As such, I think it is worth mentioning that it is quite ...
user avatar
  • 23.1k
8 votes
Accepted

Calculating the Feigenbaum Constants

Several changes are required to obtain the desired results. First, the syntax error mu[n] == mu must be replaced by mu[n] = mu. ...
user avatar
  • 58.6k
8 votes
Accepted

Applying loop functions with input list of iterators

You need to use SlotSequence (##) in place of Slot (#). # refers to the first element (in your case to {a, 0, 4}) in a ...
user avatar
  • 350k
8 votes
Accepted

Function to create random matrix, then a simulation. *EDIT* Create two functions

Update: Animation of fire-spreading: ...
user avatar
  • 350k
8 votes
Accepted

Trouble iterating my forest fire simulation

I found your simulation idea interesting, so I decided to look into the problem. What I found was that your implementation of nextState is mostly where the fault ...
user avatar
  • 106k
7 votes
Accepted

Iterating `Log` infinitely

You can use FixedPoint: FixedPoint[Log[3.5 #] &, 3.5] == -ProductLog[-1, -1/3.5] True ...
user avatar
  • 33.3k
7 votes
Accepted

Skipping over iterator values in a Table

You can do this without Table: g[k_] := k^2 + 1 Map[If[# != 6, f[#] = g[#], f[#] = 1] &, Range[10]] {2, 5, 10, 17, 26, ...
user avatar
  • 32.5k
7 votes

How to iterate over the columns of a Dataset?

To get the data arranged for use in ListPlot, you'll have to use 'Normal - e.g. like this: ...
user avatar
  • 95.3k
7 votes
Accepted

ReplaceRepeated as a Looping construct?

Using the shortcut //. together with a MaxIterations options ...
user avatar
  • 27.1k
7 votes
Accepted

Do-Command around entire Notebook (by iterating it from another notebook?)

Indeed, the existing notebook can be called repeatedly from another notebook, which iterates over the desired parameters, passing them to the existing notebook, which then passes the answers back to ...
user avatar
  • 58.6k
7 votes

Modeling the spread of an infection in networked computers

The demonstration of CellularAutomaton is impressive but it is far from necessary for this problem. I propose ListCorrelate ...
user avatar
  • 265k
7 votes

How to programmatically specify multiple iterators?

Perhaps you can avoid Do and instead use Tuples: Tuples @ Range[0, {0, 1, 2}] {{0, 0, 0}...
user avatar
  • 124k
7 votes
Accepted

Incorrect syntax highlighting? "Variables made special by use in arguments" not working

Welcome to MMA SE! (Note that I think you shouldn't be using Evaluate there: consider i=3; Do2[Print[i], {i,5}].) Syntax ...
user avatar
  • 8,418
6 votes
Accepted

Table with multiple iterators running parallel

There are two easy approaches that come to mind. The first is to simply use MapThread. ...
user avatar
  • 265k

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