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 ...
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 ...
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 ...
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
...
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 ...
14
votes
How to plot an imaginary number, i, power tower as done in the following way?
Plot the left graph.
...
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 ...
12
votes
Modeling the spread of an infection in networked computers
Non CellularAutomaton solution, using @MartinEnder's suggestion of FixedPointList as opposed to ...
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 ...
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 ...
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 ...
9
votes
Changing iterator inside a Table?
Use the correct iterator for the job, in this case use While instead of Table:
...
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. ...
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 ...
8
votes
Accepted
Function to create random matrix, then a simulation. *EDIT* Create two functions
Update: Animation of fire-spreading:
...
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 ...
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:
...
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 ...
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 ...
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}...
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 ...
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 ...
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 ...
6
votes
Accepted
What is wrong with the Mann iteration?
The following approach might be more "standard Mathematica":
...
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}
6
votes
Accepted
Nest or fold a series of geometric transforms
If elements of tList are TransformationFunctions, you can use a combination of Composition ...
6
votes
Accepted
Changing iterator inside a Table?
There aren't many functions that create indeterminate-length lists. NestWhileList comes to mind. Sow/...
6
votes
6
votes
How to reuse an iterator in different functions?
iter = {i, 0, 10};
Since Table "holds" all its arguments you must Evaluate iter
<...
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 &...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
iterators × 180list-manipulation × 53
plotting × 19
procedural-programming × 17
functions × 16
iteration × 14
function-construction × 12
equation-solving × 11
matrix × 9
core-language × 8
map × 8
numerics × 6
programming × 6
performance-tuning × 5
calculus-and-analysis × 4
syntax × 4
summation × 4
random × 4
recursion × 4
scoping × 4
simulation × 4
infinite-loop × 4
differential-equations × 3
graphics × 3
probability-or-statistics × 3