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

-4
votes
1answer
43 views

I want to run 5 different simulation cases over an entire Mathematica Workbook?

I want to loop over the case numbers, so run cases 1 -5 without manually changing. caseNumber = 1; Which[caseNumber == 1, dataString = "Jan", caseNumber == 2, dataString = "Feb", caseNumber == 3, ...
1
vote
1answer
47 views

how to use loop function to add column heading and row heading

I have a raw data xsl file without heading column and column heading I want the A,B,C....J to be question 1, question2.....question J and 1,2,3 ....n to be participant 1, participant2, .........
1
vote
1answer
65 views

How to write a loop to run iterations of functions to obtain different values? [closed]

I am trying to iterate the function a, b and td2 (10 times) inside a For loop. This will gives me 10 different values of td2 which eventually gives me 10 different values of fullData2. In another ...
-1
votes
1answer
58 views
-1
votes
1answer
129 views

Periodic boundary conditions for two walkers

For some reason I'm getting infinite loops most of the time i run this. Perhaps the periodic boundary conditions are wrong. Seems like the probability of the two positions to be the same is extremely ...
-1
votes
1answer
54 views

Iterate a large matrix calculation [closed]

I want to repeat the calculation of a pretty big formula about 100 times. I tried using Do loop but it takes sooo much time that mathematica stops working. I will take a simple example to illustrate ...
5
votes
0answers
47 views

Counting automorphisms that preserve a group action

Note: the math, I believe, is not the problem here. The issue is not that I get the wrong answer, just that my code does not terminate. So, if you do not feel comfortable with the problem below, I do ...
1
vote
1answer
50 views

Solve a backward-forward equation with a loop

I want to solve this recursive equation X[t+1] = 0.8 X[t] + 0.04 P[t+1] + 119.6; P[t_] := 0.4 X[t] + 0.8 P[t + 1]; P[t_] := S[t] X[t] - g[t]; and with these ...
3
votes
2answers
86 views

Solving system of equations in Mathematica

I am unable to solve this system of equations in Mathematica. Where the third equation takes value (on the right hand side) from 0.00001 to ...
6
votes
4answers
596 views

Paying off an installment

How do I determine the weekly installment I have to pay, if my loan is, let's say, loan=5000, with interest rate of 2% every ...
2
votes
0answers
56 views

Why does this function recur forever? [closed]

I am trying to solve Project Euler Problem 31, but I don't want answers for that. I just want to know why this function recurs forever. It just keeps subtracting one forever, on the ones where it goes ...
3
votes
1answer
42 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
1answer
127 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
364 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
82 views

Parallelize in Mathematica [duplicate]

Here is two test to understand the parallelize in Mathematica: ...
-1
votes
3answers
86 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
80 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
68 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
139 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
132 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
414 views

How to calculate a list without loop?

I have pairs of numbers {a1, b1}, {a2, b2}, {a3, b3}, ..., ...
0
votes
2answers
118 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
34 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
106 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
40 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
69 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
86 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 ...
3
votes
3answers
148 views

How to check keys and values in nested Associations?

Considering we have a an association: ...
0
votes
1answer
57 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
65 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
176 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 NSolve...
1
vote
1answer
155 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 x[...
0
votes
0answers
126 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
103 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
91 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
102 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
181 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
140 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
254 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 ...
2
votes
2answers
230 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
201 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 iteration....
1
vote
2answers
407 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
150 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
280 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
231 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
114 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
458 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
118 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
521 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 ...