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

0
votes
1answer
32 views

While-loop not converging even when termination condition is met [closed]

I am trying to solve a self-consistent loop for a system involving numeric integrations, but even though the condition that I have set is met, the loop does not break, but loops indefinitely. Here is ...
0
votes
2answers
44 views

MousePosition and While loop Control, maybe Dynamic in While statement?

I would like to write a simple code that samples mouse position as frequently as the system can handle (with minimum dt) starting when the mouse position leaves a region and ending when the mouse ...
0
votes
1answer
58 views

FindRoot, Loops and multivariate nonlinear system

I posted a question yesterday asking how I could get all the solutions to my system of 4 nonlinear equations with 4 unknowns. I gave up on this since it seems ...
1
vote
1answer
89 views

Iteration convergence of Newton approximations

I am trying to determine for which initial values Newton's approximation of specific functions (EX: f(x)=x^2 -1)converge and to what numbers it will converge to. *Where Newton's approximations are ...
0
votes
0answers
70 views

How to prevent long evaluation and infinite loops

I'm new to this, so sometimes I accidentally ask Mathematica to do calculations with numbers so big that it can't handle it and it immediately freezes my laptop to the point where there's nothing I ...
0
votes
2answers
83 views

`Do` looping - break & output based on pattern

I have the following loop that I would like to stop after the pattern repeats & output cycle length: ...
0
votes
1answer
76 views

Problem with recursion depth

I want to solve a problem where I need to compute the Euler-Lagrange equation. However I receive a recursion problem, and I don't understand why. ...
-1
votes
1answer
62 views

Calculating sum

mm1 = {1 , 2}; mm2 = {3, 5}; xxm = mm1*x + mm2*y ; mm6 = 0; m7m = Do[mm6 = mm6 + Replace[xxm, {mm1 -> mm1[[i]], mm2 -> mm2[[i]]}, {i, Length[mm1]}]; mm6 ...
0
votes
2answers
80 views

Compile a Module wich has a loop with undetermined bound

Suppose I have such a module as below: test[int_] := Module[{m}, m = Table[i, {i, 1, 10}]; Do[m[[i]] = i*i, {i, 1, int}]; Return[m] ] The bound for ...
4
votes
1answer
99 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
180 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
164 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
162 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
72 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
243 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
135 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
136 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
174 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 ...
0
votes
1answer
97 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
79 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
332 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
110 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
340 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
218 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
273 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
191 views

While loop not breaking when condition is met

I am having trouble with the while loop not breaking, ...
3
votes
2answers
261 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
240 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). ...