Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Something is wrong with my cobweb plot code but I couldn't figure out where do the mistakes come from.

So basically we have the iterative map $x_n == x_{n-1}^{2} - 3 \mu$. I would like to draw a cobweb diagram that shows in the range $-\frac{1}{12}<\mu<\frac{1}{4}$ there exists a fixed point $\frac{1}{2}(1-\sqrt{1+12\mu})$.

Below are the code and the diagram:

enter image description here

enter image description here

enter image description here

My questions are:
1. Why the diagonal line in the cobweb is not appearing and why is it replaced by a horizontal blue line?
2. The label on top is wrong and I couldn't fix it.
3. How can I fix the cobweb code so that I can show, say let $-\frac{1}{12}<\mu=0.2<\frac{1}{4}$ and initial value 2, there is a convergence towards a fixed point $\frac{1}{2}(1-\sqrt{1+12\mu})$.

Many thanks. I really appreciate any helps.

share|improve this question

closed as too localized by whuber, Oleksandr R., Ajasja, Artes, R. M. May 19 '13 at 16:33

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

"Why the diagonal line in the cobweb is not appearing and why is it replaced by a horizontal blue line?" - if you'll look at the scale of your axes, you should see why the line $y=x$ ought to look flat... – J. M. May 19 '13 at 12:46
@J.M. Then how can I change the scale to make it look correct? I have some troubles changing the options, it will make the plot even worse. – user71346 May 19 '13 at 12:51
I'd say you have an even more fundamental problem: your iteration is diverging quite wildly, as your starting point is rather far away from the domain of convergence of your iteration. Try a smaller starting value. – J. M. May 19 '13 at 13:05
@J.M. I chose x0 = 2 because it is close to the fixed point which is approx 1.4. I tried x0 ranging from -2 to 2 but no big changes. – user71346 May 19 '13 at 13:38
When $\mu=0.2$, I calculate the fixed point $\frac{1}{2}(1-\sqrt{1+12\mu})$ to be around $-0.422$ rather than 1.4. The latter is a different fixed point. And as already said, you need to start close to the fixed point. – murray May 19 '13 at 14:40

As Murray noted, you must have made an error calculating the attraction point:

1/2 (1 - Sqrt[1 + 12  μ]) /.  μ -> 0.2


Trying a point close to this with your code (Please, please, never provide code again as a bitmap. Typing this is no fun.)

cobweb::usage = 
  "cobweb[f,x0,nmax,ndrop] produces a cobweb plot for the recursive
  function f[x] with initial value x0, suppressing the first ndrop
  iterates. Options may also be passed to Plot. ";
cobweb[f_, x0_, range_, nmax_, ndrop_: 0, opts___Rule] :=
 Module[{plot1, plot2, p1ot3},
  plot1 = 
    Plot[{x, f[x]}, {x, range[[1]], range[[2]]}, opts, Frame -> True, 
       FrameLabel -> {"\!\(\*SubscriptBox[\(x\), \(i\)]\)", 
      "\!\(\*SubscriptBox[\(x\), \(i + 1\)]\)"}, 
       PlotLabel -> StringJoin["Cobweb Plot for: ", ToString[f[x], TraditionalForm]]]; 
  plot2 = Graphics[
            Map[Line[{{#, #}, {#, f[#]}, {f[#], f[#]}}] &, 
            Drop[NestList[f, x0, nmax], ndrop]]];
  p1ot3 = ListPlot[{{x0, x0}}, PlotStyle -> PointSize[0.03]];
  If[ndrop == 0, Return[Show[{plot1, plot2, p1ot3}]], 
   Return[Show[{plot1, plot2}]]]]

mapCobweb[μ_, x0_, range_, nmax_, ndrop_: 0, opts___Rule] := 
 cobweb[#^2 - 3 μ &, x0, range, nmax, ndrop, opts]

mapCobweb[0.2, -0.6, {-1, 1}, 40, 0, ImageSize -> 800]

enter image description here

share|improve this answer
OP might want to contemplate why the attractive fixed point is the one much nearer to the vertex of the parabola... – J. M. May 19 '13 at 15:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.