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
2 votes
1 answer
125 views

How can I count iterations with NestWhile?

I'd like to count loop iterations for some substitution rules. For example: rule = {1 -> {0}, 0 -> {1}} init = {0} maxIter = 10 I'm going to avoid all ...
lesobrod's user avatar
  • 1,085
0 votes
0 answers
69 views

Do loop Implementation

I want to generalise the following algorithm to a loop overall possible subsets of the original set. the algorithm has the following form: ver={X41,X42,X43,X44} and ...
Faktor 2's user avatar
-1 votes
1 answer
98 views

Wolfram Alpha simplifying $\sqrt{1+x^\sqrt{1+x^\sqrt{1+...}}}$ incorrectly [closed]

I am pretty new to Wolfram Alpha. I want Wolfram Alpha to find the derivative of $\sqrt{1+x^\sqrt{1+x^\sqrt{1+...}}}$. At the moment, I am having trouble with Wolfram Alpha simplifying it incorrectly. ...
Dylan Levine's user avatar
0 votes
3 answers
96 views

How do I create a Table from a For loop?

I've been trying to create a table that has the % of the cycle of a sample and the module of acceleration for the first 100 values, but I don't know how to create it. Here's the code: I have imported ...
Pamsh's user avatar
  • 1
0 votes
0 answers
64 views

Nested loop for two variables

I have a quantity as below, P[k_0,A_]= A Log [k0]. I want to generate data for this for A={0,10^3} and k0=10^{-11} to 10^{-2} using a Do loop but I don't know how to apply a loop on two variables ...
adeela afzal's user avatar
0 votes
1 answer
101 views

How to work on "Do" loop?

let's say ...
user8357568's user avatar
2 votes
1 answer
69 views

Print out how many times to calculate the sum of the squares of its digits until answer is 1 or 4

I am trying to write a recursive function, toscare1[], that takes as parameter a positive natural number. Then calculate the sum of the squares of its digits, thus creating a new number; then, we ...
SkySystem's user avatar
2 votes
0 answers
112 views

The fastest and most scalable way to write a nested loop

The problem is to find the weights {w1,w2,w3,w4} that satisfy the condition. Which is the fastest and most scalable way (e.g. for 10000 weights) to write this ...
John Matis's user avatar
1 vote
2 answers
124 views

Trying to apply numerical method with Do

I am trying the following scheme to learn to implement an iteration using Do loop. I tried to implement the same method using for loop but with same errors. I, therefore, turned to the Do loop to ...
Skj's user avatar
  • 19
1 vote
0 answers
37 views

ParametricNDSolve computation time is sensitive to the range of independent variable

My code to solve a system of nonlinear differential equations are the following: ...
user280016's user avatar
-1 votes
1 answer
74 views

Right writing of While loop

Help me pls write While loop correctly. I have next code: ...
Mam Mam's user avatar
  • 1,731
3 votes
1 answer
143 views

FixedPoint not working, despite quick convergence of sequence [closed]

Trying the computation below, with Mathematica 13.0.0, I am not getting a result returned. FixedPoint[Cos, 0.85] This appears in the 3rd edition of "...
S.V's user avatar
  • 315
0 votes
2 answers
285 views

While Loop inside a Do loop and the usage of a break

I am struggling with using a While loop inside a Do loop and using the break to break the loop. In this code, I would like to use the While loop for the value of i and the Do loop for the value of h, ...
Iras's user avatar
  • 25
0 votes
1 answer
102 views

Using Tuples for creating the sample space [closed]

I want to use Tuples (if you know better way please let me know) to create the sample space for some events. Assume that I have 2 events each of which can change to ...
Parviz's user avatar
  • 383
1 vote
1 answer
45 views

Reduce relations with Fibonacci function never terminates,

i have a reduce operation which includes Fibonacci function. but the problem is it never terminates, i tried some modifications, for example removing f1 in my relation. sometimes it works and at least ...
Azzurro94's user avatar
  • 499
0 votes
1 answer
178 views

Contour plot with x, y and z values?

I have x , y and z as x = List[1.355, 1.357, 1.359, 1.36, 1.357, 1.355]; and ...
a019's user avatar
  • 811
2 votes
1 answer
79 views

NdSolveValue Freeze sensitive to initial condition

I am trying to solve the following system of non-linear differential equations: ...
Andrei's user avatar
  • 21
1 vote
0 answers
64 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 ...
Hauke Reddmann's user avatar
1 vote
1 answer
75 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 ...
Miguel Zarate's user avatar
1 vote
0 answers
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 ...
Miguel Zarate's user avatar
0 votes
0 answers
77 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 ...
Miguel Zarate's user avatar
2 votes
1 answer
46 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 ...
Dhruv Sharma's user avatar
1 vote
1 answer
244 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 ...
Staples's user avatar
  • 21
4 votes
1 answer
292 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 ...
AccidentalTaylorExpansion's user avatar
1 vote
0 answers
56 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 ...
user75105's user avatar
2 votes
3 answers
229 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 ...
Illari's user avatar
  • 399
-1 votes
1 answer
167 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): ...
John's user avatar
  • 421
0 votes
1 answer
80 views

Problem with Do Loop and TableForm

The following code is supposed to generate 10 tables based on different calculations for different q: ...
John's user avatar
  • 421
0 votes
0 answers
112 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.
Alperen koç's user avatar
-2 votes
1 answer
118 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 ...
Naljor's user avatar
  • 1
0 votes
1 answer
71 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: ...
subrinarafiq's user avatar
-5 votes
1 answer
65 views

Why does my code not work? [closed]

Why does the following code not work? ...
yu chen's user avatar
  • 11
0 votes
1 answer
72 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 ...
Hossain Sultani's user avatar
0 votes
0 answers
38 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: ...
Timothy Aaronn Norris's user avatar
1 vote
2 answers
70 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 ...
Klangen's user avatar
  • 967
1 vote
0 answers
178 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 ...
user66418's user avatar
  • 103
1 vote
1 answer
1k 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++)
a019's user avatar
  • 811
0 votes
1 answer
153 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 ...
Alonso Perez Lona's user avatar
1 vote
1 answer
166 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 ...
H. Kenan's user avatar
  • 663
1 vote
1 answer
77 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 ...
someoneouthere's user avatar
0 votes
1 answer
74 views

How to make a table for loops?

I have a code given by ...
Mehrab's user avatar
  • 171
1 vote
2 answers
200 views

Avoiding a for loop to create a list

I am trying to evaluate: ...
TheInvoker's user avatar
3 votes
1 answer
66 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$ ...
BigM's user avatar
  • 257
4 votes
3 answers
627 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 ...
ithilquessirr's user avatar
0 votes
1 answer
141 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 ...
aluuzz's user avatar
  • 57
3 votes
3 answers
307 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 ...
D. D.'s user avatar
  • 33
0 votes
0 answers
104 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 ...
Guaro's user avatar
  • 25
1 vote
1 answer
184 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, ...
Herr Schrödinger's user avatar
5 votes
4 answers
449 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 ...
harazogo's user avatar
2 votes
1 answer
116 views

NestWhile and infinite loop

Obviously, the following code leads to an infinite loop: ...
stone-zeng's user avatar