Questions tagged [infinite-loop]

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.

Filter by
Sorted by
Tagged with
0
votes
0answers
34 views

Run a loop without merging the cells

I have to run a loop of a certain variable than spans through the entire notebook. However the notebook has already been divided into different sections; merging these sections will be a pain and ...
1
vote
1answer
59 views

For loop for two variable at the same time

Can I use for loop for two variables as example show below at the same time? for (int x = 0, y = 0; x < 10 && y < 10; x++, y++)
0
votes
1answer
50 views

Return last value of While function

I want to make a function that performs a multiplication with Inner i number of times using a ...
1
vote
1answer
77 views

An optimization problem over two variables

I have the function fun[x_,y_, t_] = Cos[x] + Exp[I y] Sin[x] Sin[t]; such that $0\le {\rm x}\le \pi$, $0\le {\rm y}\le 2\pi$, and $0\le {\rm t} \le 10$. I compute ...
1
vote
1answer
63 views

Looping a function that requires previous calculations in order to continue

I am trying to solve a system of overdetermined linear equations for 2 unknowns with 3 variables. For a given equation of a line, we can write it as: ax + by = c, which expressed in vector form is ...
0
votes
1answer
55 views

How to make a table for loops?

I have a code given by ...
1
vote
2answers
119 views

Avoiding a for loop to create a list

I am trying to evaluate: ...
3
votes
1answer
61 views

Generating trigonometric sums

How can one generate all cosine polynomials with $\pm1$ coefficient of following form: $$\sum_{k=1}^n\pm\cos kt.$$ I tried DO loop but couldn't get all of them as clearly cannot exhaust $2^n$ ...
3
votes
3answers
291 views

Sum of Random Integers

I am trying to get a list of numbers with at least 1000 sums as possible, using random numbers from 1 to 10. But I don't want to get blank list output. How can I only get a list of numbers greater ...
0
votes
1answer
89 views

Combined ParametricNDSolveValue with Do loop?

two weeks ago, I post a question see, and I got its answer, however, I would like to vary the values: g from (0.02 to 0.07), R from (0.1 to 0.3),and k2 from (0.03 to 0.07) by an increment of 0.01 ...
3
votes
3answers
142 views

Infinite While loop

I have an exercise where I need to input a multi-digit number and evaluate the square of the sum of its digits. I am new to Mathematica and I can't figure out why I'm getting an infinite loop. This is ...
0
votes
0answers
89 views

Dynamic loop unexpectedly stops in CDF Player Pro V11.3

Correction The issue described below it is not caused by CDF Player Pro after all. Apologies for the confusion. The Dynamic loop just unexpectedly stops anyways (it just takes longer when run in ...
1
vote
1answer
80 views

Build a list from a Loop!

I need to build a list with the values of the parameter $\gamma = \mu/a$ and the standard deviation of the following process, ...
5
votes
4answers
321 views

How to populate a table with results from a while function

Does anybody know how to save the intermediate results inside a while function in a table? Here is my code. I would like to save the x,y,counter values in a table in every step that while takes. Thank ...
2
votes
1answer
39 views

NestWhile and infinite loop

Obviously, the following code leads to an infinite loop: ...
1
vote
1answer
161 views

Why is this an infinite loop? [closed]

The following minimal non working example is an infinite loop: why is it so? list={1}; n=2; While[Last@list<10,Append[list,n];n++] It seems that ...
1
vote
1answer
43 views

Looping and find the minimum of a function and get data in excel sheet

I have written a code. I want to change y from (*10^-4 to 10^-6) and want to find the corresponding minimum and then need to export the value of y and corresponding minimum in an excel sheet. I know ...
2
votes
1answer
22 views

Use of timing system to change input variable in a function

Assume you have some function which is defined by a while loop: sampleFunc[start_] := Module[{i}, While[i = 1; start < 10, i++];] And let's assume I do: ...
2
votes
2answers
238 views

Using a loop to make a vector of functions

I am trying to use a do loop to make a vector of an arbitrary number of functions that can be evaluated later. I think the problem I am having is because of the AppendTo function in my code, because ...
3
votes
1answer
66 views

Setting some Rows and Entries in a Matrix to 0

How can I set certain entries in a matrix to be 0? Given an $m\times n$ matrix with specified values: mat = Table[1/i, {i, n}, {j, m}] I want to make some ...
1
vote
1answer
99 views

For loop Delay Differential Equation [closed]

I need to Solve a delay differential equation with one free parameter, then plot the values of the solution. I am not able to write the code for this. ...
1
vote
1answer
66 views

How to run this statement multiple times and put them in a matrix?

I have the following Mathematica Code. ...
0
votes
1answer
37 views

Loops and guesses

I have to solve a system of equations in the following way: I first guess a value for a variable, let's call it y, calculate another variable ...
3
votes
2answers
96 views

How to do calculations in a loop from list of data?

I wrote the code below to do the calculation for each variables. I would like to know how to do this in one loop and to print out timing each time a cycle of calculations is completed. Another ...
5
votes
2answers
865 views

A while loop that terminates after a number of seconds elapsed?

I would like to write something along the lines of: While[(t=Timer[])<60 (*in seconds*), ...do stuff... ] Unfortunately, I'm not aware of a timer object in ...
2
votes
1answer
131 views

Abort when key is pressed

Is it possible to abort a while loop when a key is pressed? Lets say I have this code t=0; While[t<10!,Print[t];t++] Is there a way to stop this loop when I press space? Is there a command like "...
-2
votes
1answer
166 views

For-loop doesn't work [closed]

I need some help. I try to run the code below, but at the end I1 = 0, I2 = 0 (the same as their initial values). I'm not sure which part of my code is wrong. ...
3
votes
6answers
164 views

avoiding writing loops

I have a list a={1,2,3,4,5} I want to calculate absolute differences of each element with all other elements ...
8
votes
2answers
135 views

Recursion depth exceeded in pattern matching with attribute Flat

I am defining a linear associative multiplication operation Mult[]: ...
0
votes
1answer
96 views

Taking derivative using some variable

I have a function with four variable, let's suppose it as f(t,x,y,z). I want to define a For loop in which in each iteration, differentiation operator acts on the f(t,x,y,z) with respect each ...
1
vote
0answers
114 views

loops in one loop, [closed]

I'm new Mathematica user. I try for loop but it didnt work. I used ...
-4
votes
2answers
109 views

Having trouble looping through arrays

Apologies if this question is written in the incorrect format this is my first time posting here. I am trying to generate a list of vectors whose x, y and z components can be made by selecting an ...
-1
votes
1answer
100 views

Repeating Calculations/Iterations without a specific function

I am trying to repeat an initial condition many times such that I get a desired final output. ONE final output depends on many subsequent calculations from ONE initial condition. But I want to get a ...
0
votes
1answer
217 views

Help With Do While Loops

I understand this question has been asked before but for some reason I can't get it to work also I'm new to stackexchage so I apologize if everything I write is not up to standards. That being ...
0
votes
0answers
39 views

Do loop carrying out recursion not looping - must be a simple mistake!

I have what I think is a basic do loop, but it is not executing as planned. Starting with some setup: ...
0
votes
1answer
600 views

Exporting data file in For loop

I prepared a code in which some numerical data can be produced. I want to export the data in terms of counter of loop but I don't know how I can do it. It my please if someone who knows, helps me. ...
0
votes
1answer
180 views

Do Loop with Solve not working

I am trying to solve bellowing loop but I faced with following error! ...
0
votes
2answers
100 views

Comparing two matrices in an If block

I want to find out for what value of n MatrixPower[u, n] == IdentityMatrix[3] ...
1
vote
0answers
74 views

Avoiding loops with breakpoints of a Piecewise function

I'm new to mathematica and I'm trying to avoid loops. The setting is the following: I have consumers with preferences (their Betas). Depending on the Beta consumers will have different preferences. ...
1
vote
0answers
70 views

Why is this while loop not giving me any output? [closed]

I have following code in my Mathematica: ...
1
vote
0answers
52 views

Repeatedly applying a function

I have writing a code in order to get pixel values of a image along a line. I want to repeatedly to apply the function to the image to get pixel values along multiple lines. My question is how can ...
0
votes
1answer
73 views

why the result not contain imaginary, I? [closed]

Good day, First of all, sorry if my coding in this forum has mistake. I already learned it and this is the best try from me. May anyone help me troubleshoot my problem below. ...
-4
votes
1answer
68 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
103 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
94 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
77 views
-1
votes
1answer
164 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 ...
0
votes
1answer
74 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 ...
6
votes
0answers
121 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
217 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 ...