15
votes
Paying off an installment
Using Annuity:
pmt /.Solve[TimeValue[Annuity[pmt, 52, 1], .02, 0] == 5000, pmt]
155.545
...
13
votes
Accepted
How to calculate a list without loop?
Accumulate@Array[b, {3}]
(* {b[1], b[1] + b[2], b[1] + b[2] + b[3]} *)
therefore:
...
11
votes
Accepted
A while loop that terminates after a number of seconds elapsed?
You could do something like this:
tstart = SessionTime[];
While[(t = SessionTime[] - tstart) < 60, (* do stuff *)]
10
votes
10
votes
Accepted
FixedPoint not working, despite quick convergence of sequence
$Version
(* "13.0.1 for Mac OS X x86 (64-bit) (January 28, 2022)" *)
The Possible Issues section of the ...
8
votes
8
votes
Accepted
Recursion depth exceeded in pattern matching with attribute Flat
I find Flat hard to work with. Despite seeing it in use numerous times I'm never quite sure what it will do until I try it, so maybe I'm not the person to answer ...
8
votes
Accepted
Why is this an infinite loop?
The loop is infinite, because the result of Append is the new list, not the modification of existing.
Documentation:
...
7
votes
How do I limit the iterations in a while loop?
As an alternative to a manual check of the iterator, as proposed by Kuba, you could refactor to use NestWhile by converting your body and test to functions without ...
7
votes
Accepted
ReplaceRepeated as a Looping construct?
Using the shortcut //. together with a MaxIterations options
...
7
votes
Accepted
solve equation with loop
First off, don't use capital letters, you'll run into trouble like you did there (E is defined as the natural log unit $e$). You can do what you are going for with ...
7
votes
7
votes
avoiding writing loops
Total[DistanceMatrix[a]]
...too short to be an acceptable answer (minimum is 30 characters) without some meaningless commentary
7
votes
6
votes
Accepted
While loop repeats itself using initialization cell
Mathematica won't run it twice unless you (possibly unknowingly) instruct it to do so.
I suspect this is what is happening (please update the question with the details):
You put some initialization ...
6
votes
For-loop doesn't work
First of all there is nothing like double in Mathematica, you don't need to define the type of variable here.
I don't know what problem are you trying to solve, ...
6
votes
Accepted
Infinite While loop
The crux of the matter is how n is changed on each iteration.
Math
Consider a multi-digit integer $n = a_1 a_2 a_3 \ldots a_N$, where $a_k$ is the $k$-th digit of ...
6
votes
Accepted
Generating trigonometric sums
n = 10;
basis = Table[Cos[k t], {k, 0, n}];
Tuples[{-1, 1}, n + 1].basis
5
votes
Looping things in Mathematica
As alluded to by Daniel Lichtblau you could use TriangleWave with appropriate scaling, e.g.
...
5
votes
Accepted
5
votes
5
votes
Accepted
How to check keys and values in nested Associations?
This solution will traverse all nested associations regardless of depth and replace each value with the value that corresponds to its key in replacements.
...
5
votes
Accepted
Check every list element for appearance
All you need is to do Map MemberQ over the second column (a.k.a. [[2]]) of each lines:
<...
5
votes
Accepted
5
votes
Accepted
5
votes
Paying off an installment
Using the example for an ordinary annuity from here:-
Calculating The Present And Future Value Of Annuities
The example demonstrates how a present value principal of 4329.48 is paid down by five ...
5
votes
A while loop that terminates after a number of seconds elapsed?
An example using TimeConstrained:
...
4
votes
Minimize loop optimization
I'm not sure exactly what you want, but in an effort to demonstrate some possibilities:
...
4
votes
Solving a trigonometric equation with one parameter
Setting b = 1 from the start, your equation can be rewritten as
(3 k)/(3 + a k^2) == Tan[k]
This has multiple solutions for <...
4
votes
Problem with recursion depth
You define L1 in terms of L1, which leads to a recursion. A much simplified but completely analogous example is
...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
infinite-loop × 121list-manipulation × 15
procedural-programming × 12
equation-solving × 9
functions × 9
matrix × 8
table × 8
recursion × 8
programming × 6
plotting × 5
differential-equations × 5
random × 5
conditional × 5
evaluation × 4
replacement × 4
vector × 4
iterators × 4
mathematical-optimization × 3
export × 3
dynamic × 3
calculus-and-analysis × 2
numerics × 2
probability-or-statistics × 2
complex × 2
syntax × 2