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

3
votes
1answer
29 views

While loop repeats itself using initialization cell

I am running While loops in an initialization cell for the purpose of submitting the notebook to the online cluster. However it appears to me that the While loop in an initialization cell would run ...
0
votes
0answers
30 views

Optimizing over every element in a vector [closed]

So I have a 16 element vector, called LUEigenvector, depending on a series of variables a1,a2,...b1,b2...c1,c2... All the elements depend on all the variables. I want to use NMinimize sequentially, ...
0
votes
1answer
117 views

For-loop function problem [closed]

I wrote the following true anomaly function based on a Fortran program that I found in a computational space flight dynamics book. The function uses an iterative method to calculate the true anomaly ...
2
votes
4answers
239 views

solve equation with loop

I want to solve equation with different variable and list answers in a table how can Solve it in a loop (Without repeating the equation) ...
-1
votes
1answer
67 views

Parallelize in Mathematica [duplicate]

Here is two test to understand the parallelize in Mathematica: ...
-1
votes
3answers
78 views

How to change function iteratively as a function of its previous form?

I am trying to do the following :- f[x_] := {x, 2}; Do[f[x_] :=Append[f[x], {x, 4}],{3}] % runs into recursion limit because I want to grow my function (which ...
0
votes
0answers
58 views

TimeConstrained Aborts not occuring when entire body of While is AbortProtected

In improving my code for this question over on Math, I seem to have run across a condition where TimeConstrained Abort[]s do not occur, but further computation is ...
0
votes
1answer
63 views

errors in simple for loops

Im trying to run the following code, which I have translated from Matlab. I created a for loop nested inside another for loop. mW is a matrix, and ...
4
votes
2answers
130 views

ReplaceRepeated as a Looping construct?

There are a lot of discussions about looping constructs (notable example here). Wolfram language guides, as usually, contain most relevant links. Looping constructs guide has the following part on ...
-3
votes
2answers
111 views

How to create a series using For loop.? [closed]

i want to create a series such as 10^n-1 * 10^n-2 *.......... * 10^2 * 10^1 using for loop ; here is my code. For[n=1, n<18, a=10^n; n++, b=(10^n)*a;]; ...
5
votes
3answers
400 views

How to calculate a list without loop?

I have pairs of numbers {a1, b1}, {a2, b2}, {a3, b3}, ..., ...
0
votes
2answers
62 views

How to evaluate function in the grid?

I have a function f[a_, b_]: = b^a + a b. a takes values {1,2,3,4}, and ...
1
vote
0answers
27 views

Repeat code segment from certain cell [closed]

If I have a lot of code and wish to repeat it in a different cell, but with some variables changed, how do I do it? (without copying and pasting) I tried using GoTo and Label but it did not recognize ...
0
votes
1answer
97 views

Looping things in Mathematica

So let me start by stating I'm really new to Mathematica. Being a biologist.. I'm trying to make two different loops. And I've been googling around and looking at some youtube video. But, I'm getting ...
0
votes
0answers
37 views

Impose a condition on a function in a loop

I am trying to calculate something in the following code and I need to omit the final values which are going to be infinity.obviously I want to extract the answers of H2[s] which are zero. ...
1
vote
1answer
63 views

Display a triangle that rotates at certain rate when space bar is held down?

This question is a follow up on: Open a pop up window that runs a calculation in loop until it is closed? How can I open a pop up to show a picture of a triangle that rotates by ...
3
votes
1answer
66 views

Open a pop up window that runs a calculation in loop until it is closed?

How should I construct a code which opens a pop up window, displays a constantly updating image in it and is terminated once the pop up is closed? The constant updating would be an infinite loop of ...
2
votes
3answers
115 views

How to check keys and values in nested Associations?

Considering we have a an association: ...
0
votes
1answer
55 views

Designing a loop that fetches 5 random vectors each with 5 components from a set of 10 until Linear dependence is found

I am currently trying to find a way to make a loop that will select 5 random columns without replacement of a 5x10 matrix until it finds a determinant equal to 0 out of the new matrix formed by the 5 ...
0
votes
2answers
60 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
122 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
140 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
125 views

How to prevent long evaluation and infinite loops [duplicate]

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
98 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
89 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
85 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
117 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
119 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
236 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
206 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
136 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
341 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
145 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
211 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
210 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
111 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
83 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
423 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
116 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
458 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
227 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
421 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
280 views

While loop not breaking when condition is met

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