声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 11104|回复: 39

[稳定性与分岔] 分岔的基本概念及matlab程序实现

  [复制链接]
发表于 2008-4-4 09:26 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
如题,最基本的分岔概念如:saddle-node;transcritical;supercritical pitchfork;subcritical pitchfork等,如果你不是很了解,可以学习一下下面的程序。



  1. %% Animation for a Saddle Node bifurcation
  2. % Range of x
  3.      xmin = -4;
  4.      xmax = 4;
  5.      x = xmin:0.1:xmax
  6. % Some auxiliary variable to plot x-axis
  7.      ax = (0.0).*x;
  8. % Range of r
  9.      rmin = -4
  10.      rmax = 4
  11. % number of frames in the movie
  12.      imax = 21
  13. % Rage of dx/dt (here y=dx/dt)
  14.      ymin = rmin ;
  15.      ymax = rmax + xmax.^2;
  16. % Some auxiliary variables to plot the y-axis
  17.      ky = ymin:0.1:ymax
  18.      ay = (0.0).*ky
  19. %% Start of the loop for acquisition of the movie frames
  20. for i = 1:imax
  21. %calculate r value
  22.      r = rmin + (i-1)*(rmax-rmin)/(imax-1)
  23. %create string for labelling r
  24.      strr = num2str(r);
  25.      strt = ['r=' strr];
  26. %calculate dxdt
  27.      y = r + x.^2
  28. %plot x-axis
  29.      plot(x,ax,'--');
  30. % determine range of plot
  31.      axis([xmin xmax ymin ymax])
  32.      hold on
  33. %plot y-axis
  34.      plot(ay,ky,'--')
  35. %plot f(x)
  36.      plot(x,y,'r');
  37. %plot fixed points
  38. if (r < 0)
  39.      plot(-(-r).^(0.5),0,'o','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  40.      plot((-r).^(0.5),0,'o','MarkerSize',10,'MarkerEdgeColor','k');
  41. end
  42. if(r == 0.0)
  43.      plot((-r).^(0.5),0,'*','MarkerSize',10,'MarkerEdgeColor','k');
  44. end
  45. %plot flow direction
  46. if(r < 0)
  47.      plot(-3,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  48.      plot(0,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  49. plot(3,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  50. end
  51. if(r == 0)
  52.      plot(-3,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');     
  53. plot(3,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  54. end
  55. if(r > 0)
  56.      plot(-3,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');     plot(0,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  57. plot(3,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  58. end
  59. %plot labels
  60.      xlabel('x','FontSize',20)
  61.      ylabel('dx/dt','FontSize',20)
  62.      text(-3,15,'dx/dt = r + x^2','Color','r','FontSize',20)
  63.      text(1,15,strt,'FontSize',20)
  64.      title('Saddle Node Bifurcation','FontSize',20)
  65. %get movie frame
  66.      h = gcf;
  67.      M(i) = getframe(h,[5 5 480 380]);
  68.      hold off
  69. % end of loop
  70. end
  71. %play and save movie
  72.      movie(M);
  73.      movie2avi(M,'SaddleNode','fps',1);

复制代码

点评

赞成: 5.0
赞成: 5
  发表于 2014-3-26 15:44

评分

1

查看全部评分

回复
分享到:

使用道具 举报

 楼主| 发表于 2008-4-4 09:27 | 显示全部楼层
  1. %% Animation for a Transcritical Bifurcation (same structure as Saddle-node, limited annotations for this program)

  2. xmin = -6;
  3. xmax = 6;
  4. x = xmin:0.1:xmax
  5. ax = (0.0).*x;

  6. rmin = -4
  7. rmax = 4
  8. imax = 21

  9. ymin = -6 ;
  10. ymax = 6;
  11. ky = ymin:0.1:ymax
  12. ay = (0.0).*ky

  13. for i = 1:imax
  14. %calculate r value
  15. r = rmin + (i-1)*(rmax-rmin)/(imax-1)
  16. %create title string
  17. strr = num2str(r);
  18. strt = ['r=' strr];

  19. %calculate dxdt
  20. y = r.*x - x.^2

  21. %plot x-axis
  22. plot(x,ax,'--');
  23. axis([xmin xmax ymin ymax])
  24. hold on
  25. %plot y-axis
  26. plot(ay,ky,'--')

  27. %plot f(x)
  28. plot(x,y,'r');

  29. %plot fixed points
  30. if (r < 0)
  31. plot(r,0,'o','MarkerSize',10,'MarkerEdgeColor','k');
  32. plot(0,0,'o','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  33. end
  34. if(r == 0.0)
  35. plot((-r).^(0.5),0,'*','MarkerSize',10,'MarkerEdgeColor','k');
  36. end
  37. if (r > 0)
  38. plot(r,0,'o','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  39. plot(0,0,'o','MarkerSize',10,'MarkerEdgeColor','k');
  40. end

  41. %plot flow direction
  42. if(r < 0)
  43. plot(-4.5,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  44. plot(0.5.*r,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  45. plot(4.5,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  46. end

  47. if(r == 0)
  48. plot(-4.5,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  49. plot(4.5,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  50. end

  51. if(r > 0)
  52. plot(-4.5,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k'); plot(0.5.*r,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  53. plot(4.5,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  54. end

  55. %plot labels
  56. xlabel('x','FontSize',20)
  57. ylabel('dx/dt','FontSize',20)
  58. text(-5,5,'dx/dt = rx - x^2','Color','r','FontSize',20)
  59. text(2,5,strt,'FontSize',20)
  60. title('Transcritical Bifurcation','FontSize',20)

  61. %getframe
  62. h = gcf;
  63. M(i) = getframe(h,[5 5 480 380]);
  64. hold off
  65. end

  66. %play and save movie
  67. movie(M);
  68. movie2avi(M,'Transcritical','fps',1);
复制代码
 楼主| 发表于 2008-4-4 09:27 | 显示全部楼层
  1. %% Animation for a Supercritical Pitchfork bifurcation (same structure as the Saddle Node case, limited annotation)

  2. xmin = -3;
  3. xmax = 3;
  4. x = xmin:0.1:xmax
  5. ax = (0.0).*x;

  6. rmin = -4
  7. rmax = 4
  8. imax = 21

  9. ymin = -20;
  10. ymax = 20;
  11. ky = ymin:0.1:ymax
  12. ay = (0.0).*ky

  13. for i = 1:imax
  14. %calculate r value
  15. r = rmin + (i-1)*(rmax-rmin)/(imax-1)
  16. %create title string
  17. strr = num2str(r);
  18. strt = ['r=' strr];

  19. %calculate dxdt
  20. y = r.*x - x.^3

  21. %plot x-axis
  22. plot(x,ax,'--');
  23. axis([xmin xmax ymin ymax])
  24. hold on
  25. %plot y-axis
  26. plot(ay,ky,'--')

  27. %plot f(x)
  28. plot(x,y,'r');

  29. %plot fixed points
  30. if (r < 0)
  31. plot(0,0,'o','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  32. end
  33. if(r == 0.0)
  34. plot(0,0,'*','MarkerSize',10,'MarkerEdgeColor','k');
  35. end
  36. if (r > 0)
  37. plot(0,0,'o','MarkerSize',10,'MarkerEdgeColor','k');
  38. plot(r.^(0.5),0,'o','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  39. plot(-r.^(0.5),0,'o','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  40. end

  41. %plot flow direction
  42. if(r <= 0)
  43. plot(-2.5,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  44. plot(2.5,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  45. end

  46. if(r > 0)
  47. plot(-2.5,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  48. plot(-r.^(0.5)/2,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  49. plot(r.^(0.5)/2,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  50. plot(2.5,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  51. end

  52. %plot labels
  53. xlabel('x','FontSize',20)
  54. ylabel('dx/dt','FontSize',20)
  55. text(-2,15,'dx/dt = rx - x^3','Color','r','FontSize',20)
  56. text(1,15,strt,'FontSize',20)
  57. title('Supercritical Pitchfork Bifurcation','FontSize',20)

  58. %getframe
  59. h = gcf;
  60. M(i) = getframe(h,[5 5 480 380]);
  61. hold off
  62. end

  63. %play and save movie
  64. movie(M);
  65. movie2avi(M,'SuperPitchfork','fps',1);
复制代码

点评

赞成: 5.0
赞成: 5
  发表于 2014-3-26 15:45
 楼主| 发表于 2008-4-4 09:27 | 显示全部楼层
  1. %% Animation for a Subcritical Pitchfork bifurcation

  2. xmin = -3;
  3. xmax = 3;
  4. x = xmin:0.1:xmax
  5. ax = (0.0).*x;

  6. rmin = -4
  7. rmax = 4
  8. imax = 21

  9. ymin = -20;
  10. ymax = 20;
  11. ky = ymin:0.1:ymax
  12. ay = (0.0).*ky

  13. for i = 1:imax
  14. %calculate r value
  15. r = rmin + (i-1)*(rmax-rmin)/(imax-1)
  16. %create title string
  17. strr = num2str(r);
  18. strt = ['r=' strr];

  19. %calculate dxdt
  20. y = r.*x + x.^3

  21. %plot x-axis
  22. plot(x,ax,'--');
  23. axis([xmin xmax ymin ymax])
  24. hold on
  25. %plot y-axis
  26. plot(ay,ky,'--')

  27. %plot f(x)
  28. plot(x,y,'r');

  29. %plot fixed points
  30. if (r < 0)
  31. plot(0,0,'o','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  32. plot((-r).^(0.5),0,'o','MarkerSize',10,'MarkerEdgeColor','k');
  33. plot(-(-r).^(0.5),0,'o','MarkerSize',10,'MarkerEdgeColor','k');
  34. end
  35. if(r == 0.0)
  36. plot(0,0,'*','MarkerSize',10,'MarkerEdgeColor','k');
  37. end
  38. if (r > 0)
  39. plot(0,0,'o','MarkerSize',10,'MarkerEdgeColor','k');
  40. end

  41. %plot flow direction
  42. if(r < 0)
  43. plot(-2.5,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  44. plot(-(-r).^(0.5)/2,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  45. plot((-r).^(0.5)/2,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  46. plot(2.5,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  47. end

  48. if(r >= 0)
  49. plot(-2.5,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  50. plot(2.5,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
  51. end

  52. %plot labels
  53. xlabel('x','FontSize',20)
  54. ylabel('dx/dt','FontSize',20)
  55. text(-2.5,15,'dx/dt = rx + x^3','Color','r','FontSize',20)
  56. text(1,15,strt,'FontSize',20)
  57. title('Subcritical Pitchfork Bifurcation','FontSize',20)

  58. %getframe
  59. h = gcf;
  60. M(i) = getframe(h,[5 5 480 380]);
  61. hold off
  62. end

  63. %play and save movie
  64. movie(M);
  65. movie2avi(M,'SubPitchfork','fps',1);
复制代码

点评

赞成: 5.0
赞成: 5
  发表于 2014-3-26 15:44

评分

1

查看全部评分

发表于 2008-4-4 19:23 | 显示全部楼层
非常之好!
如果我能给你加分,我就加了!
:@D
 楼主| 发表于 2008-4-4 19:54 | 显示全部楼层

回复 5楼 的帖子

看了这些程序希望对大家对基本的分岔过程有一个感性的认识,声明:此程序是网上找的
发表于 2008-4-5 19:52 | 显示全部楼层
无水,如果能把运行结果的图也贴出来就更完美了!
发表于 2008-4-5 21:09 | 显示全部楼层
我不是很懂,但我用程序运行了一下,结果依次如下,供大家参考
untitled.jpg
untitled2.jpg
untitled3.jpg
untitled4.jpg

评分

1

查看全部评分

发表于 2008-4-5 21:16 | 显示全部楼层
随着r值得增大,图形和x方向的零轴的交点也相应的变化,上面给出的只是最后r增大到4的时候的图形。
 楼主| 发表于 2008-4-6 09:59 | 显示全部楼层

回复 9楼 的帖子

那你还是把基本的概念搞清楚,这个动态的过程就是一个分岔的过程
发表于 2008-4-8 16:49 | 显示全部楼层

回复 8楼 的帖子

很强,学习中。能不能把动态图保存了?
 楼主| 发表于 2008-4-9 18:20 | 显示全部楼层

回复 11楼 的帖子

没有想过这个问题,不过可以去请matlab版的高手看看,应该可以做成moive的形式
 楼主| 发表于 2008-4-9 20:33 | 显示全部楼层

回复 11楼 的帖子

还有你可以看一下程序运行之后会保存一个avi文件,那就是录像,动态变化的
发表于 2008-5-7 15:19 | 显示全部楼层
原来是一个动态的过程啊
!!!!!
发表于 2008-5-7 20:01 | 显示全部楼层
very good:victory:
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-12-18 22:54 , Processed in 0.150714 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表