Tagged Questions

Questions about looping or recursive structures that do not complete. Such structures include While, For, FixedPoint, and NestWhile. Also user defined functions that make recursive calls to themselves.

learn more… | top users | synonyms

1
vote
1answer
38 views

Coding `While` loops

I am interested in replicating the code in this question on MSE, whose contents I have copied for ease of reading: Pseudocode: Consider that 1 is the starting index of a list 1.  input natural ...
1
vote
1answer
166 views

Problem with FOR Loop in MATHEMATICA [closed]

I have some problem in solving two coupled polynomial equations in Mathematica. I have used FOR loop and this program starts running indefinitely for Infinite time, and therefore I got stuck. My ...
1
vote
1answer
124 views

Solving a trigonometric equation with one parameter

I have the following equation: 2 a^2 k^2 Sin[b k] - 6 a (k Cos[b k] - Sin[b k]/b) == 0 I set the value of b to 1, and I want ...
1
vote
2answers
122 views

Minimize loop optimization

I'm new in Mathematica 10. So far, I have a two variable-function and I've use Minimize to find the optimal solution. Nevertheless, I'd like to make a sensibility analysis and study how this optimal ...
2
votes
1answer
55 views

Clear inside a loop

I want to solve a system of differential equations and each time I want to change two parameters. To prevent wrong result I want to clear every assignment after solving the equations in each ...
1
vote
2answers
177 views

Loop until convergence of two variables

I have the following program which i need to repeat steps until until two variables converge and I want this to be printed with the number of iterations: What I have : Input variables: ...
1
vote
1answer
121 views

Check every list element for appearance

I'm used to MATLAB so this might be a stupid question but Mathematica is freaking me out. I have a big matrix with the following format: ...
5
votes
1answer
84 views

How do I limit the iterations in a while loop?

Is there a way to limit the number of iterations in a while loop? Right now I am cleaning up the code, and for now if I make a mistake, the loop keeps going forever. I'd like to be able to limit the ...
2
votes
1answer
137 views

Loop in solving multiple matrix calculation

I am wondering is there a way to use loop, like Do, For, to rewrite the last line in the code. I tried to use ...
2
votes
2answers
212 views

Generating complete lists of polynomials

I would like to generate a list of all $3$-variable Laurent polynomials with non-negative integer coefficients using a looping construct so that I can, one-by-one, check them for specific ...
0
votes
1answer
86 views

looping in mathematica for using the current value as initial state of next value [closed]

i have some initial state $psi[x,t]$. I perform some operation on it and store the value in another state $pi1[x,t]$. Now on the next step i have to use $psi1[x,t]$ as initial state and perform the ...
0
votes
1answer
76 views

Running function - updating list - run function etc

I am making a larger program, so I would prefer to give a short example of my problem: ...
1
vote
2answers
220 views

If/else re-evaluate (integer only solutions)

I am trying to get Mathematica to do an if/else loop. I can get as far as the if, but I would like it to re-evaluate until only integer solutions are found. Here is what I have: ...
3
votes
1answer
104 views

Recursion when randomizing elements in a list

I want to randomize certain elements of a list; Since the code list = {a, b, c, d, e, f, g}; list[[{1, 3, 5}]] = RandomSample@list[[{1, 3, 5}]]; list works fine, ...
2
votes
1answer
233 views

Infinite loop with While is very processor-intensive [closed]

This simple line of code: While[True, Pause[1]] uses 55% of one CPU core on my computer. Are there more efficient ways to construct simple infinite loops in ...
1
vote
3answers
212 views

Code hanging inside a For loop

I'm pretty new to Mathematica (and functional programming in general). I'm working on some code to find winners (maximal values) in a list. The code I have that is hanging is this line. ...
0
votes
2answers
196 views

Conditional Table

I have following : SeedRandom[2] Table[Table[RandomInteger[100, {100, 10}][[r, s]] == x[r + s], {r, 1, 10}], {s,1,10}] How can I set condition inside Tables?Such ...
0
votes
1answer
126 views

While loop not breaking when condition is met

I am having trouble with the while loop not breaking, ...
3
votes
2answers
212 views

Export in Manipulate, infinite loop

I want to make export of a plot inside Manipulate, but only once. However, this code runs infinitely and does export infinitely: ...
2
votes
2answers
178 views

While loop doing cell evaluation not completing

I am trying to get a loop structure using While to repeatedly evaluate another cell referred to in its body (using a cell tag). ...