# 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.

116 questions
Filter by
Sorted by
Tagged with
51 views

### Avoiding infinite rule recursion

Assume I want to apply rule $R_1$ from a rule set $S$ to an expression $E$ just if it is "half safe", i.e., if the next application of $S$ to $R_1(E)$ does not yield $E$ again. (This ...
44 views

### How to get a loop for a differential equation system?

I would like to know how can I obtained a loop of this system ...
35 views

### How to write a complex no linear term in loop of a differential equation system?

I have this system of equations $$i \frac{d \psi_{m}}{dt} = k \psi_{m-1} + k \psi_{m+1} + \gamma \vert \psi_{m} \vert^{2} \psi_{m}$$ and this is my code ...
34 views

### How to do a time dependent loop for different initial conditions

I would like to do a loop for this problem, this is my code ...
24 views

### Lock focus on cell / Identify reason for loss of focus

The code at the end of this post is a snake game. It's a Dynamic Graphics wrapped in an ...
31 views

### Skip time taking loop values to take input next value after certain time

I am fitting using NonlinearModelFit, where I am trying to input guess values for parameters (g and xp1) from the for a loop. For a certain value of g or xp1, the loop takes infinitely long to compute ...
136 views

### Mathematica crashes with a simple For-loop

I am new to Mathematica, so I am sorry if this is a bit of a stupid question but I really am stumped. I am trying to define a function in Mathematica that does a very specific thing, but for some ...
107 views

### Best way to make live animations

I often find myself in a situation where I want to see something animated 'live'. With this I mean I have some data, a function to update that data let's call it ...
37 views

### Maximize recursive function (exact or numerical)

I am essentially just using Mathematica as an advanced calculator, but I know it is much more powerful. I am sure it can solve my problem. Any input is appreciated, including the tutorial or handbook ...
30 views

### Evaluate For Loop for a fixed number of iterations

a = Table[Prime[n], {n, PrimePi[i]}]; b = Delete[a, 1]; p = IntegerPartitions[i, 4, b]; Total[ Times @@ Values[1/Factorial@#] & /@ Counts /@ p]; I need to ...
188 views

### Re-writing code chunk using While loop

I can't seem to wrap my head around the syntax for how to rewrite this chunk of code I have using a while loop, and would appreciate some help. I'm going through a list and am grouping the values into ...
104 views

### Problem using TableForm and Do loops

The following code is supposed generates a table based on different calculations for a given q (e.g. q[1] for this example): ...
54 views

### Problem with Do Loop and TableForm

The following code is supposed to generate 10 tables based on different calculations for different q: ...
67 views

### Plot an infinite sum

I want to plot the following equation (w-$\delta$ graph) Ty Tx and ly are constant and I will assign a value for them. I am a new one on the Mathematica and can not handle this.
100 views

### turn infinite loop into finite loop

I am trying to make a table where I can save the stock value with the iterative part, where I should have 100 sequence with 843 entry in each sequence. The loop doesn't run correctly in the sense ...
65 views

### Problem with iterations of Prepend/While

I am doing some work with black-scholes and am trying to find random interest rates based on some given information. This is my original code: ...
52 views

### Why does my code not work? [closed]

Why does the following code not work? ...
61 views

### For-loop not indexing correctly [closed]

I have a question. Why does my result start with J = 2? I write another loop but it start 1 i confused-i need help ...
37 views

### Mathematica Function Taxicab Numbers [duplicate]

I have spent days trying to compile this code and I cannot generate a list of taxicab numbers for the Hardy-Ramanujan Theory. Here is the module I wrote earlier: ...
56 views

### How do I modify my code to detect cycles in this Collatz-like recursion?

A popular variant of the Collatz recursion is the following. Given a positive integer $n_i$, If $n_i$ is even, $n_{i+1}=n/2$, If $n_i$ is odd, $n_{n+1}=3n-1$. The Mathematica code I'm using to ...
81 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 ...
549 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++)
69 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 ...
114 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 ...
69 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 ...
64 views

### How to make a table for loops?

I have a code given by ...
171 views

### Avoiding a for loop to create a list

I am trying to evaluate: ...
63 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$ ...
456 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 ...
135 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 ...
217 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 ...
93 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 ...
116 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, ...
417 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 ...
65 views

### NestWhile and infinite loop

Obviously, the following code leads to an infinite loop: ...
256 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 ...
62 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 ...
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: ...
413 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 ...
123 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 ...
147 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. ...
94 views

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

I have the following Mathematica Code. ...
38 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 ...
126 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 ...
936 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 ...
383 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 "...
390 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. ...
184 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 ...