Message Boards Message Boards

0
|
3237 Views
|
1 Reply
|
0 Total Likes
View groups...
Share
Share this post:

Showing dynamics in phase diagram - difference equations

Posted 10 years ago

Hi guys, I have a problem in showing dynamics of the solution of difference equation of first order. I would like to show, if the solution is converging or diverging based on parameters.

I have some results, however the dynamics is not showing correctly. I enclose the figure - red solid line shows how it should look like. The grey upside downs show the wrong solution from the code.

Anyone knows how to fix it?

Thanks a lot!

Jan

Here I provide you with code

d3[a_, b_, y_] := a*y + b;
s[y_] := y;

Manipulate[
 Module[{result},
  result = 
   Quiet[Re[
     Table[Evaluate[
       p[k] /. First[
         RSolve[{p[k + 1] == -d/b (p[k]) + (a - c)/b, p[1] == n}, 
          p[k], k]]], {k, 1, nn}]]]; 
  GraphicsGrid[{{Plot[{a - b p, c + d p}, {p, 0, 20} , 
      PlotRange -> {0, 30}, 
      PlotStyle -> Directive[{Thickness[.01], Gray}], 
      AxesLabel -> {Style["p", Italic], Style["q", Italic]}, 
      PlotLabel -> "Demand and Supply", AxesOrigin -> {0, 0}, 
      Ticks -> None, 
      Epilog -> {{Gray, Thin, 
         Line[Riffle[
           Partition[Riffle[result, s[c, d, #] & /@ result], 2], 
           Rest[Partition[Riffle[result, d3[a, b, #] & /@ result], 
             2]]]]}, {Red, 
         Point[#] & /@ 
          Partition[Riffle[result, s[c, d, #] & /@ result], 2]}, {Red,
          Point[#] & /@ 
          Rest[Partition[Riffle[result, d3[a, b, #] & /@ result], 
            2]]}}],
     ListLinePlot[result, PlotLabel -> "Price Movement", 
      PlotStyle -> Red, Ticks -> None, 
      AxesLabel -> {"iteration", Style["p", Italic]}]}}, 
   ImageSize -> 550]],
 {{b, 1, "slope of D"}, .5, 1.2, .1},
 {{d, .7, "slope of S"}, .5, 1.2, .1},
 {{a, 12, "initial D"}, 5, 27},
 {{c, 1, "initial S"}, .1, 10},
 {{n, 14, "starting price, \!\(\*SubscriptBox[\(P\), \(0\)]\)"}, .5, 
  19},
 {{nn, 50, "number of iterations"}, 1, 100, 1}, 
 SaveDefinitions -> True]
Attachments:
POSTED BY: Jan Žá?ek

Code formatting instructions are in http://community.wolfram.com/groups/-/m/t/270507 .

POSTED BY: Bruce Miller
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract