Skip to main content

Questions tagged [iterators]

Questions on using and specifying iterators used in Mathematica functions.

Filter by
Sorted by
Tagged with
4 votes
2 answers
236 views

Given two functions, generate all nested applications of the functions to a given order

I have two functions $f$ and $g$. Given some order parameter $n$, I want to created all nested applications of $f$ and $g$ and save them in a list. For example, for order 1 we will have ...
JohnnyB's user avatar
  • 95
3 votes
3 answers
211 views

How to reuse an iterator in different functions?

How can I reuse iterators? For example, instead of Table[i, {i,0,10}] Table[i^2, {i,0,10}] Table[f[i], {i,0,10}] write something like ...
homocomputeris's user avatar
1 vote
1 answer
106 views

A way to generalize my code for this non linear ODE problem

I am trying to solve the differential equation $y''(x) = y(x)+\sin[y'(x)]$ using "Fixed Point Iteration" over the interval $[0,1].$ Now using central difference method I arrived at the ...
Learner's user avatar
  • 219
0 votes
1 answer
51 views

How to make this bisection code work for different equations?

I am very new to Mathematica. I have this code of Bisection Method for finding a root of a polynomial. ...
Learner's user avatar
  • 219
0 votes
0 answers
52 views

Multiple iterators and vectors in a region

I'm interested in vectors whose coordinates are multiple of icosahedron coordinates of the vertices times $n+\tau m$ with $n,m$ integers. Then I want to see if they fall inside an icosahedral region ...
Dac0's user avatar
  • 243
1 vote
3 answers
516 views

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

Can somebody explain what two variables exactly they have plotted against each other to get such graphs, and how one would go about getting this graph in Mathematica?
boii's user avatar
  • 43
-2 votes
1 answer
117 views

How to plot an iterative function of y(n+1) against y(n) in order to analyze the convergence of real power towers? [closed]

I'm new to mathematica and was wondering how to plot an iterative graph for power towers. If there is a power tower y= x^x^x^x^x^x^... we can rewrite it as an iterative equation in the following way: ...
boii's user avatar
  • 43
0 votes
1 answer
120 views

How can I nest a complex function?

I am examining the mandelbrot set so I need to iterate the function f[z_Complex, c_] := (z)^2 + c Besides, I want to choose the complex numbers dynamically from ...
Süleyman Küçük's user avatar
1 vote
1 answer
98 views

Inconsistent results solving system of equations with FindRoot

I have been trying to solve the following problem (Is basically a physics problem: an expansion of equations of state up to 1st order of the order parameter in order to solve for the critical ...
Greivin Alfaro's user avatar
0 votes
0 answers
40 views

"ListPlot" of some probability distribution of a function under "NSum"

Sir, While trying to Listplot the Probability distribution of a function under command NSum, it shows some error messages and no plot is shown. the details of the inputs written in mathematica along ...
R. Bhattacharya's user avatar
0 votes
1 answer
70 views

How to optimize code for obtaining large data set?

In an application, I need to find a region where some conditions must be true. However, these conditions are made of interpolating function solved by ParametricNDSolve. I will give a toy model example ...
Lp_cam's user avatar
  • 1
4 votes
2 answers
173 views

Evaluation of an iterator construct containing Sequence in Table

The following code: Table[i*j, Apply[Sequence , {{i, 1, 3}, {j, 1, 2}}]] returns the error: Table::nliter: Non-list iterator Sequence@@{{i,1,3},{j,1,2}} at ...
StarBucK's user avatar
  • 2,164
2 votes
2 answers
137 views

Efficient alternatives to a Table based iteration

I have performed some operations using the Table iterator but I am looking for efficient alternatives to my approach. First, some preliminary code: ...
Tom6639's user avatar
  • 309
0 votes
0 answers
79 views

How to implement recursive function in While loop Module, calling on other functions

I am trying to implement a module such that it " takes a distance matrix, Q, and iterates the corresponding “Bellman operator” module written above until a final cost-to-go function (i.e. J) is ...
J0ta's user avatar
  • 115
2 votes
2 answers
450 views

In a for loop, how do I assign a table of values to a new variable for every iteration?

I am trying to create a divided differences table for a set of data of depth n, specified by the user. I am not sure how to create and assign a new variable name for each iteration of the for loop. ...
Swearingene's user avatar
2 votes
3 answers
291 views

Nested floor functions

I would like to compute a limit involving a particular nested floor function. For example: ...
MathRevenge's user avatar
1 vote
3 answers
77 views

Digits product and an iteration process

I would like to create a code which gives me the square of the product of the digits of a number, with the only rule that if a number has a 0, then it doesn't count in the product (for example, if the ...
MathRevenge's user avatar
2 votes
0 answers
26 views

Constructing Table iterators programmatically: how to avoid the non-list iterator error? [duplicate]

The following simple code of course works: Table[n^2, {n, 3, 15, 2}] (* Out: {9, 25, 49, 81, 121, 169, 225} *) I would then like to construct the iterator ...
cybervigilante's user avatar
6 votes
5 answers
451 views

Changing iterator inside a Table?

Consider Table[ If[i == 3, i = i + 2;]; i , {i, 1, 10}] {1, 2, 5, 4, 5, 6, 7, 8, 9, 10} The above output is not what I would expect (namely ...
Kagaratsch's user avatar
3 votes
2 answers
132 views

Generate a sequence of all cases

There is a sequence of numbers that satisfies $a_1=2$, $a_n-a_{n-1}\in \{1,3,5\}$ I tried to enumerate all possibilities using the code below ...
expression's user avatar
  • 5,652
6 votes
0 answers
102 views

WTC2021 Iterators Paclet download

At WTC2021 Roman Maeder gave a presentation about Iterators. In the presentation notebook it is mentioned that the code / paclet (Iterators-0.9.paclet) is provided as part of the presentation ...
Philipp's user avatar
  • 726
1 vote
0 answers
32 views

Repeated calculation with neural network measurement slows down

I have a list of 200 neural nets nets0. I have to measure the output of several layers of each of them on a list of 1000 associations ...
user40532's user avatar
  • 215
0 votes
0 answers
66 views

Generating iteration and constraint lists dynamically

I have a model for which I want to perform a set of calculations with successively deeper iterations and more constraint. In other words for a given value of a Do iterator, n, I want to: perform a ...
jmm's user avatar
  • 271
3 votes
0 answers
90 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 ...
Filipe Miguel's user avatar
5 votes
1 answer
232 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 ...
Lucas Mumbo's user avatar
2 votes
3 answers
143 views

Exporting specific frame of ListAnimate

Imagine I have a certain list of Graphics-type objects that I then incorporate into ListAnimate ...
sam wolfe's user avatar
  • 4,863
0 votes
3 answers
162 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 ...
Wombles's user avatar
  • 792
2 votes
1 answer
162 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 ...
Felipe Villazon's user avatar
1 vote
0 answers
74 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. ...
Per Alexandersson's user avatar
4 votes
1 answer
164 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 ...
user77287's user avatar
6 votes
2 answers
255 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 ...
jbl's user avatar
  • 347
5 votes
3 answers
350 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 ...
jbl's user avatar
  • 347
0 votes
1 answer
76 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? ...
r_al's user avatar
  • 33
2 votes
2 answers
171 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 ...
Joe's user avatar
  • 175
3 votes
1 answer
162 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 ...
anon248's user avatar
  • 614
2 votes
1 answer
62 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 ...
John's user avatar
  • 1,621
1 vote
0 answers
104 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 ...
Scott Constantine's user avatar
0 votes
2 answers
274 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 ...
Nishpish 's user avatar
1 vote
1 answer
720 views

Fixed point iteration with While or Do Loop

I need to write a while or do loop to perform the iteration $x_{n+1}=Cos(x_n)$ with initial value $x_0=1$ and stops when the absolute value of the difference between two consecutive iterations is $|x_{...
Asghar Bakerdar's user avatar
2 votes
2 answers
127 views

Using iterative functions to specifically sort a list

The following code sort the list li in a such way that consecutive terms $t_n,t_{n+1}$ are of the from ...{x_,y_}, {y_,z_}.... i....
azerbajdzan's user avatar
  • 18.8k
1 vote
1 answer
70 views

Use of a For/While loop inside another For/While loop for dual integration [closed]

Can anyone please give suggestion for using For/While loop inside For/While loop for integrating a function with respect to two variables say for- $\qquad r = (x^2 + (a/y^2))^(-1/2)$ Integration is ...
Proxy Kad's user avatar
5 votes
1 answer
135 views

Nest or fold a series of geometric transforms

I have a requirement to perform a series of GeometricTransformation[]s using the AfineTransform[] function. I use these to set ...
user74549's user avatar
  • 197
0 votes
1 answer
111 views

How I can plot the below map?

I have tried to plot the following map: $\qquad \begin{cases} y_{n+1}=r y_n^{x_{n+1}-x_{n+2}}\\ y_1=x_1-x_2 \quad \end{cases}$ using the code shown below. The error I have got is that x[1] - x[2] ...
zeraoulia rafik's user avatar
1 vote
1 answer
37 views

Plotting an iterated piecewise function with endogenous nodes

I am trying to plot a piecewise function that I can define recursively, where the nodes are endogenous as well. Basically, $f(l)=a^{t}$ when $l \in \left( \frac{\mu}{\alpha^{t-1}(1-\alpha)+\mu(1-\...
Federico's user avatar
1 vote
1 answer
84 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 ...
Camilo's user avatar
  • 13
7 votes
1 answer
445 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 ...
Display Name's user avatar
  • 2,029
1 vote
1 answer
797 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 ...
user68207's user avatar
8 votes
1 answer
362 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. ...
Nohora Alejandra Hernndez Cepe's user avatar
4 votes
1 answer
131 views

Iterative comparison between different vectors

I have some soccer outcomes for each league round to import in a data form similar to that: ...
Nate's user avatar
  • 401
2 votes
1 answer
127 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 ...
xiaohuamao's user avatar
  • 4,728