MATLAB common nonlinear visualization drawing method - bifurcation diagram and Poincaré section (chaos visualization, Poincare section, Logistic, Henon, Lorenz, Rossler, Duffing system)

This article was first published on the WeChat public account of matlab enthusiasts, welcome to pay attention.

Please add a picture description

Conventional statement: I have no relevant engineering application experience, and I only write this blog purely because I am interested in related algorithms. So if there are mistakes, welcome to correct them in the comment area, thank you very much. This article mainly focuses on the implementation of the algorithm. I have no experience in practical applications and other issues, so I will not involve it anymore.

1 Introduction

This article briefly introduces the commonly used non-linear visualization methods. Due to space issues, it is divided into two chapters. The first part introduces the concept of phase diagram and phase space. The second part introduces the drawing method of Poincaré section and bifurcation diagram. I don’t plan to write about visualization in the third article, let’s see if I want to write a time series analysis such as spectrum analysis, Lyapunov index analysis, and dimension analysis, but this part is not very interesting, and I really have no motivation o(╥ ﹏╥) o.

Nonlinear mathematical research has been born for a long time. From the butterfly effect to the present, the commonly used analysis methods have not changed much. The research direction of each field is different, but if the nonlinearity of the equation is involved in the thesis, a qualitative analysis is always required. Since the methods are similar, you can often refer to methods related to nonlinear analysis in other fields or good-looking way of drawing.

This blog mainly talks about how to draw a bifurcation diagram, and by the way, how to draw a Poincaré section. Bifurcation generally refers to a phenomenon in which a certain constant in the system changes, causing the entire system to change accordingly. In a circuit, it may be a change in capacitance, in a mechanical system, it may be a change in the frictional resistance of a bearing, and in a flow field, it may be a change in wind speed. Small changes in these parameters will cause a sudden change in the temperament of the system, becoming oscillating and diverging out of control.

The previous article introduced the drawing of phase diagrams, which can be regarded as the basis of nonlinear visualization. It is recommended to take a look at the previous article:
MATLAB common nonlinear visualization drawing methods - phase diagram and phase space https://blog.csdn. net/weixin_42943114/article/details/123193855

References
[1] Morris W. Hirsch. Introduction to Differential Equations, Dynamical Systems and Chaos [M]. People's Posts and Telecommunications Press, 2008. [
2] Liu Bingzheng. Nonlinear Dynamics and Chaos Foundation [M]. Published by Northeast Normal University Society, 1994.
[3] Khalil HK . Nonlinear Systems (3rd Edition) [M]. Electronic Industry Press, 2005. [
4]Morris W. Hirsch. Differential equations, dynamical systems, and an introduction to chaos [M ] Academic Press
[5] Introduction to Differential Equations, Dynamical Systems and Chaos [M]
[6] Fundamentals of Computational Physics-Chapter 10 Lecture 77 (Beijing Normal University) (Chinese University MOOC) Fundamentals of Computational Physics_Beijing Normal University_China University MOOC (MOOC) (icourse163.org)
[7]Computing accurate Poincaré maps[J]. PHYSICA D, 2002, 171(3):127-137.
[8]Santo Banerjee. Applications of Chaos and Nonlinear Dynamics in Engineering[ M]. Springer, 2011
[9]Ali.H.Nayfeh. Applied Nonlinear Dynamics Analytical, Computational, and Experimental Methods[M]. 1995. (Using the Henon system in P284)
[10]James Gleick. Chaos: Create new science[M].

2 Bifurcation Diagram Drawing of Discrete Nonlinear System

2.1 Bifurcation diagram of one-dimensional Logistic system

A logistic system is a very simple map in the form of a quadratic polynomial. The map was developed by biologist Robert May in 1976 to show that even very simple systems can generate chaos. Its iteration equation is as follows:
xn + 1 = a ( 1 − xn ) xn x_{n+1}=a(1-x_n)x_nxn+1=a(1xn)xn
This iterative equation is used to describe the change in the population growth of a certain species. Among them, the meaning of x is the number of existing species divided by the theoretical maximum number, and a is the growth rate. According to the equation, the change in the number of species is related to the existing population x of the species, and is also related to the environmental pressure (1-x) brought about by overpopulation.

When the growth rate a is less than 1, the species gradually dies out; when the growth rate is between 1 and 3, the species can be stabilized within a range; when the growth rate is larger, a nonlinear phenomenon will gradually appear.

There are two ways to draw its bifurcation diagram:

The first one is to evenly distribute the initial points, and then perform successive iterations to observe the law of motion.

For example, the following figure selects two parameters of a=2.1 and a=3.3, initially distributes each initial value, performs iterations, and observes the changes of these initial values: it can be seen that
Please add a picture description
when a=2.1, all populations finally converge to 1 point. When a=3.3, all population points finally converge to 2 points.

Continue to refine the value of a, list a graph, and you can see the convergence law of the system under different parameter a changes: the
Please add a picture description
result of the final iteration 200 times is shown in the figure below:
Please add a picture description
this embodiment changes with a certain parameter (such as a), resulting in A graph in which the behavior of the system changes is called a bifurcation graph .

Of course, in order to look good, you can also add a little color according to the density of the points, such as the following.
Please add a picture description
The code for the above figures is as follows:

clear
clc
close all
%分岔图
%离散系统

%% 1Logistic系统
%% 1.1Logistic系统 两个典型的a,进行迭代的效果
d=0.004;
x=d:d:1-d;
Nx=length(x);
BF=zeros(1,Nx);
a1=2.1;
a_k1=a1;%第一个a=2.1
a2=3.3;
a_k2=a2;%第二个a=3.3
x1=x;
x2=x;
%在系统中迭代50次
for m=1:50
    %把结果绘图
    f1=figure(1);
    set(f1,'Color',[1,1,1])
    clf
    subplot(1,2,1)
    plot(a1*ones(size(x1)),x1,'.')
    ylim([0,1])
    text(a1-0.8,0.5,['a1=',num2str(a1)])
    text(a1-0.8,0.4,['迭代次数',num2str(m)])
    subplot(1,2,2)
    plot(a2*ones(size(x1)),x2,'.')
    ylim([0,1])
    text(a2-0.8,0.5,['a2=',num2str(a2)])
    text(a2-0.8,0.4,['迭代次数',num2str(m)])
    pause(0.1)
    %更新下一次迭代
    x1=Logistic(x1,a_k1);
    x2=Logistic(x2,a_k2);
end

%% 1.2 不同a,绘制分岔图
%初始种群采用均匀分布
d=0.005;
x=d:d:1-d;
a=0:0.004:4;%把a采集的足够密,就可以绘制随参数a变化的分岔图

Nx=length(x);
Na=length(a);
BF=zeros(Na,Nx);%初始化最终储存的矩阵

for k=1:Na
    a_k=a(k);
    x1=x;
    %在系统中迭代200次
    for m=1:200
        x1=Logistic(x1,a_k);
    end
    %把结果保存
    BF(k,:)=x1;
end

%画图
figure()
hold on
for k=1:Na
    a_k=a(k);
    plot(a_k*ones(1,Nx),BF(k,:),...
        'LineStyle','none','Marker','.','MarkerFaceColor','k','MarkerEdgeColor','k',...
        'MarkerSize',1)
end
hold off
xlabel('a')

%% 1.3 不同a 动图,把上面那个分岔图的过程展示出来
d=0.005;
x=d:d:1-d;
a=0:0.004:4;

Nx=length(x);
Na=length(a);
BF=ones(Na,1)*x;
BFx=a'*ones(1,Nx);
%在系统中迭代100次
for m=1:90
	%绘制图片
    f3=figure(3);
    clf
    scatter(BFx(:),BF(:),0.5,'k','MarkerEdgeAlpha',0.5)
    text(0.7,0.6,['迭代次数',num2str(m)])
    xlabel('a')
    ylabel('x')
    set(f3,'Color',[1,1,1])
    pause(0.1)
    
	%迭代更新
    for k=1:Na
        a_k=a(k);
        x1=BF(k,:);
        x1=Logistic(x1,a_k);
        %把结果保存
        BF(k,:)=x1;
    end
end

%% 1.4 不同a上颜色
d=0.002;
x=d:d:1-d;
a=0:0.002:4;
Nx=length(x);
Na=length(a);
BF=zeros(Na,Nx);

for k=1:Na
    a_k=a(k);
    x1=x;
    %在系统中迭代250次
    for m=1:250
        x1=Logistic(x1,a_k);
    end
    %把结果保存
    BF(k,:)=x1;
end
%上颜色
BF_C=zeros(size(BF));
for k=1:Na
    BF_k=BF(k,:);
    [N,~,bin] = histcounts(BF_k,[0:0.01:1]);%统计每个小区间,点的数量,作为颜色
    BF_C(k,:)=N(bin);%记录各个点的颜色
end
BFy=BF;
BFx=a'*ones(1,Nx);
figure()
scatter(BFx(:),BFy(:),0.5,BF_C(:),'MarkerEdgeAlpha',0.5)
caxis([0,20])
colormap(jet)
ylim([0,1]);
xlim([2,4]);


%% 后置函数
function x2=Logistic(x1,a)
%Logistic系统
%x(n+1)=a*(1-x(n))*x(n)
x2=a*(1-x1).*x1;
end

As mentioned above, there are two methods for drawing bifurcation diagrams. The second method is to select a random initial point for iteration, and then take its last 200 historical positions (or motion processes) as the bifurcation diagram instead of the final one. All positions of all points at any time.

The advantage of this method is that the calculation is fast, and only one initial point can be selected, and there is no need to use 200 points to iterate together.

The code is as follows, the specific code difference can be compared with the code 1.2 in the method 1 above:

%% 2.1 换一种计算方法
%初始化
a=0:0.004:4;
Nx=200;%最终储存最后200个点
Na=length(a);
BF=zeros(Na,Nx);

for k=1:Na
    a_k=a(k);
    x0=0.234;%随便初始一个点
    for m=1:100 %先初始100步,来排除初始点选取的干扰
        x0=Logistic(x0,a_k);
    end
    xs=zeros(1,Nx);%再正式开始循环,记录下一个点在迭代时候每一个位置
    for m=1:Nx
        x2=x0;
        x0=Logistic(x2,a_k);
        xs(m)=x2;
    end
    %把结果保存
    BF(k,:)=xs;
end
%画图%这里用scatter还是plot函数绘图都行
figure()
hold on
for k=1:Na
    a_k=a(k);
    plot(a_k*ones(1,Nx),BF(k,:),...
        'LineStyle','none','Marker','.','MarkerFaceColor','k','MarkerEdgeColor','k',...
        'MarkerSize',1)
end
hold off
xlabel('a')
ylabel('x')

%% 后置函数
function x2=Logistic(x1,a)
%Logistic系统
%x(n+1)=a*(1-x(n))*x(n)
x2=a*(1-x1).*x1;
end

Please add a picture description
The final result is as above, and it can be seen that it is not much different from the result of the previous method one.

Because what should be convergent will eventually converge, what should be bifurcated will also bifurcate, and what should be chaotic will still be chaotic. This is the behavior characteristic of the system itself, and has nothing to do with the initial selection point.

In addition, one more long-winded sentence, the Logistic system has a very typical period-doubling bifurcation characteristic, that is, the line of the bifurcation diagram is divided from 1 into 2, 2 into 4, and 4 into 8, and then the bifurcation speed becomes faster and faster until it enters a chaotic state. Here 2 forks represent that the iteration result changes back and forth between two points, and the period is 2; similarly, 4 forks represent that the point jumps back and forth at 4 points, and the period is 4. This is my personal interpretation of the period-doubling bifurcation.

2.2 Bifurcation diagram of two-dimensional Henon system

The Henon system was introduced by Michel Hénon probably in the 1960s and 1970s as a simplified model of the Poincaré section of the Lorenz model. Therefore, I also plan to use it as a key entry point to connect discrete systems and Poincaré sections.

So in this section, how to draw a bifurcation diagram with a two-dimensional discrete system.

The Henon system has two variables x and y, and its iteration formula is:
xn + 1 = 1 + yn − a ∗ xn 2 yn + 1 = b ∗ xn x_{n+1}=1+y_n-a*x_n^2 \\ y_{n+1}=b*x_nxn+1=1+ynaxn2yn+1=bxn
Here we take b=0.3, then the only variable parameter of the system is a.

When a=0.2, the whole system finally stabilizes to the point (x=1.09, y=3.27). When a=0.95, the system moves periodically back and forth on 4 points. When a=1.38, the system will fall into chaos.

The figure below shows the final form of the system when different values ​​of a are taken.
Please add a picture description
So how to convert this two-dimensional result graph to a bifurcation graph? In the previous one-dimensional Logistic system bifurcation diagram, the vertical axis is directly x. For the two-dimensional discrete results, we need to project onto the one-dimensional results first, and then draw the bifurcation diagram.

To be simple, we can directly project on the y-axis, and we use the y-value of the system to draw the bifurcation diagram; or project onto the x-axis, and use the system's x-value to draw the bifurcation diagram. (Or projected onto a special line, but generally simple points are directly projected onto the axis)
Please add a picture description
Please add a picture description
It can be seen that, except for a slightly different shape, the position of the bifurcation point is exactly the same as the shape after the bifurcation of.
Therefore, for the bifurcation diagram of a two-dimensional system or a higher-dimensional system, it is only necessary to project the discrete points onto an axis, without affecting the analysis and judgment of the bifurcation points of the system.

The drawing code is as follows. Here, due to the large amount of two-dimensional calculations, the second method is directly used, that is, only one initial point is selected for iteration, and then the process is recorded.

clear
clc
close all
%分岔图
%离散系统
%% 2 Henon系统
a=0:0.0016:1.4;
%采用直接截取迭代中间过程,作为分岔图
NT=300;%选取最后300次结果
Na=length(a);
BF_x=zeros(Na,NT);
BF_y=zeros(Na,NT);

for k=1:Na
    a_k=a(k);
    %初始值取0
    x1=0;
    y1=0;
    %先初始迭代200次,避免初始值选取引起的干扰
    for m=1:200
        [x1,y1]=Henon(x1,y1,a_k,0.3);
    end
    %然后再迭代300次,作为要保存的结果
    for m=1:NT
        [x1,y1]=Henon(x1,y1,a_k,0.3);
        %把结果保存
        BF_x(k,m)=x1;
        BF_y(k,m)=y1;
    end
end

%分岔图1,用y绘图
figure()
hold on
for k=1:Na
    a_k=a(k);
    plot(a_k*ones(1,NT),BF_y(k,1:NT),...
        'LineStyle','none','Marker','.','MarkerFaceColor','k','MarkerEdgeColor','k',...
        'MarkerSize',1)
end
hold off
xlabel('a')
ylabel('y')
%分岔图2,用x绘图
figure()
hold on
for k=1:Na
    a_k=a(k);
    plot(a_k*ones(1,NT),BF_x(k,1:NT),...
        'LineStyle','none','Marker','.','MarkerFaceColor','k','MarkerEdgeColor','k',...
        'MarkerSize',1)
end
hold off
xlabel('a')
ylabel('x')
ylim([-1.5,2])
%绘制典型情况的最终x-y图
figure()
aa=[0.2,0.95,1.036,1.076,1.08,1.38];%要展示的aa图
for k=1:6
    subplot(2,3,k)
    [~,Ind_a]=min(abs(a-aa(k)));
    plot(BF_x(Ind_a,:),BF_y(Ind_a,:),'LineStyle','none','Marker','.')
    xlim([-1.5,1.5])
    ylim([-0.4,0.4])
    xlabel('x');ylabel('y');
    title(['a=',num2str(aa(k))])
end

%% 后置函数
function [x2,y2]=Henon(x1,y1,a,b)
%Henon系统
%x(n+1)=1+y(n)-a*x(n)^2
%y(n+1)=b*x(n)
x2=1+y1-a*x1.*x1;
y2=b*x1;
end

3 Poincaré section

3.1 Drawing ideas

For a chaotic system, its trajectory is often chaotic and disorderly, and it is difficult to describe it concisely. Then one of the ideas is to simplify information, reduce the dimension of description, and simplify the trajectory of space into a series of discrete points.

For a system with periodic or quasi-periodic motion, the motion in phase space is represented by rotation round after round. We define a section (usually a plane), and record the intersection point when the trajectory passes through this surface. When enough intersection points are recorded, the image formed by these intersection points is the image of the Poincaré section. We call this surface intersecting the trajectory the Poincaré section.

Next, I will roughly demonstrate the general idea mentioned above by drawing the bifurcation diagram of the Duffing equation.

The Duffing equation is a nonlinear equation named after Georg Duffing. It is based on the equation proposed by the simple pendulum of forced vibration. It was proposed very early, but it was used for chaos research relatively late. Since it has a very obvious and simple physical model behind it, it is even possible to do experiments to observe the nonlinearity of this equation [6]. The form of the equation is:

x ¨ = − x 3 + x − δ x ˙ + γ cos ⁡ ( ω t ) \ddot{x}=-x^3+x-\delta \dot{x}+\gamma \cos{(\omega t )}x¨=x3+xdx˙+ccos( t ) _

Putting this equation into a third-order system of equations, we get:

[ xx ˙ z ] ′ = [ x ˙ − x 3 + x − δ x ˙ + γ z − ω sin ⁡ ( ω t ) ] \begin{bmatrix} x \\ \dot{x} \\ z \end{ bmatrix} ' =\begin{bmatrix} \dot{x} \\ -x^3+x-\delta \dot{x}+\gamma z \\ -\omega \sin{(\omega t)} \end {bmatrix}xx˙z=x˙x3+xdx˙+γz- Ohsin( t ) _
Here is a time-varying variable cos(wt), for the convenience of analysis, it is defined as z=cos(wt) separately.

Now, I have a third-order nonlinear system of equations. Default ω=1, γ=1.

Afterwards, we define z=0 in the space as the plane on which the trajectory is to be cut. Moreover, the trajectory is recorded only when it passes through the plane in the forward direction, and not recorded when it passes through the plane in the reverse direction. This is to allow only one point to be recorded in one cycle.

The figure below shows its three-dimensional trajectory and Poincaré section when δ=1.5, δ=1.35, and δ=1.15: Of
Please add a picture description
course, the z=0 section actually defined should be infinite in space without boundary restrictions, here for convenience For drawing, a quadrilateral was used instead, hoping not to cause misunderstanding.

Through the Poincaré section, you can know the approximate characteristics of the system. For example, when δ=1.5, the Poincaré section has only 1 point, which proves that the system is a period 1 system. When δ=1.35, the Poincaré cross-section becomes 2 points, indicating that the system is a period 2 system, returning to the starting point twice per revolution. When δ=1.5, the Poincaré section becomes close to a curve, indicating that the system is likely to be a quasi-periodic motion.

So the drawing method of the Poincaré section can be divided into 3 steps:

1 计算出轨线
2 计算轨线与某一平面的交点
3 将交点绘制出来,就得到了庞加莱截面

The second step is to calculate the intersection point, which is usually obtained by interpolation.

Here is the plotting code:

%庞佳莱截面
%截面采用公式Ax+By+Cz+D=0;的形式
%采用杜芬方程
clear
clc
close all
%% 第一步,计算出轨迹
h=5e-3;
x0=0:h:1600;
y0=[0.1;0.1;1];%最后一项是cos(w*t),当t=0时必须为1.
[y1,Output]=ODE_RK4_hyh(x0,h,y0,[1.5,1,1]);
%[1.5,1,1],[1.35,1,1],[1.15,1,1]
Lx=y1(1,2000:end);
Ly=y1(2,2000:end);
Lz=y1(3,2000:end);
%% 第二步,计算与平面的交点
Plane=[0;0;1;0];%一般情况下是个垂直某个轴的平面。这里是Ax+By+Cz+D=0的形式给出的平面。
[tP_List,yP_List]=Solve_Poincare(x0,y1,Plane);%计算Poincare平面

%% 第三步,绘制庞加莱截面
%1庞加莱截面
%最开始几个点还没有稳定,没有体现出系统特点,所以放弃
figure()
plot(yP_List(1,10:end),yP_List(2,10:end),'.')%从第10个点之后开始绘制
xlim([-1,0.6])
ylim([-0.8,0.2])

%2展示用的示意图,只作为演示
figure()
hold on
patch([Lx,nan],[Ly,nan],[Lz,nan],[Lx+Ly,nan],...
    'EdgeColor','interp','Marker','none','MarkerFaceColor','flat','LineWidth',0.8,'FaceAlpha',1);
plot3(yP_List(1,10:end),yP_List(2,10:end),zeros(size(yP_List(2,10:end))),...
    '.','MarkerSize',8,'color','r')
patch([-1.6,0.4,0.4,-1.6],[-0.7,-0.7,0.0,0.6],[0,0,0,0],[1,1,1,1],...
    'FaceAlpha',0.8,'EdgeColor',[0.5,0.5,0.5]) 
view([-17,39])
box on
grid on
%绘制投影的相图
set(gcf,'position',[300 200 560 500])
xlim([-2,2])
zlim([-3,1])
plot3( Lx,Ly,zeros(size(Ly))-3 ,'color','k')
hold off

%% 后置函数
function [tP_List,yP_List]=Solve_Poincare(t,y,Plane)
%截面方程z=0
% Plane=[0;0;1;0];%一般情况下是个垂直某个轴的平面
%一般只记录从负到正穿越。如果想反向也记录,可以设置Plane=-Plane。

%第二步,插值得到线与面的交点
yP_List=[];
tP_List=[];
Dis=DistancePlane(y,Plane);
N=size(y,2);
for k=1:N-1
    if Dis(k)<=0 && Dis(k+1)>0
        t0=t(k);t1=t(k+1);
        yP0=y(:,k);yP1=y(:,k+1);
        Dis0=Dis(k);Dis1=Dis(k+1);
        %一维线性插值,求Dis=0时的t和y
        %(相比较前面积分的4阶RK,这里用线性插值精度有点低,先这么凑合着吧)
        yP=yP0+(yP1-yP0)/(Dis1-Dis0)*(0-Dis0);
        tP=t0+(t1-t0)/(Dis1-Dis0)*(0-Dis0);
        %储存
        yP_List=[yP_List,yP];
        tP_List=[tP_List,tP];
    end
end
end


%点到平面的距离
function Dis=DistancePlane(xk,Plane)
% xk,坐标点,如果是3维坐标,大小就是3*N的矩阵。
% Plane,平面,形如Ax+By+Cz+D=0形式的平面。

N=size(xk,2);%计算总共多少个点
xk2=[xk;ones(1,N)];
Dis=dot(xk2,Plane*ones(1,N),1)./norm(Plane(1:end-1));
end

%两点线性插值
function y=interp2point_linear(x0,x1,y0,y1,x)
y=y0+(y1-y0)/(x1-x0)*(x-x0);
end

%两点3次插值
function y=interp2point_spline(x0,x1,y0,y1,x)
%y0包含y0的值和y0的导数,yy=y0(1),dy=y0(2)
xx0=x0;
xx1=x1;
yy0=y0(1);dy0=y0(2);
yy1=y1(1);dy1=y1(2);
cs = csape([xx0,xx1],[dy0,yy0,yy1,dy1],[1,1]);
y=ppval(cs,x);
end

function [F,Output]=Fdydx(x,y,Input)
%形式为Y'=F(x,Y)的方程,参见数值分析求解常系数微分方程相关知识
%高次用列向量表示,F=[dy(1);dy(2)];y(1)为函数,y(2)为函数导数
%杜芬方程duffing,参见中国大学MOOC,北京师范大学-计算物理基础-77倒摆与杜芬方程
d=Input(1);
r=Input(2);
w=Input(3);

dy(1)=y(2);
dy(2)=-y(1)^3+y(1)-d*y(2)+r*y(3);
dy(3)=-w*sin(w*x);

F=[dy(1);dy(2);dy(3)];
Output=[];
end

function [y,Output]=ODE_RK4_hyh(x,h,y0,Input)
%4阶RK方法
%h间隔为常数的算法
y=zeros(size(y0,1),size(x,2));
y(:,1)=y0;
for ii=1:length(x)-1
    yn=y(:,ii);
    xn=x(ii);
    [K1,~]=Fdydx(xn    ,yn       ,Input);
    [K2,~]=Fdydx(xn+h/2,yn+h/2*K1,Input);
    [K3,~]=Fdydx(xn+h/2,yn+h/2*K2,Input);
    [K4,~]=Fdydx(xn+h  ,yn+h*K3  ,Input);
    y(:,ii+1)=yn+h/6*(K1+2*K2+2*K3+K4);
end
Output=[];
end

3.2 Quick drawing with stroboscopic method

This calculation method, the specific idea is still the three steps.

1 计算出轨线
2 计算轨线与某一平面的交点
3 将交点绘制出来,就得到了庞加莱截面

But the second step is no longer directly obtained by interpolating two points on the trajectory, but directly obtained by time t.

For example, the following is our Duffin equation in Section 3.1. We take the z=0 plane as the Poincaré section.
[ xx ˙ z ] ′ = [ x ˙ − x 3 + x − δ x ˙ + γ z − ω sin ⁡ ( ω t ) ] \begin{bmatrix} x \\ \dot{x} \\ z \end{ bmatrix} ' =\begin{bmatrix} \dot{x} \\ -x^3+x-\delta \dot{x}+\gamma z \\ -\omega \sin{(\omega t)} \end {bmatrix}xx˙z=x˙x3+xdx˙+γz- Ohsin( t ) _
However, z=0 can obviously be calculated. z=cos(t), when t=0.5π+2kπ and t=1.5π+2kπ, z is unconditionally equal to 0.
For the Poincaré section, we only take one point for one cycle, so the time t of all points on the Poincaré section should satisfy t=1.5π+2kπ.

Because, for the stroboscopic sampling method, it means to take points once in a while, and these points are naturally on a certain Poincaré section. This method uses pre-calculated time intervals, which greatly reduces the amount of calculations in the program.

Also take δ=1.15, the results of the Poincaré section are shown in the figure below. It can be seen that this lazy method has the same result as the honest calculation in the previous chapter.
Please add a picture description
In fact, since there is no need to calculate the specific value of z, the step of calculating z can even be omitted from the equation. In this way, although there is no z variable, the Poincaré section of the system at z=0 is still calculated.
[ xx ˙ ] ′ = [ x ˙ − x 3 + x − δ x ˙ + γ cos ⁡ ( ω t ) ] \begin{bmatrix} x \\ \dot{x} \\ \end{bmatrix} ' =\ begin{bmatrix} \dot{x} \\ -x^3+x-\delta \dot{x}+\gamma \cos{(\omega t) } \end{bmatrix}[xx˙]=[x˙x3+xdx˙+ccos( t ) _]
The code is as follows:

%庞佳莱截面(频闪法)
%采用杜芬方程
clear
clc
close all
%第一步,计算出轨迹
h=5e-3;
x0=0:h:1600;
y0=[0.1;0.1];%这里简化了方程,所以只有两个输入
[y1,Output]=ODE_RK4_hyh(x0,h,y0,[1.15,1,1]);
%[1.5,1,1],[1.35,1,1],[1.15,1,1],[0.1,0.35,1.4]
Lx=y1(1,:);
Ly=y1(2,:);
%Lz=cos(1*x0);

%采用频闪采样法计算
tP_Ideal=3*pi/2:(2*pi/1):x0(end);%这里考虑z=0平面,时间间隔dt=2*pi。
tP_List=zeros(1,length(tP_Ideal));
Ind_List=zeros(1,length(tP_Ideal));
for k=1:length(tP_Ideal)
    [~,Ind]=min(abs( tP_Ideal(k)-x0 ));%直接根据索引来找到对应的点
    Ind_List(k)=Ind;
    tP_List(k)=x0(Ind);
end
yP_List=y1(:,Ind_List);
%注,如果上面时间间隔h为pi/600之类的形式,这里连min函数都可以取消,直接按照索引去寻找就行

%绘图
%1庞加莱截面
%最开始几个点还没有稳定,没有体现出系统特点,所以放弃
figure()
plot(yP_List(1,10:end),yP_List(2,10:end),'.')
xlim([-1,0.6])
ylim([-0.8,0.2])


function [F,Output]=Fdydx(x,y,Input)
%形式为Y'=F(x,Y)的方程,参见数值分析求解常系数微分方程相关知识
%高次用列向量表示,F=[dy(1);dy(2)];y(1)为函数,y(2)为函数导数
d=Input(1);
r=Input(2);
w=Input(3);

dy(1)=y(2);
dy(2)=-y(1)^3+y(1)-d*y(2)+r*cos(w*x);
% dy(3)=-w*sin(w*x);%由于无需计算具体的z值,所以这里把z合并到了dy(2)项里,减少计算量

F=[dy(1);dy(2)];
Output=[];
end

function [y,Output]=ODE_RK4_hyh(x,h,y0,Input)
%4阶RK方法
%h间隔为常数的算法
y=zeros(size(y0,1),size(x,2));
y(:,1)=y0;
for ii=1:length(x)-1
    yn=y(:,ii);
    xn=x(ii);
    [K1,~]=Fdydx(xn    ,yn       ,Input);
    [K2,~]=Fdydx(xn+h/2,yn+h/2*K1,Input);
    [K3,~]=Fdydx(xn+h/2,yn+h/2*K2,Input);
    [K4,~]=Fdydx(xn+h  ,yn+h*K3  ,Input);
    y(:,ii+1)=yn+h/6*(K1+2*K2+2*K3+K4);
end
Output=[];
end

This method can only be used in some special systems with clear periodicity.

When [δ, γ, ω] = [0.1, 0.35, 1.4], the system will be chaotic, and its Poincaré cross-section will also appear in a chaotic form: the
Please add a picture description
above graph involves a lot of points, so it cannot be obtained in one go , can only be obtained by calculating one by one. The drawing code is as follows, for reference only:

clear
clc
close all
%初始化
h=2*pi/700;
x0=0:h:2e5*pi/700;
y0=[0.1;0.1];%最后一项是cos(w*t),当t=0时必须为1
%这里一口气求出一大堆点不太现实,内存有限,所以采取分批计算,逐步绘图来实现
figure(1)
hold on
for k=1:100
    [y1,Output]=ODE_RK4_hyh(x0,h,y0,[0.1,0.35,1.4]);
    Lx=y1(1,:);
    Ly=y1(2,:);
    %采用频闪采样法计算
    %由于w变为了1.4,这里还是z=0平面,采样间隔改为 (3*pi/2:(2*pi/1):2000)/1.4
    yP_List=y1(:,376:500:end);%注,这里376=3/2/1.4*350+1

    %内存有点不够了,分段进行下面的计算
    x0=x0+2e5*pi/700;%时间整体向后移动
    y0=y1(:,end);%把最后一刻的状态当做下一个时间段初始状态
    %绘图
    %1庞加莱截面
    scatter(yP_List(1,1:end),yP_List(2,1:end),0.8,'k','MarkerEdgeAlpha',0.6)
    %disp(k)
end

function [F,Output]=Fdydx(x,y,Input)
%形式为Y'=F(x,Y)的方程,参见数值分析求解常系数微分方程相关知识
%高次用列向量表示,F=[dy(1);dy(2)];y(1)为函数,y(2)为函数导数
d=Input(1);
r=Input(2);
w=Input(3);
dy(1)=y(2);
dy(2)=-y(1)^3+y(1)-d*y(2)+r*cos(w*x);
F=[dy(1);dy(2)];
Output=[];
end

function [y,Output]=ODE_RK4_hyh(x,h,y0,Input)
%4阶RK方法
%h间隔为常数的算法
y=zeros(size(y0,1),size(x,2));
y(:,1)=y0;
for ii=1:length(x)-1
    yn=y(:,ii);
    xn=x(ii);
    [K1,~]=Fdydx(xn    ,yn       ,Input);
    [K2,~]=Fdydx(xn+h/2,yn+h/2*K1,Input);
    [K3,~]=Fdydx(xn+h/2,yn+h/2*K2,Input);
    [K4,~]=Fdydx(xn+h  ,yn+h*K3  ,Input);
    y(:,ii+1)=yn+h/6*(K1+2*K2+2*K3+K4);
end
Output=[];
end

4 Bifurcation diagrams of nonlinear systems

The bifurcation diagrams for discrete systems were introduced earlier. For a continuous system, how to draw a bifurcation diagram?

The general idea is:

  1先绘制出系统的轨线 (3维系统转3维曲线,用轨线)
  2绘制轨线和某个面的交点(3维曲线转2维点,用庞加莱截面)
得到某个平面的上的若干点后,问题就转化为前面二维离散系统的分岔图了:
  4将这些点投影到某个线上(2维的点转1维的值)
  5绘制分岔图

The purpose is to transform the continuous system into a scatter-point form that can draw bifurcation diagrams.

4.1 Bifurcation diagram of Duffing system

Taking the Duffin equation introduced earlier as an example, the bifurcation diagram of fixing ω=1, γ=1 and changing δ is as follows. The drawing method is to calculate the Poincaré section under each δ, and then take the coordinate y as the bifurcation diagram in the same way as the previous discrete point bifurcation.

Please add a picture description

The drawing code is as follows, the calculation time is relatively long, you need to wait patiently for a while:

%利用庞佳莱截面绘制分岔图
clear
clc
close all
%第一步,计算出轨迹
h=8e-3;
x0=0:h:1600;
y0=[0.1;0.1];%最后一项是cos(w*t),当t=0时必须为1.

%不同的d
d=0.5:0.002:1.5;%0.02
N_c=length(d);
N_P=250;%假设穿过截面的共有250个点
BF=nan(N_c,N_P);
%第二步,这里直接用频闪法求出截面所在点的索引
%z=0平面
tP_Ideal=3*pi/2:(2*pi/1):x0(end);%这里考虑z=0平面,时间间隔dt=2*pi。
tP_List=zeros(1,length(tP_Ideal));
Ind_List=zeros(1,length(tP_Ideal));
for m=1:length(tP_Ideal)
    [~,Ind]=min(abs( tP_Ideal(m)-x0 ));
    Ind_List(m)=Ind;
    tP_List(m)=x0(Ind);
end
%第三步,开始对每一个d进行循环,计算其庞加莱截面
for k=1:N_c
    d_k=d(k);
    [y1,~]=ODE_RK4_hyh(x0,h,y0,[d_k,1,1]);
    yP_List=y1(:,Ind_List);
    %储存
    N_P_temp=size(tP_List,2);
    if N_P_temp>N_P
        BF(k,1:N_P)=yP_List(2,1:N_P);%取坐标y作为分岔图
    else
        BF(k,1:N_P_temp)=yP_List(2,1:N_P_temp);%取坐标y作为分岔图
    end
    disp(d_k)
end
%最后一步,绘图
figure()
hold on
for k=1:N_c
    d_k=d(k);
    plot(d_k*ones(1,N_P-30+1),BF(k,30:N_P),...
        'LineStyle','none','Marker','.','MarkerFaceColor','k','MarkerEdgeColor','k',...
        'MarkerSize',1)
end
hold off

function [F,Output]=Fdydx(x,y,Input)
%形式为Y'=F(x,Y)的方程,参见数值分析求解常系数微分方程相关知识
%高次用列向量表示,F=[dy(1);dy(2)];y(1)为函数,y(2)为函数导数
d=Input(1);
r=Input(2);
w=Input(3);
dy(1)=y(2);
dy(2)=-y(1)^3+y(1)-d*y(2)+r*cos(w*x);
F=[dy(1);dy(2)];
Output=[];
end

function [y,Output]=ODE_RK4_hyh(x,h,y0,Input)
%4阶RK方法
%h间隔为常数的算法
y=zeros(size(y0,1),size(x,2));
y(:,1)=y0;
for ii=1:length(x)-1
    yn=y(:,ii);
    xn=x(ii);
    [K1,~]=Fdydx(xn    ,yn       ,Input);
    [K2,~]=Fdydx(xn+h/2,yn+h/2*K1,Input);
    [K3,~]=Fdydx(xn+h/2,yn+h/2*K2,Input);
    [K4,~]=Fdydx(xn+h  ,yn+h*K3  ,Input);
    y(:,ii+1)=yn+h/6*(K1+2*K2+2*K3+K4);
end
Output=[];
end

4.2 Bifurcation Diagram of Rossler System

The Rossler system is a nonlinear system proposed by Rössler himself in the 1970s. The form is relatively simple, but it still has complex nonlinear behavior.

The equation is:

x ˙ = − y − z y ˙ = x + a y z ˙ = b + z ( x − c ) \dot{x}=-y-z \\ \dot{y}=x+ay \\ \dot{z}=b+z(x-c) \\ x˙=yzy˙=x+and yz˙=b+z(xc)
The figure below draws a=0.1, b=0.1, changing the trajectory diagram drawn by different c.
Please add a picture description
Here, according to its trajectory characteristics, the x=0.1 plane is selected as its Poincaré section.

The drawing code is as follows, it takes a long time to run, so you need to wait patiently.

%利用庞佳莱截面绘制分岔图
%截面采用公式Ax+By+Cz+D=0;的形式
%Rossler方程
clear
clc
close all
h=5e-3;%时间步长
x0=0:h:800;%时间
y0=[2;2;2];

%不同的c开始循环
c=3:0.02:16;
N_c=length(c);
N_P=300;%假设穿过截面的共有300个点
BF=nan(N_c,N_P);
for k=1:N_c
    c_k=c(k);disp(c_k)
    %计算出轨迹
    [y1,~]=ODE_RK4_hyh(x0,h,y0,[0.1,0.1,c_k]);
    %计算Poincare平面
    Plane=[1;0;0;0.1];%x=0.1平面(正方向)
    [tP_List,yP_List]=Solve_Poincare(x0,y1,Plane);%计算Poincare平面
    %储存y值作为待会分岔图的点
    N_P_temp=size(tP_List,2);
    if N_P_temp>N_P
        BF(k,1:N_P)=yP_List(2,1:N_P);
    else
        BF(k,1:N_P_temp)=yP_List(2,1:N_P_temp);
    end
end

%绘制分岔图
figure()
hold on
for k=1:N_c
    c_k=c(k);
    plot(c_k*ones(1,N_P-30+1),BF(k,30:N_P),...
        'LineStyle','none','Marker','.','MarkerFaceColor','k','MarkerEdgeColor','k',...
        'MarkerSize',1)
end
hold off

%后置函数
function [tP_List,yP_List]=Solve_Poincare(t,y,Plane)
%截面方程z=0
% Plane=[0;0;1;0];%一般情况下是个垂直某个轴的平面
%一般只记录从负到正穿越。如果想反向也记录,可以设置Plane=-Plane。

%第二步,插值得到线与面的交点
yP_List=[];
tP_List=[];
Dis=DistancePlane(y,Plane);
N=size(y,2);
for k=1:N-1
    if Dis(k)<=0 && Dis(k+1)>0
        t0=t(k);t1=t(k+1);
        yP0=y(:,k);yP1=y(:,k+1);
        Dis0=Dis(k);Dis1=Dis(k+1);
        %一维线性插值,求Dis=0时的t和y
        %(相比较前面积分的4阶RK,这里用线性插值精度有点低)
        yP=yP0+(yP1-yP0)/(Dis1-Dis0)*(0-Dis0);
        tP=t0+(t1-t0)/(Dis1-Dis0)*(0-Dis0);
        %储存
        yP_List=[yP_List,yP];
        tP_List=[tP_List,tP];
    end
end
end

%点到平面的距离
function Dis=DistancePlane(xk,Plane)
% xk,坐标点,如果是3维坐标,大小就是3*N的矩阵。
% Plane,平面,形如Ax+By+Cz+D=0形式的平面。
N=size(xk,2);%计算总共多少个点
xk2=[xk;ones(1,N)];
Dis=dot(xk2,Plane*ones(1,N),1)./norm(Plane(1:end-1));
end

%两点线性插值
function y=interp2point_linear(x0,x1,y0,y1,x)
y=y0+(y1-y0)/(x1-x0)*(x-x0);
end

%两点3次插值
function y=interp2point_spline(x0,x1,y0,y1,x)
%y0包含y0的值和y0的导数,yy=y0(1),dy=y0(2)
xx0=x0;
xx1=x1;
yy0=y0(1);dy0=y0(2);
yy1=y1(1);dy1=y1(2);
cs = csape([xx0,xx1],[dy0,yy0,yy1,dy1],[1,1]);
y=ppval(cs,x);
end

function [F,Output]=Fdydx(x,y,Input)
%形式为Y'=F(x,Y)的方程,参见数值分析求解常系数微分方程相关知识
%高次用列向量表示,F=[dy(1);dy(2)];y(1)为函数,y(2)为函数导数
%Rossler 吸引子
a=Input(1);
b=Input(2);
c=Input(3);

dy(1)=-y(2)-y(3);
dy(2)=y(1)+a*y(2);
dy(3)=b+y(3)*(y(1)-c);

F=[dy(1);dy(2);dy(3)];
Output=[];
end

function [y,Output]=ODE_RK4_hyh(x,h,y0,Input)
%4阶RK方法
%h间隔为常数的算法
y=zeros(size(y0,1),size(x,2));
y(:,1)=y0;
for ii=1:length(x)-1
    yn=y(:,ii);
    xn=x(ii);
    [K1,~]=Fdydx(xn    ,yn       ,Input);
    [K2,~]=Fdydx(xn+h/2,yn+h/2*K1,Input);
    [K3,~]=Fdydx(xn+h/2,yn+h/2*K2,Input);
    [K4,~]=Fdydx(xn+h  ,yn+h*K3  ,Input);
    y(:,ii+1)=yn+h/6*(K1+2*K2+2*K3+K4);
end
Output=[];
end

The bifurcation diagram is drawn as follows:
Please add a picture description
The selection of the Poincaré section will cause the shape of the bifurcation diagram of the system to change. But the position of the bifurcation point will not be changed. Because the position of the bifurcation point is determined by the system itself.

4.3 Bifurcation diagram of Lorenz system

The Lorenz system is a nonlinear system discovered and proposed by the meteorologist Lorenz, and it is also the beginning of the discipline of chaos. When simulating atmospheric flow, Lorentz found that a small initial error can lead to huge changes in the system in the future. This idea dealt a heavy blow to those determinists in the physics community in the 1960s. Lorenz also summed up this uncertainty as the "butterfly effect".

This system can be written as:
x ˙ = a ( y − x ) y ˙ = rx − y − xzz ˙ = xy − bz \dot{x}=a(yx)\\ \dot{y}=rx-y -xz\\ \dot{z}=xy-bzx˙=to ( andx)y˙=rxyxzz˙=xyb z
general system a=10, b=8/3, change the value of r to observe the different appearance of the system. The following figures show the three-dimensional phase trajectory diagrams of the xy plane corresponding to different r values: the
Please add a picture description
bifurcation diagram is:
Please add a picture description
the drawing code is as follows:

%利用庞佳莱截面绘制分岔图
%截面采用公式Ax+By+Cz+D=0;的形式
%Lorenz方程
clear
clc
close all

h=2e-3;
x1=100;
x0=0:h:x1;
y0=[2;2;2];
%不同的c
c=1:1:500;
N_c=length(c);
N_P=300;%假设穿过截面的共有300个点
BF=nan(N_c,N_P);
for k=1:N_c
    c_k=c(k);disp(c_k)
    %计算出轨迹
    [y1,~]=ODE_RK4_hyh(0:10*h:x1,10*h,y0,[10,8/3,c_k]);%先粗略的计算前几步,然后排除初始点的影响,舍弃不要
    [y1,~]=ODE_RK4_hyh(x0+x1,h,y1(:,end),[10,8/3,c_k]);
    %计算Poincare平面
    Plane=[1;-1;0;0];%x-y=0平面(正方向)
    [tP_List,yP_List]=Solve_Poincare(x0,y1,Plane);%计算Poincare平面
    %对于Lorenz系统再加一条,如果系统稳定了,则将稳定点也记录在最终分岔图内:
    if isempty(tP_List) && sum(y1(1,end)-y1(2,end))<1e-2%如果最后x和y足够接近,则认为收敛了
        tP_List=x0(end-1:end);
        yP_List=y1(:,end-1:end);
    end
    %储存y值作为待会分岔图的点
    N_P_temp=size(tP_List,2);
    if N_P_temp>N_P
        BF(k,1:N_P)=yP_List(2,1:N_P);
    else
        BF(k,1:N_P_temp)=yP_List(2,1:N_P_temp);
    end
end

%绘制分岔图
figure()
hold on
for k=1:N_P
    c_k=c(k);
    plot(c_k*ones(1,N_P),BF(k,1:N_P),...
        'LineStyle','none','Marker','.','MarkerFaceColor','k','MarkerEdgeColor','k',...
        'MarkerSize',1)
end
hold off


function [tP_List,yP_List]=Solve_Poincare(t,y,Plane)
%截面方程z=0
% Plane=[0;0;1;0];%一般情况下是个垂直某个轴的平面
%一般只记录从负到正穿越。如果想反向也记录,可以设置Plane=-Plane。

%第二步,插值得到线与面的交点
yP_List=[];
tP_List=[];
Dis=DistancePlane(y,Plane);
N=size(y,2);
for k=1:N-1
    if Dis(k)<=0 && Dis(k+1)>0
        t0=t(k);t1=t(k+1);
        yP0=y(:,k);yP1=y(:,k+1);
        Dis0=Dis(k);Dis1=Dis(k+1);
        %一维线性插值,求Dis=0时的t和y
        %(相比较前面积分的4阶RK,这里用线性插值精度有点低)
        yP=yP0+(yP1-yP0)/(Dis1-Dis0)*(0-Dis0);
        tP=t0+(t1-t0)/(Dis1-Dis0)*(0-Dis0);
        %储存
        yP_List=[yP_List,yP];
        tP_List=[tP_List,tP];
    end
end
end


%点到平面的距离
function Dis=DistancePlane(xk,Plane)
% xk,坐标点,如果是3维坐标,大小就是3*N的矩阵。
% Plane,平面,形如Ax+By+Cz+D=0形式的平面。

N=size(xk,2);%计算总共多少个点
xk2=[xk;ones(1,N)];
Dis=dot(xk2,Plane*ones(1,N),1)./norm(Plane(1:end-1));
end

function [F,Output]=Fdydx(x,y,Input)
%形式为Y'=F(x,Y)的方程,参见数值分析求解常系数微分方程相关知识
%高次用列向量表示,F=[dy(1);dy(2)];y(1)为函数,y(2)为函数导数
%Lorenz 吸引子
a=Input(1);b=Input(2);r=Input(3);
dy(1)=a*(y(2)-y(1));
dy(2)=r*y(1)-y(2)-y(1)*y(3);
dy(3)=y(1)*y(2)-b*y(3);
F=[dy(1);dy(2);dy(3)];
Output=[];
end

function [y,Output]=ODE_RK4_hyh(x,h,y0,Input)
%4阶RK方法
%h间隔为常数的算法
y=zeros(size(y0,1),size(x,2));
y(:,1)=y0;
for ii=1:length(x)-1
    yn=y(:,ii);
    xn=x(ii);
    [K1,~]=Fdydx(xn    ,yn       ,Input);
    [K2,~]=Fdydx(xn+h/2,yn+h/2*K1,Input);
    [K3,~]=Fdydx(xn+h/2,yn+h/2*K2,Input);
    [K4,~]=Fdydx(xn+h  ,yn+h*K3  ,Input);
    y(:,ii+1)=yn+h/6*(K1+2*K2+2*K3+K4);
end
Output=[];
end

Guess you like

Origin blog.csdn.net/weixin_42943114/article/details/123462050