34 votes
Accepted

Has this implementation of FDM touched the speed limit of Mathematica?

Okay, this is a bit of an embarassment. Here is a very small modification of the original code. I simply made explicit option settings, made a denominator to Sin ...
user avatar
20 votes

Archimedes' Scheme to find $\pi$

This is a "visual proof" of the Archimedean limiting regular polygons. You could implement the recursion and it would progressively approach $\pi$. The proof lies in the "squeezing" argument. $\pi$ ...
user avatar
  • 55.1k
18 votes

Finite difference method not converging to correct steady state or conserving area?

Since a fully NDSolve-based solution is acceptable for you, let me give you one. You simply need the magic of "Pseudospectral" or a dense enough 4th order spatial ...
user avatar
  • 52.5k
15 votes

Paying off an installment

Using Annuity: pmt /.Solve[TimeValue[Annuity[pmt, 52, 1], .02, 0] == 5000, pmt] 155.545 ...
user avatar
  • 10.6k
13 votes

RecurrenceTable iteration variable not localized? Bug or user error?

As Bob Hanlon's answer points out, RecurrenceTable does not hold its arguments, but most especially, it does not hold its iterator arguments. This must surely be ...
user avatar
  • 67k
13 votes
Accepted

How do I recursively calculate this equation and generate a list of iteration?

You were correct. NestList is exactly the function you want to use. ...
user avatar
  • 4,604
12 votes
Accepted

Poisson PDE over a irregular region with FDM

As mentioned in the comment above, handling irregular region with FDM is cumbersome and frustrating in my view, actually that's where I stopped my self-learning of FDM and turned to finite element ...
user avatar
  • 52.5k
12 votes
Accepted

Finite difference method not converging to correct steady state or conserving area?

Introduction A lack of time to write up an answer ironically provided time to reflect on the problem, and some nagging uncertainties about some issues contributed to the delay. The slowness of the ...
user avatar
  • 216k
11 votes
Accepted

Archimedes' Scheme to find $\pi$

You should use RecurrenceTable: ...
user avatar
  • 6,134
11 votes

Solving Recurrence Equation $a_{n+1}=a_n(1-a_n)$

Your recurrence is an instance of the logistic map $$x_{n+1} = r x_n(1 - x_n).$$ The first sentence of the Solution in some cases section in the link above says: The special case of r = 4 can in ...
user avatar
11 votes

RecurrenceTable iteration variable not localized? Bug or user error?

Unlike many other functions that use an iterator, RecurrenceTable does not have the attribute HoldAll. Presumably, this ...
user avatar
  • 120k
11 votes
Accepted

Finding Hofstadter's Q-Sequence very slow

Proper memoization is the key: Q[1] = 1; Q[2] = 1; Q[n_] := Q[n] = Q[n - Q[n - 1]] + Q[n - Q[n - 2]] data = Table[Q[n]/n, {n, 10000}]; // AbsoluteTiming {0....
user avatar
  • 23.2k
11 votes
Accepted

Plotting an image of a discrete dynamical system

Use the sliders to modify matrix entries. Click and drag locators (small disks) to modify initial points; ALT+Click to add/remove locators. ...
user avatar
  • 349k
10 votes
Accepted

Limit n->Infinity of recursive sequence

Alternatively, and perhaps more directly, use ...
user avatar
  • 58.4k
10 votes

Archimedes' Scheme to find $\pi$

You can use Mathematica to prove the induction step in a proof that $a_n, b_n \rightarrow L$ for some limit $L$ by showing that $a_n$ is decreasing and $b_n$ increasing toward each other and that the ...
user avatar
  • 216k
10 votes

How do I recursively calculate this equation and generate a list of iteration?

Your can use MatrixPower for this example: f[n_] := MatrixPower[{{.5, -.6}, {.75, 1.1}}, n].{2, 0} f /@ Range[0, 5] yields: <...
user avatar
  • 55.1k
10 votes

Find a stable 3-cycle of the sine map

This is how you define the function $g$ in Mathematica: g[a_, x_] = a*Sin[π*x]; Making a color-plot of the function $g(g(g(x)))-x$ in the $a$-$x$ plane and ...
user avatar
  • 36.2k
10 votes
Accepted

How to plot a system of recurrence equations

Straightforward method: ...
user avatar
10 votes

How to Generate a Phase Portrait for a Jacobian Evaluated at Fixed Points

First, we can plot phase portrait for 3D system as follows (see comment @I.M.) ...
user avatar
  • 34.1k
9 votes

How to replace the symbol n in DifferenceRoot

There is a hidden option to change the variables used by DifferenceRoot[]: ...
user avatar
9 votes
Accepted

Using dynamic programming to compute an integer sequence

This is a good chance to use #0:) If[#1 == 1, 1, # + 1 - #0[EulerPhi @ #]] & /@ Range[20] ...
user avatar
  • 349k
8 votes
Accepted

Evolution of a trait in an asexual population (performance tuning)

Here is a modified version of your code. On my PC it completes your example run in about 5 seconds. I won't try to describe every change but will point out the major features. Some of the changes are ...
user avatar
  • 83.4k
8 votes

Paying off an installment

The general formula can be derived as follows. ...
user avatar
  • 58.4k
8 votes
Accepted

Calculating the Feigenbaum Constants

Several changes are required to obtain the desired results. First, the syntax error mu[n] == mu must be replaced by mu[n] = mu. ...
user avatar
  • 58.4k
8 votes
Accepted

Using Total inside the RecurrenceTable

First, as I noted in the comment, a much simpler approach is to use NestList: NestList[f, 12, 3] {12, 9, 729, 1080} Let's ...
user avatar
  • 23.2k
8 votes

How to draw discrete dynamic systems in mathematica

Play with the following example: $$ \begin{eqnarray} x(n+1)&=&rx(n)(1-y(n))\\ y(n)&=&x(n), \end{eqnarray} $$ with $r=\displaystyle\frac{2005}{1000}$ and three orbits. The phase ...
user avatar
7 votes

Recursion question

Started as a comment to the OP. Turning this into an answer was requested. The OP asked for Mathematica help solving the recurrence. I suggested recognizing that the recurrence was the sum of ...
user avatar
  • 2,940
7 votes

Evolution of a trait in an asexual population (performance tuning)

When building a simulation like yours you should test the performance of the individual components before incorporating them into the simulation. That is, you should know the cost of the components as ...
user avatar
  • 106k
7 votes
Accepted

How can I find the coefficients of the next recursive symbolic function?

The recurrence relation can be represented by f[0] = f0; f[1] = f1; f[2] = f2; f[n_] := f[n] = Simplify[-m f[n - 1] + f[n - 3]] based on which, the coefficients ...
user avatar
  • 58.4k
7 votes
Accepted

Incorrect answer given by RSolve

This is a bug in RSolve. The problem appears to be caused by a missing check while applying a transformation to solve this example, which should have returned unevaluated with the available methods. ...
user avatar

Only top scored, non community-wiki answers of a minimum length are eligible