# Questions tagged [iterators]

Questions on using and specifying iterators used in Mathematica functions.

160 questions
Filter by
Sorted by
Tagged with
51 views

### Supplying a seed for an iterative method in LinearSolve

Just a quick question. Does anyone know if it is possible to supply a seed for the iterative methods in LinearSolve? I have a large sparse system, and even using some Krylov iterative solver, my ...
111 views

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

This example is obviously not useful on its own, but it will cover everything I actually need to know for a more complicated function I'm making. The example is to recreate the ...
106 views

### Exporting specific frame of ListAnimate

Imagine I have a certain list of Graphics-type objects that I then incorporate into ListAnimate ...
115 views

### Iterative function

I would like to write a bit of code that does the following. Pick a random number from 1 to 20 (inclusive) then if that number is < 15, stop if that number is > 15 pick 2 numbers from 1-20, and ...
100 views

### Repeating and Sequencing Procedures with two Do-loops

I have a Do loop where I'm looking for the value of certain parameters that respect the conditions inside an If, and with those values, a run another Do to make another calculation of an expression ...
33 views

### Custom Table, for iterating over permutations

It is common that I iterate over all permutations of 1,2...,n, either by making a table or performing a sum. Instead of creating the set of all permutations, it would be better to iterate over them. ...
129 views

### Trouble iterating my forest fire simulation

I'm having some trouble iterating my simulation of a forest fire. I'm new to Mathematica, so apologies for poor coding. I'm sure there are far neater and more efficient ways of doing this, but I would ...
222 views

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

How can I write a function with parameters b, i, and j, which would return a i x j array of 0s, 1s, and 2s, but the array needs to be populated randomly with 0s and 1s which have respective ...
292 views

### Function representing a forest fire after one time step

How can I create a function that would have as its argument an array mat of 0s, 1s, and 2s where the 2s are burning trees and the function would give an array that represents the forest after one time ...
42 views

### solve for variable in iterator limit

Why can we not solve for P in the iterator limit in the problem below? How can it be solved? ...
112 views

### Can one make Do'-Loops of arbitrary depth?

In the documentation for the Do[...] function, a loop of nesting up to any number of layers is supported. But to apply their function, one needs to know ahead of time how many layers of loops they're ...
131 views

### Strange indexing behavior by Table

Maybe I do not understand how Table works, but I find this very confusing and it took me a long time to debug because this was part of a much more complicated routine. I am trying to build an array ...
49 views

### Two different variables in a Do Loop

I am trying to use the code developed by @Alex Trounev here: Numerical solution of an iterative equation for different kind of q. I am not sure how to incorporate ...
58 views

### Need help with NestList [closed]

NestList::intnm: Non-negative machine-sized integer expected at position 3 in NestList[#1 + t&, 0, 8.]. What does the above error mean and how can I refer to result of ...
78 views

### Using condition for each element of a matrix

I'm trying to write a code so that for each element of matrix C2 if the element i,j is equal to element j,i and it is equal to 1 then it adds one to a variable and if not it adds one to another ...
192 views

67 views

### Code to generate many Do-loops, where the $i$-th loop has upper bound given by $f(i$)

How do I get Mathematica to run an arbitrary number of Do-loops, where the i-th loop it upper bound given by some function $f(i)$? I badly need help with this. Let's denote the desired code by ...
397 views

### 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]?

ClearAll[x, f] x = {a, b, c}; f = {3, 5, 2}; Thread[Table[x, f]] produces Table::nliter: Non-list iterator f at position 2 does not evaluate to a real numeric ...
235 views

### How do I evaluate my functions over a range of values? [closed]

I want to use the list of data which will come from MapData1 (in code); the first element is θ and second is Action(I). I want to use this Action(I) and Angle(θ) in ...
198 views

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

I'm trying to evaluate a function, that depends on two variables, in a specific set of values. I will write an example, but my system is more complicated. ...
93 views

### Iterative comparison between different vectors

I have some soccer outcomes for each league round to import in a data form similar to that: ...
68 views

### Stop (Parallel)Table evaluation when wanted case is found

I have to go through a long list of evaluations, for which I suppose Table instead of For or ...
74 views

### Making a recursive function

Suppose I have the following functions: a[x_] := x b[x_] := x (a[x]) - a[x] + 1 c[x_] := x (b[x]) - b[x] + 1 d[x_] := x (c[x]) - c[x] + 1 as you can see each ...
116 views

### Does lower case n have some significance in the Wolfram Language? [duplicate]

I am truly confused with this one, and maybe someone could help me to clear this up. I am running a Table[] that runs multiple neural networks in series on OpenAI'...
63 views

### Is it possible to generate iterators dynamically during parallel processing?

I have a parallel processing code written in Wolfram Mathematica, similar to: ...
128 views

### Iterating with Do rather than NestList

This code below works fine for me. ...
65 views

### Problem with iterations of Prepend/While

I am doing some work with black-scholes and am trying to find random interest rates based on some given information. This is my original code: ...
94 views

### How to iterate through a lists of lists and delete a certain element?

Say I have a list of lists such as l1 = {{a, 2}, {a, 5}, {b, 3}, {b, 9}} How would I iterate through the list and delete all the lists with the first element b ...
320 views

### How to nest multiple functions with multiple variables

I'm trying to solve coupled equations by using iteration. There are two functions $G$ and $H$ that I need to find. In the code, G and H are actually lists of numbers. I start by using a simpler ...
53 views

### Nested Table With Iterable Bounds

I have a set of data that looks vaguely like this: ...
43 views

### Iterate through union of lists to correspond to each element a list of names of the lists to which the element belongs

Say I have several lists L1, L2,L3 an I want to correspond to each of the elements of Union[L1,L2,L3] a list of list names to ...
77 views

### How to iteratively (or most efficiently) create such list?

Update A very crude attemp ...
171 views

### Automating a large operation by making a function

I would like to automate the following operation. To be transparent I shall put my code into separate chunks and explain the process. Suppose I have the following: ...
86 views

### For- loop which can reuse updated values [closed]

Eout = E^x ; For[kz = 1, kz < 4, kz++, Print[Eout1[kz] = Eout]; Print[kz]] The output is E^x 1 E^x 2 E^x 3 But what ...
535 views

### Dot products and For-loops

I'm taking a class where we're working with matrix applications inside of Mathematica. In this case, we're analyzing senatorial votes that have been numericized so that a value of 1 corresponds to "...
101 views

### How can I iterate across a list of triples?

i just started to use Mathematica and Im completely new to programming. So i'm some kind of noob in the purest form.. I'm trying to transform a coordinate system into a different one. I'm using <...
127 views

### Creating matrices using a Do-loop

Here is an image of current assignment; I am not able to do step 6 to 8 When I try to do the Do-loop, it states that the {i, j} does not have appropriate bounds. ...
54 views

### ListCountourPlot does not show any result [closed]

I was trying to show the heat conduction of Laplace equation problem.But the plot does not show properly ...
82 views

### Defining iterative algorithms [closed]

Assume the iterative algorithm of interest to be as follows: ...
712 views

### Multivariate Newton-Raphson method and FindRoot module [closed]

Let's suppose that we have the following equation ...
493 views

### Golden section search method that terminate after $n$ iterations

I am attempting to code a program that executes the golden section search method, and I would like to terminate the computations after $n$ iterations, where the user decides what $n$ is. My code works ...
529 views

### How to programmatically specify multiple iterators?

How to use Row[Table[{B[i],0,i},{i,0,2}],","] directly in Do command? I mean that the following command ...
1k views

### Encountering 'Error: Set::setraw: Cannot assign to raw object' during procedural function definition

Sorry for the rather vague title, but I don't know what is wrong with my code. Here is a Ruby version of what I'm trying to do: ...