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 ...
Martin Ender's user avatar
  • 8,764
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 ...
Szabolcs's user avatar
  • 235k
20 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 ...
Joo-Haeng Lee's 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 ...
NonDairyNeutrino's 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 ...
Mr.Wizard's user avatar
  • 271k
14 votes

How to plot an imaginary number, i, power tower as done in the following way?

Plot the left graph. ...
cvgmt's user avatar
  • 71k
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 ...
WReach's user avatar
  • 68.8k
12 votes

Modeling the spread of an infection in networked computers

Non CellularAutomaton solution, using @MartinEnder's suggestion of FixedPointList as opposed to ...
martin's user avatar
  • 8,678
12 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 ...
Chris K's user avatar
  • 20.1k
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 ...
kglr's user avatar
  • 393k
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 ...
Bob Hanlon's user avatar
  • 156k
9 votes

Changing iterator inside a Table?

Use the correct iterator for the job, in this case use While instead of Table: ...
Jason B.'s user avatar
  • 68.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. ...
bbgodfrey's user avatar
  • 61.4k
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 ...
kglr's user avatar
  • 393k
8 votes
Accepted

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

Update: Animation of fire-spreading: ...
kglr's user avatar
  • 393k
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 ...
m_goldberg's user avatar
  • 108k
8 votes

How to plot an imaginary number, i, power tower as done in the following way?

Plotting the real part on the horizontal and the imaginary part on the vertical axis, as is common: ...
Roman's user avatar
  • 47.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 ...
bbgodfrey's user avatar
  • 61.4k
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 ...
Mr.Wizard's user avatar
  • 271k
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}...
Carl Woll's user avatar
  • 131k
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 ...
thorimur's user avatar
  • 9,010
6 votes

Unexpected behaviour from Table[]

The above analysis is quite correct. I also don't disagree that the decision to not require braces was questionable. I spent quite a period of time in this spring analyzing the design issues ...
Itai Seggev's user avatar
  • 14.1k
6 votes
Accepted

PerfectNumber messes with my iterator

The error message does not come from your own Do loop, but from a Do loop inside the ...
Arnoud Buzing's user avatar
6 votes
Accepted

What is wrong with the Mann iteration?

The following approach might be more "standard Mathematica": ...
MarcoB's user avatar
  • 66.8k
6 votes
Accepted

use Range to form a vector

Array[y, 7, 1, Join] {0, 0, 0, I t, 0, 0, 0, I t^2, 0, 0, 0, I t^3, 0, 0, 0, I t^4, 0, 0, 0, I t^5, 0, 0, 0, I t^6, 0, 0, 0, I t^7}
kglr's user avatar
  • 393k
6 votes
Accepted

Nest or fold a series of geometric transforms

If elements of tList are TransformationFunctions, you can use a combination of Composition ...
kglr's user avatar
  • 393k
6 votes
Accepted

Changing iterator inside a Table?

There aren't many functions that create indeterminate-length lists. NestWhileList comes to mind. Sow/...
Michael E2's user avatar
  • 235k
6 votes

Nested floor functions

Using Nest to get 3 nested Floor functions: Nest[Floor[#*x^2] &, 1, 3]
Sjoerd Smit's user avatar
  • 23.2k
6 votes

How to reuse an iterator in different functions?

iter = {i, 0, 10}; Since Table "holds" all its arguments you must Evaluate iter <...
eldo's user avatar
  • 64.5k
6 votes

How to reuse an iterator in different functions?

Not really an answer, and maybe pedantic, but nevertheless... You probably don't want to do that at all (although the Evaluate suggestions work fine if this is a &...
lericr's user avatar
  • 26.8k

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