无水1324 发表于 2008-4-4 09:26

分岔的基本概念及matlab程序实现

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



%% Animation for a Saddle Node bifurcation
% Range of x
   xmin = -4;
   xmax = 4;
   x = xmin:0.1:xmax
% Some auxiliary variable to plot x-axis
   ax = (0.0).*x;
% Range of r
   rmin = -4
   rmax = 4
% number of frames in the movie
   imax = 21
% Rage of dx/dt (here y=dx/dt)
   ymin = rmin ;
   ymax = rmax + xmax.^2;
% Some auxiliary variables to plot the y-axis
   ky = ymin:0.1:ymax
   ay = (0.0).*ky
%% Start of the loop for acquisition of the movie frames
for i = 1:imax
%calculate r value
   r = rmin + (i-1)*(rmax-rmin)/(imax-1)
%create string for labelling r
   strr = num2str(r);
   strt = ['r=' strr];
%calculate dxdt
   y = r + x.^2
%plot x-axis
   plot(x,ax,'--');
% determine range of plot
   axis()
   hold on
%plot y-axis
   plot(ay,ky,'--')
%plot f(x)
   plot(x,y,'r');
%plot fixed points
if (r < 0)
   plot(-(-r).^(0.5),0,'o','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
   plot((-r).^(0.5),0,'o','MarkerSize',10,'MarkerEdgeColor','k');
end
if(r == 0.0)
   plot((-r).^(0.5),0,'*','MarkerSize',10,'MarkerEdgeColor','k');
end
%plot flow direction
if(r < 0)
   plot(-3,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
   plot(0,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
plot(3,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
end
if(r == 0)
   plot(-3,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');   
plot(3,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
end
if(r > 0)
   plot(-3,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');   plot(0,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
plot(3,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
end
%plot labels
   xlabel('x','FontSize',20)
   ylabel('dx/dt','FontSize',20)
   text(-3,15,'dx/dt = r + x^2','Color','r','FontSize',20)
   text(1,15,strt,'FontSize',20)
   title('Saddle Node Bifurcation','FontSize',20)
%get movie frame
   h = gcf;
   M(i) = getframe(h,);
   hold off
% end of loop
end
%play and save movie
   movie(M);
   movie2avi(M,'SaddleNode','fps',1);

无水1324 发表于 2008-4-4 09:27

%% Animation for a Transcritical Bifurcation (same structure as Saddle-node, limited annotations for this program)

xmin = -6;
xmax = 6;
x = xmin:0.1:xmax
ax = (0.0).*x;

rmin = -4
rmax = 4
imax = 21

ymin = -6 ;
ymax = 6;
ky = ymin:0.1:ymax
ay = (0.0).*ky

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

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

%plot x-axis
plot(x,ax,'--');
axis()
hold on
%plot y-axis
plot(ay,ky,'--')

%plot f(x)
plot(x,y,'r');

%plot fixed points
if (r < 0)
plot(r,0,'o','MarkerSize',10,'MarkerEdgeColor','k');
plot(0,0,'o','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
end
if(r == 0.0)
plot((-r).^(0.5),0,'*','MarkerSize',10,'MarkerEdgeColor','k');
end
if (r > 0)
plot(r,0,'o','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
plot(0,0,'o','MarkerSize',10,'MarkerEdgeColor','k');
end

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

if(r == 0)
plot(-4.5,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
plot(4.5,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
end

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

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

%getframe
h = gcf;
M(i) = getframe(h,);
hold off
end

%play and save movie
movie(M);
movie2avi(M,'Transcritical','fps',1);

无水1324 发表于 2008-4-4 09:27

%% Animation for a Supercritical Pitchfork bifurcation (same structure as the Saddle Node case, limited annotation)

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

rmin = -4
rmax = 4
imax = 21

ymin = -20;
ymax = 20;
ky = ymin:0.1:ymax
ay = (0.0).*ky

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

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

%plot x-axis
plot(x,ax,'--');
axis()
hold on
%plot y-axis
plot(ay,ky,'--')

%plot f(x)
plot(x,y,'r');

%plot fixed points
if (r < 0)
plot(0,0,'o','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
end
if(r == 0.0)
plot(0,0,'*','MarkerSize',10,'MarkerEdgeColor','k');
end
if (r > 0)
plot(0,0,'o','MarkerSize',10,'MarkerEdgeColor','k');
plot(r.^(0.5),0,'o','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
plot(-r.^(0.5),0,'o','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
end

%plot flow direction
if(r <= 0)
plot(-2.5,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
plot(2.5,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
end

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

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

%getframe
h = gcf;
M(i) = getframe(h,);
hold off
end

%play and save movie
movie(M);
movie2avi(M,'SuperPitchfork','fps',1);

无水1324 发表于 2008-4-4 09:27

%% Animation for a Subcritical Pitchfork bifurcation

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

rmin = -4
rmax = 4
imax = 21

ymin = -20;
ymax = 20;
ky = ymin:0.1:ymax
ay = (0.0).*ky

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

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

%plot x-axis
plot(x,ax,'--');
axis()
hold on
%plot y-axis
plot(ay,ky,'--')

%plot f(x)
plot(x,y,'r');

%plot fixed points
if (r < 0)
plot(0,0,'o','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
plot((-r).^(0.5),0,'o','MarkerSize',10,'MarkerEdgeColor','k');
plot(-(-r).^(0.5),0,'o','MarkerSize',10,'MarkerEdgeColor','k');
end
if(r == 0.0)
plot(0,0,'*','MarkerSize',10,'MarkerEdgeColor','k');
end
if (r > 0)
plot(0,0,'o','MarkerSize',10,'MarkerEdgeColor','k');
end

%plot flow direction
if(r < 0)
plot(-2.5,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
plot(-(-r).^(0.5)/2,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
plot((-r).^(0.5)/2,0,'<','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
plot(2.5,0,'>','MarkerSize',10,'MarkerEdgeColor','k','MarkerFaceColor','k');
end

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

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

%getframe
h = gcf;
M(i) = getframe(h,);
hold off
end

%play and save movie
movie(M);
movie2avi(M,'SubPitchfork','fps',1);

xinwilliam 发表于 2008-4-4 19:23

非常之好!
如果我能给你加分,我就加了!
:@D

无水1324 发表于 2008-4-4 19:54

回复 5楼 的帖子

看了这些程序希望对大家对基本的分岔过程有一个感性的认识,声明:此程序是网上找的

octopussheng 发表于 2008-4-5 19:52

无水,如果能把运行结果的图也贴出来就更完美了!

buiesea 发表于 2008-4-5 21:09

我不是很懂,但我用程序运行了一下,结果依次如下,供大家参考

buiesea 发表于 2008-4-5 21:16

随着r值得增大,图形和x方向的零轴的交点也相应的变化,上面给出的只是最后r增大到4的时候的图形。

无水1324 发表于 2008-4-6 09:59

回复 9楼 的帖子

那你还是把基本的概念搞清楚,这个动态的过程就是一个分岔的过程

chencylx03 发表于 2008-4-8 16:49

回复 8楼 的帖子

很强,学习中。能不能把动态图保存了?

无水1324 发表于 2008-4-9 18:20

回复 11楼 的帖子

没有想过这个问题,不过可以去请matlab版的高手看看,应该可以做成moive的形式

无水1324 发表于 2008-4-9 20:33

回复 11楼 的帖子

还有你可以看一下程序运行之后会保存一个avi文件,那就是录像,动态变化的

whecust 发表于 2008-5-7 15:19

原来是一个动态的过程啊
!!!!!

liyu__1004 发表于 2008-5-7 20:01

very good:victory:
页: [1] 2 3
查看完整版本: 分岔的基本概念及matlab程序实现