I have been teaching the course &quot;Mathematics&quot; for the PhD students at Ca' Foscari University for a few years. In the lectures I cover some &quot;scattered&quot; material that may prove useful, sooner or later, to develop quantitative models in Economics. One of the weeks of the course is devoted to non-linear dynamics, one-dimensional maps and chaos.<br>R can be extremely useful to explore the dynamics, compute fixed points or cycles and have a numerical look at the map. The mix of computational techniques and theoretical investigation is widely acknowledged to be fruitful. As <a target="_blank" href="https://books.google.it/books?id=JDQGAwAAQBAJ&printsec=frontcover&hl=it#v=onepage&q&f=false">Strogatz, &quot;Nonlinear Dynamics and Chaos: With Applications to Physics, Biology, Chemistry, and Engineering&quot;</a>, puts it:<br><blockquote>The study of maps is still in its infancy, but exciting progress has been made in the last twenty year, thanks to the growing availability of calculators, then computers, and now computer graphics. Maps are easy and fast to simulate on digital computers where time is <i>inherently</i> discrete. Such computer experiments have revealed a number of unexpected and beautiful patterns…</blockquote>Given a non-linear map \(f\) you may want to plot the time series of states \(x_{t+1}=f(x_t)\), depict the cobweb diagram and look at fixed points, to begin with. Let \(f\) be the immortal logistic map depending on the parameter \(r\).<br><br><pre><code>f &lt;- function(x,r) r*x*(1-x)<br>bounce &lt;- function(f,init=4,n=10,cobweb=T,timeseries=F,dom=NULL,...){<br>iterates &lt;- NULL<br>x0 &lt;- init<br>for(t in 1:n){<br>  x1&lt;- f(x0,...)<br>  iterates[t] &lt;- x1<br>  x0 &lt;- x1<br>  }<br><br>if(cobweb &amp; !timeseries){<br>    if(is.null(dom)){<br>    a &lt;- range(c(init,iterates))[1]-0.5<br>    b &lt;- range(c(init,iterates))[2]+0.5} else<br>    {a &lt;- dom[1];b &lt;- dom[2]}<br>    curve(f(x,...),a,b);grid(col=1);abline(0,1,lty=2)<br>    lines(c(init,iterates), f(c(init,iterates),...),t=&quot;s&quot;)<br>    points(c(init,iterates), f(c(init,iterates),...))<br>}<br><br>if(timeseries){<br>    plot(0:n,c(init,iterates),t=&quot;l&quot;)<br>}<br><br>}<br>bounce(f,0.1,r=3.7,n=100)<br></code></pre><br><span>bounce </span>computes \(n\) iterates of the map starting from init an plots a cobweb diagram. Defaults may or may not work for a specific map but the plotting domain can be provided if the educated guess doesn't work (here, say, <span>bounce(f,0.1,r=3.7,n=100,dom=c(0,1)</span> would be probably better).<br><table align="center" cellpadding="0" cellspacing="0"><tr><td><a href="https://2.bp.blogspot.com/-iaK8ANs7DaY/WEKOf7LjdnI/AAAAAAAAC1I/AbiP4cefWzYQAS7Znflz2FtAfipbbTWAgCLcB/s1600/logi.jpg"></a></td></tr><tr><td>bounce(f,0.1,r=3.7,n=100)</td></tr></table><div>The function <span>bounce</span> shows the 45-degrees line (dashed) and its intersections with the graph of the function: fixed points and their stability can be visually investigated (or found with <span><span>uniroot</span></span>). Indeed, the name comes from the repeated &quot;bounces&quot; on the line and on the graph. Setting <span>timeseries=T </span>displays the sequence of states of the dynamics (i.e., the time series) as shown below for \(r=3.8282\), a value that generates intermittency, see page 363 of Strogatz:</div><table align="center" cellpadding="0" cellspacing="0"><tr><td><a href="https://3.bp.blogspot.com/-X7vTDvLQ-M0/WEKWLDhFkSI/AAAAAAAAC1c/It7ENodkoxA8L-j2CPN0tsSI_a8XM7p0gCLcB/s1600/intermittency.jpg"></a></td></tr><tr><td>bounce(f,0.1,r=3.8282,n=100,timeseries=T)</td></tr></table>In a coming post, we'll use R to draw <a target="_blank" href="https://en.wikipedia.org/wiki/Logistic_map">bifurcation diagrams</a> and <a target="_blank" href="http://www.math.harvard.edu/archive/118r_spring_05/handouts/lyapunov.pdf">Lyapunov exponents</a>.<br><br>