Questions tagged [iterators]
Questions on using and specifying iterators used in Mathematica functions.
150
questions
1
vote
2answers
93 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 ...
2
votes
1answer
99 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 ...
2
votes
1answer
46 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 ...
1
vote
0answers
43 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 ...
0
votes
2answers
56 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 ...
1
vote
1answer
88 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_{...
2
votes
2answers
105 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....
1
vote
1answer
48 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 ...
5
votes
1answer
103 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 ...
0
votes
1answer
91 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] ...
1
vote
1answer
29 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-\...
1
vote
1answer
65 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 ...
6
votes
1answer
383 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 ...
1
vote
1answer
99 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 ...
8
votes
1answer
177 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.
...
4
votes
1answer
88 views
Iterative comparison between different vectors
I have some soccer outcomes for each league round to import in a data form similar to that:
...
2
votes
1answer
63 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 ...
3
votes
1answer
57 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 ...
0
votes
1answer
106 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'...
1
vote
0answers
55 views
Is it possible to generate iterators dynamically during parallel processing?
I have a parallel processing code written in Wolfram Mathematica, similar to:
...
3
votes
2answers
125 views
0
votes
1answer
64 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:
...
2
votes
2answers
67 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 ...
4
votes
1answer
209 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 ...
1
vote
2answers
49 views
1
vote
1answer
34 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 ...
1
vote
2answers
75 views
0
votes
1answer
145 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:
...
1
vote
0answers
85 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 ...
4
votes
3answers
474 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 "...
1
vote
2answers
85 views
How can I iterate across a list of triples?
i just started to use Mathematica and I`m 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 <...
0
votes
1answer
101 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.
...
1
vote
1answer
53 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
...
1
vote
1answer
79 views
Defining iterative algorithms [closed]
Assume the iterative algorithm of interest to be as follows:
...
1
vote
2answers
500 views
Multivariate Newton-Raphson method and FindRoot module [closed]
Let's suppose that we have the following equation
...
2
votes
1answer
376 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 ...
12
votes
3answers
503 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
...
3
votes
1answer
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:
...
2
votes
1answer
124 views
How to change the dimension of a tensor inside a loop using XAct/XTensor?
I'd like to define a function CDOrder[k] to compute the k-th order covariant derivative of a vector ...
0
votes
0answers
128 views
Operation on sublists with multiple arguments
I have a list and add only the values which are > 0 with:
Total[Cases[mylist, x_ /; x > 0]]
How to do this if I now have a list of sublists?
...
4
votes
2answers
132 views
use Range to form a vector
I have a function
y[k_]:={0,0,0,I*t^k};
and I need to get a vector
Join[y[1],y[2],y[3],y[4],y[5],y[6],y[7]]
and it is just ...
6
votes
4answers
559 views
Applying loop functions with input list of iterators
Given an iterator, I am trying to generate a table of all possible pairs of values. The form of the iterator I'd like fixed, because I want to run other loops with it as well. The closest to what I ...
0
votes
0answers
95 views
Iterating a Module
I have a Module that can act on other Modules, which is given as
Kk[EE,p,z1,z2,z3,K_func]
and I am trying to iterate it, such that
...
1
vote
2answers
109 views
What is wrong with the Mann iteration?
I have written the Mann iteration's code for the mapping $\frac{z}{1+z^2}$, in Mathematica, but it is very slow. In fact it needs more than 200 seconds for obtaining 17th iteration, while Matlab does ...
1
vote
3answers
266 views
integral equation iteration
So I am trying to recreate the numerical treatment in this papir (https://journals.aps.org/prb/abstract/10.1103/PhysRevB.29.130), equation 3.7. The main point is to try to solve the following equation
...
1
vote
1answer
60 views
How to implement recurrence operations efficiently?
This question is related to this one. I basically want to partition a volume recursively.
Consider a volume as
vol = ExampleData[{"TestImage3D", "MRbrain"}];
...
2
votes
0answers
52 views
Using Iterators within the WebSearch Command
I am currently trying to use the WebSearch command within Mathematica to search names from a Dataset that I have already imported. The names that I am trying to search are located in the 4th column of ...
1
vote
1answer
140 views
0
votes
0answers
106 views
Variables defined modulo $\pi$ and avoiding singularities; phase plotting for a map
I have the following $2$-dimensional implicitly defined map
...
2
votes
1answer
149 views
How to plot a phase portrait of a map for many initial points?
Suppose I have a 2-dimensional map $x_{n+1} = f(x_{n},y_{n}), \quad y_{n+1} = g(x_{n},y_{n})$, and a number of initial points $(x_{0}, y_{0})$ in some given range. I take each initial point and ...