MATLAB common nonlinear visualization drawing method - phase diagram and phase space (two-dimensional linear phase diagram and nonlinear phase space)

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.

0 Preface

This article briefly introduces the commonly used non-linear visualization methods. Due to space constraints, it is decided to introduce two articles. The first article introduces the concepts of phase diagram and phase space. The second part introduces the drawing method of Poincaré section and bifurcation diagram. In the third article, I will not write about visualization. Let’s see if I want to write a time series analysis such as spectrum analysis, Lyapunov index analysis, and dimension analysis (digging holes, continue digging holes).

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.

The second blog link is as follows:
MATLAB common nonlinear visualization drawing method - bifurcation diagram and Poincaré section (chaos visualization, Poincare section, Logistic, Henon, Lorenz, Rossler, Duffing system) https://blog.csdn.net /weixin_42943114/article/details/123462050

There are four previous articles that introduced some interesting characteristics of nonlinearity. If you are interested, you can jump to view:
Use matlab for chaotic pendulum simulation (double pendulum, triple pendulum, multi-pendulum demonstration) https://blog.csdn.net/weixin_42943114 /article/details/121891553

Use matlab to realize the fractal pattern display of Newton iteration method in complex number domain space (newton method) https://blog.csdn.net/weixin_42943114/article/details/121905957

MATLAB implementation of Mandelbrot set Julia set fractal (fractal art) https://blog.csdn.net/weixin_42943114/article/details/122814900

Use matlab to realize the three-body problem (double star, three star, multi-star movement) https://blog.csdn.net/weixin_42943114/article/details/106616411

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].

1 Simple second-order differential equation

First of all what is non-linearity? That is, except for linear systems, they are all nonlinear systems. Therefore, if you want to understand the difference between nonlinear systems, you must first understand the characteristics of linear systems, and then you can compare and see the characteristics of nonlinear systems.

1.1 The simplest linear system

Let's take a bad street spring linear system as an example. The force of the spring is f=-k x, which is related to the displacement of the small square. The force of the damper is f=-c dx, where dx is the velocity of the small square.
Please add a picture description
At this time, the acceleration of the small square can be solved by the second law of cattle F=ma:
− kx − cx ˙ = mx ¨ -kx-c\dot{x}=m\ddot{x}kxcx˙=mx¨For
convenience hereafter, assume m=1.

Because it contains second-order derivatives, it is inconvenient to analyze. Therefore, in order to facilitate subsequent mathematical analysis, we organize the equations into the following form:

[ x x ˙ ] ′ = [ x ˙ − k x − c x ˙ ] = [ 0 1 − k − c ] ∗ [ x x ˙ ] \left[ \begin{array}{c} x\\ \dot{x}\\ \end{array} \right] ^{'} = \left[ \begin{array}{c} \dot{x} \\ -kx -c\dot{x} \\ \end{array} \right] = \left[ \begin{array}{c} 0 & 1 \\ -k & -c \\ \end{array} \right] * \left[ \begin{array}{c} x \\ \dot{x} \\ \end{array} \right] [xx˙]=[x˙kxcx˙]=[0k1c][xx˙]

Here there are 2 column vector elements, so it is called a 2nd order differential equation. We call this kind of differential equation that can be organized into the form of x'=Ax as a linear equation, where A is a constant matrix. All the information of the differential equation is contained in the matrix A, so we establish the relationship between the differential equation and linear algebra. The specific relationship is introduced in the second chapter phase diagram.

1.2 Simple nonlinear system

For the above equation, if it is slightly modified, the damper is replaced by air damping, that is, f=-c*dx^2, which is related to the square of the speed. Then the equation can be rewritten as:
[ xx ˙ ] ′ = [ x ˙ − kx − cx ˙ 2 ] \left[ \begin{array}{c} x\\ \dot{x}\\ \end{array} \ right] ^{'} = \left[ \begin{array}{c} \dot{x} \\ -kx -c\dot{x}^2 \\ \end{array} \right][xx˙]=[x˙kxcx˙2]
At this time, the equation cannot be written in the form of x'=Ax, so this equation is nonlinear. At this time, the analysis methods of linear systems will all fail.

You can see how valuable and special forms linear systems are.

1.3 Simple time-varying systems

In Section 1.1 just now, the matrix A is a constant matrix, which represents the motion characteristics of today's mass block, which is the same as that of tomorrow's mass block, and will not change due to time. In this case, we call the system a time-invariant system, that is, a system that does not change with time.

If the spring will rust gradually, the value of k will change with time, we call this system a time-varying system. Measuring the motion properties of a mass today will be somewhat different than measuring the properties the next day. But if the time is relatively short, that is, every instant, the system is still linear.

If a nonlinear external disturbance force f(t) is added, the system will completely enter a nonlinear time-varying system. (Here, thanks to @weixin_43957890 for the modification in the comment area) Its form is:
[ xx ˙ ] ′ = [ x ˙ − kx − cx ˙ − f ( t ) ] \left[ \begin{array}{c} x\ \ \dot{x}\\ \end{array} \right] ^{'} = \left[ \begin{array}{c} \dot{x} \\ -kx -c\dot{x}-f (t) \\ \end{array} \right][xx˙]=[x˙kxcx˙f(t)]
or can also be written as:
[ xx ˙ f ] ′ = [ x ˙ − kx − cx ˙ − ff ′ ( t ) ] \left[ \begin{array}{c} x\\ \dot{x}\\ f \\ \end{array} \right] ^{'} = \left[ \begin{array}{c} \dot{x} \\ -kx -c\dot{x}-f \\ f'(t )\\ \end{array} \right]xx˙f=x˙kxcx˙ff(t)

2 Phase diagram of linear system

First of all, let's go back to the following spring model of x'=Ax:
[ xx ˙ ] ′ = [ 0 1 − k − c ] ∗ [ xx ˙ ] \left[ \begin{array}{c} x\\ \dot{x}\\ \end{array} \right] ^{'} = \left[ \begin{array}{c} 0 & 1 \\ -k & -c \\ \end{array} \right ] * \left[ \begin{array}{c} x \\ \dot{x} \\ \end{array} \right][xx˙]=[0k1c][xx˙]

2.1 Introduction of phase diagram

We take k=0.925, c=0.3, substitute them into the above phenomenon equation, and take different initial x, we can get the following sets of solutions: the matrix A represented by the linear system
Please add a picture description
is:
[ 0 1 − 0.925 − 0.3 ] \left[ \begin{array}{c} 0 & 1 \\ -0.925 & -0.3 \\ \end{array} \right][00.92510.3]
The characteristic root of matrix A is λ1=-0.15+0.95i, λ2=-0.15-0.95i. The real parts of the eigenvalues ​​are all negative, indicating that the system is convergent. The imaginary part of the eigenvalue is not zero, and there is an oscillation phenomenon.

If we don't care what time is the peak and what time is the trough, but we care more about whether the system converges and whether the system is oscillating, then there is another way to study the system, that is the phase diagram.

The phase diagram or phase space (phase space) actually has a very mysterious name, but it is actually very simple, which is to draw the relationship between variables and variable derivatives. For example, we usually draw the displacement time xt diagram, but the phase diagram here needs to draw the displacement velocity xv diagram.

The above curves are drawn in the form of a phase diagram, as follows:
Please add a picture description
It can be seen that the three curves converge to the point (0,0), which means that the three cases will eventually converge, and the speed and displacement are both 0 when they converge. If you keep going around in circles, it proves that all three situations are oscillating. We call this line drawn in phase space a trajectory.

These three curves are so consistent in shape, as if there is a force field behind them restricting the movement of the curves. Then how to deduce the field behind it? We have to go back to the original equation.
After drawing the point [x1, dx1] at a certain time t1, the point [x2, dx2] at the next time t2. According to the flow field theory, the velocity of this point is:
[ x 2 dx 2 ] − [ x 1 dx 1 ] t 2 − t 1 = [ xdx ] ′ \frac{[\begin{array}{c}x2\\ dx2\end{array}]-[\begin{array}{c}x1\\dx1\end{array}]}{t2-t1}= [\begin{array}{c}x\\dx\end{ array}]^{'}t2 _t 1[x2 _dx2][x 1dx1]=[xdx]
Therefore, we can obtain the velocity corresponding to each point to construct the velocity field. When the equation of the system is known, this velocity field is very easy to construct, which is the derivative of the variable. Therefore, this field is also a form of expression of the phase diagram.
Please add a picture description
Because the trajectory is equivalent to a streamline in the entire flow field, knowing the phase space also knows the behavior of each trajectory in the phase space. In other words, the characteristics of the system motion on the time-domain diagram can be inversely deduced.
Since trajectories are constrained by fields, some conclusions of field theory can also be directly applied to trajectories. For example, trajectories will never cross, and will not disappear out of thin air. The start and end points of the trajectory are only possible: drawing boundaries and sources (divergence points), sinks (attraction points) (or saddle points, etc.). This specific behavior will be slowly covered in later chapters.

code show as below:

clear
clc
close all
%线性系统,用来展示相空间的用途
%小阻尼震荡(负实,共轭虚部)
A=[0,1;
    -0.925,-0.3];
%大阻尼震荡(负实,无虚部)
% A=[0,1;
%     -0.96,-2];
%只有阻尼(一个为0一个为负)
% A=[0,1;
%     0,-2];
%只有弹簧(实部都为0)
% A=[0,1;
%     -1,0];
%鞍点
% A=[0.15,0;
%     0,-0.15];

[y,dy,u,v]=PhaseSpace_Linear(-5:0.05:5,-4:0.05:4,A);%构建线性系统相空间的流场

h=1e-2;
x0=0:h:20;
N=length(x0);
%相同的微分方程,不同的初始状态
[y1,~]=ODE_RK4_hyh(x0,h,[4;-2],A);%计算微分方程,这里也可以用ode45
[y2,~]=ODE_RK4_hyh(x0,h,[0;-4]+[0.5;0],A);
[y3,~]=ODE_RK4_hyh(x0,h,[-3;3]+[1;0],A);
%绘制时域图
figure()
hold on
plot(x0,y1(1,:),'color',[1,0,0])
plot(x0,y2(1,:),'color',[0,1,0])
plot(x0,y3(1,:),'color',[0,0,1])
%绘制箭头
xy_lim=axis;
xy_ratio=get(gca, 'DataAspectRatio');xy_ratio=xy_ratio(1:2);
N_Arrow=5;
for k=1:N_Arrow
    N_k=round(N/N_Arrow*(k-0.83));
    plot_arrow( xy_lim,xy_ratio,[x0(N_k),y1(1,N_k)]...
        ,[1,0,0],1, [x0(N_k)-x0(N_k-10),y1(1,N_k)-y1(1,N_k-10)] )
   plot_arrow( xy_lim,xy_ratio,[x0(N_k),y2(1,N_k)]...
        ,[0,1,0],1, [x0(N_k)-x0(N_k-10),y2(1,N_k)-y2(1,N_k-10)] )
    plot_arrow( xy_lim,xy_ratio,[x0(N_k),y3(1,N_k)]...
        ,[0,0,1],1, [x0(N_k)-x0(N_k-10),y3(1,N_k)-y3(1,N_k-10)] )
end
hold off
legend("条件1","条件2","条件3")
box on
xlabel('t');ylabel('x');
%绘制相图
figure()
hold on
plot(y1(1,:),y1(2,:),'color',[0.8,0,0],'linewidth',1);%位移和速度曲线
plot(y2(1,:),y2(2,:),'color',[0,0.8,0],'linewidth',1)
plot(y3(1,:),y3(2,:),'color',[0,0,0.8],'linewidth',1)
xlim([-5,5]);ylim([-4,4])
%绘制箭头
xy_lim=axis;
xy_ratio=get(gca, 'DataAspectRatio');xy_ratio=xy_ratio(1:2);
N_Arrow=3;
for k=1:N_Arrow
    N_k=round(N/N_Arrow*(k-0.9));
    plot_arrow( xy_lim,xy_ratio,[y1(1,N_k),y1(2,N_k)]...
        ,[0.8,0,0],2, [y1(1,N_k)-y1(1,N_k-10),y1(2,N_k)-y1(2,N_k-10)] )
    plot_arrow( xy_lim,xy_ratio,[y2(1,N_k),y2(2,N_k)]...
        ,[0,0.8,0],2, [y2(1,N_k)-y2(1,N_k-10),y2(2,N_k)-y2(2,N_k-10)] )
    plot_arrow( xy_lim,xy_ratio,[y3(1,N_k),y3(2,N_k)]...
        ,[0,0,0.8],2, [y3(1,N_k)-y3(1,N_k-10),y3(2,N_k)-y3(2,N_k-10)] )
end
hold off
xlim([-5,5]);ylim([-4,4])
box on
xlabel('x');ylabel('dx');

% figure()
hold on
h=streamslice(y,dy,u,v);%叠加上之前求解出的流场效果
xlim([-5,5]);ylim([-4,4])
box on
xlabel('x');ylabel('dx');

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

function [y,dy,u,v]=PhaseSpace_Linear(y1,y2,A)
[y,dy]=meshgrid(y1,y2);%初始化网格
u=zeros(size(y));v=u;
for k=1:numel(y)
    %计算网格上每一个点的上的方向
    F=Fdydx(0,[y(k);dy(k)],A);
    u(k)=F(1);
    v(k)=F(2);
end
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

function plot_arrow(xy_lim,xy_ratio,xy_arrow,arrow_color,arrow_width,arrow_direction)
%初始化箭头形状(归一化的形状)
arrow_0=[0,0;-1,0.5;-1,-0.5];
%对方向进行归一化
a_dn=arrow_direction(:)./xy_ratio(:);
a_dn=a_dn/sqrt(sum(a_dn.^2));
d=(xy_lim(4)-xy_lim(3)+xy_lim(2)-xy_lim(1))/2;
%箭头对窗口缩放
arrow_1=arrow_0*arrow_width*0.03*d;
%箭头旋转
arrow_2=arrow_1*[a_dn(1),a_dn(2);-a_dn(2),a_dn(1)];
%箭头变形
xy_ratio_n=xy_ratio/sqrt(sum(xy_ratio.^2));%对比例尺归一化
arrow_3=arrow_2.*xy_ratio_n+xy_arrow;
fill(arrow_3(:,1),arrow_3(:,2),arrow_color,'EdgeColor','none')
end

2.2 Qualitative analysis of linear system

The drawing method of phase space is introduced, so what kind of results will appear if different matrix A is changed?
In fact, this is mainly related to the characteristic root of matrix A. For a second-order system, when the characteristic root is found, its system characteristics are found.

The figure below simply draws the phase diagram and time domain diagram of a common second-order system. The drawing code is still the code in the previous section, just change the matrix A.
Please add a picture description
The examples I give here are basically examples of convergence. When the real part of the characteristic root of the matrix is ​​a positive number, it will diverge. This is easy to change, so I won't demonstrate it.
Let's explain it roughly in order:

1 Oscillation convergence
As mentioned before, the characteristic root is negative and there is an imaginary part. Common in underdamped systems.
We regard the central point on the phase diagram at this time as the spiral point .

2 Non-oscillating convergence
The feature is that the characteristic root is negative, but there is no imaginary part. Therefore, the convergence process will not have an oscillatory linearity. Common in overdamped systems.
We regard the center point on the phase diagram at this time as a node .

3 The convergence of the uncertain convergence point
is characterized by the characteristic root one being 0. Take the figure as an example, there is no spring in the quality block, it just slides freely on the rough ground. If the initial speed and position are uncertain, the weight block will not stop at a fixed position. But we can know that when it converges, the speed must be equal to 0.
Of course, this straight line is not necessarily horizontal, but the example I gave is rather special.

4 Undamped oscillation
Characterized by the fact that the real parts of all roots are 0. In this way, there is no convergence or divergence in the system, only the oscillation represented by the imaginary part.

5 Saddle points
are characterized by characteristic roots, one is positive and the other is negative. The performance is that the trajectory is attracted to the point first, and then moves away from the point. In fact, in physics, a mountain with a saddle surface can be used as a metaphor. A small ball rolls down from the top of the mountain, reaches the valley, and then falls from the valley to a lower layer.
Therefore, although the saddle point is usually a special solution of the equation, it is difficult to measure it in reality due to its instability.
Just like the highest point of a simple pendulum, it is theoretically a static equilibrium point, but if you do dynamic analysis, you will find it is an unstable saddle point. Therefore, when the speed is high, the simple pendulum always tends to move toward the highest point, but when it reaches the highest point, it will leave due to its instability. Unlike the lowest point, it is a convergent and stable node, and it is the final destination of the pendulum.

3 Phase diagram of nonlinear system

After talking about the phase diagram of the linear system, we also give a general situation of the phase diagram of the nonlinear system.
Here is an example of "Nonlinear System" [see Reference 3].
x 1 ˙ = 0.5 ( − h ( x 1 ) + x 2 ) x 2 ˙ = 0.2 ( − x 1 − 1.5 x 2 + 1.2 ) h ( x ) = 83.72 x 5 − 226.31 x 4 + 229.62 x 3 − 103.79 x 2 + 17.76 x \dot{x_1}=0.5(-h(x_1)+x_2)\\ \dot{x_2}=0.2(-x_1-1.5x_2+1.2)\\ h(x)=83.72x^5 -226.31x^4+229.62x^3-103.79x^2+17.76xx1˙=0.5(h(x1)+x2)x2˙=0.2(x11 . 5 x2+1.2)h(x)=83.72x5226.31x4+229.62x31 0 3 . 7 9 x2+1 7 . 7 6 x
This equation is a nonlinear equation, and the derivatives of x1 and x2 at each point can also be solved in the same way, and then the phase diagram can be drawn.
Please add a picture description
Since nonlinear systems can be locally linearized near any root, the knowledge of linear systems involved in Chapter 2 can still be used in nonlinear systems.

For example, in the picture above, you can still see three special points, two stable nodes and a saddle point.
Please add a picture description
The drawing code is as follows:

[y,dy]=meshgrid(-0.5:0.02:1.5,-0.5:0.02:1.5);%初始化网格
u=zeros(size(y));v=u;
for k=1:numel(y)
    %计算网格上每一个点的上的方向
    F=Fdydx(0,[y(k);dy(k)],1);
    u(k)=F(1);
    v(k)=F(2);
end
figure()
streamslice(y,dy,u,v,4)
xlabel('y')
ylabel('dy')
box on


function [F,Output]=Fdydx(x,y,Input)
%形式为Y'=F(x,Y)的方程,参见数值分析求解常系数微分方程相关知识
%高次用列向量表示,F=[dy(1);dy(2)];y(1)为函数,y(2)为函数导数
switch Input
    %示例1
    case 1
        p=[83.72,-226.31,229.62,-103.79,17.76,0];
        dy(1)=0.5*(-polyval(p,y(1))+y(2));
        dy(2)=0.2*(-y(1)-1.5*y(2)+1.2);
        F=[dy(1);dy(2)];
    %示例2
    case 2
        dy(1)=y(2);
        dy(2)=-y(1)+0.3*(1-y(1)^2)*y(2);%0.3
        F=[dy(1);dy(2)];
end
Output=[];
end

4 Three-dimensional system phase space

High-dimensional systems are usually also represented by two-dimensional phase planes. Two examples are given below to illustrate. (This chapter only demonstrates higher-dimensional phase spaces and trajectories, and does not involve new visualizations)

4.1 Linear third-order systems

For a higher-order linear system, a single two-dimensional phase plane cannot be accurately described, and a higher-dimensional vector field is required to describe it. That is, a high-dimensional phase space.
For example, the following three-dimensional phase space is shown in the figure:
Please add a picture description
it is not convenient to observe the characteristics of the system.
So usually, even for high-dimensional systems, only the 2-dimensional phase plane is drawn, and then the system characteristics are observed on the 2-dimensional phase plane.

The simple code for the above drawing is as follows

clear
clc
close all
D=[-1+1i,0,0;0,-1-1i,0;0,0,-1];
V=[[0.5;-0.2+0.5i;0.3],[0.5;-0.2-0.5i;0.3],[0.2;0.3;0.4]];
A= V*D*inv(V);
A=real(A);%构建一个3维线性系统
[x1,x2,x3]=meshgrid(-1.5:0.05:1.5,-1.5:0.05:1.5,-1.5:0.05:1.5);%初始化网格
u=zeros(size(x1));v=u;w=u;%开始计算相空间
for k=1:numel(x1)
    %计算网格上每一个点的上的方向
    F=Fdydx(0,[x1(k);x2(k);x3(k)],A);
    u(k)=F(1);
    v(k)=F(2);
    w(k)=F(3);
end
hcone = coneplot(x1,x2,x3,u,v,w,...
    x1(1:9:end,1:9:end,1:9:end),x2(1:9:end,1:9:end,1:9:end),x3(1:9:end,1:9:end,1:9:end),8);
hcone.FaceColor = 'red';
hcone.EdgeColor = 'none';
camlight right
lighting gouraud
% set(hsurfaces,'AmbientStrength',0.6)
hcone.DiffuseStrength = 0.8;
view(3)
axis equal vis3d

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

4.2 Higher-order time-varying systems

The following introduces the equation of a time-varying system, which is still the spring model mentioned at the beginning, but with a periodic force added.
[ xx ˙ ] ′ = [ x ˙ − kx − cx ˙ − sin ⁡ ( 2 t ) ] \left[ \begin{array}{c} x\\ \dot{x}\\ \end{array} \right ] ^{'} = \left[ \begin{array}{c} \dot{x} \\ -kx -c\dot{x}-\sin(2t) \\ \end{array} \right][xx˙]=[x˙kxcx˙sin ( 2 t )]
Because it is a time-varying system, it is impossible to draw the phase plane diagram of the field form, but only the phase diagram of the trajectory form. Please add a picture description
It can be seen that the trajectories cross, which is typical of higher order systems.

But this intersection of trajectories can be interpreted as non-intersecting trajectories in some high-dimensional phase space, projected onto a two-dimensional plane. For example, the above equation can be rewritten as:
[ xx ˙ f ] ′ = [ x ˙ − kx − cx ˙ − f 2 cos ⁡ ( 2 t ) ] \left[ \begin{array}{c} x\\ \dot{ x}\\ f\\ \end{array} \right] ^{'} = \left[ \begin{array}{c} \dot{x} \\ -kx -c\dot{x}-f \ \ 2\cos(2t)\\ \end{array} \right]xx˙f=x˙kxcx˙f2cos ( 2 t )
At this time, the phase space becomes:
Please add a picture description
So the two-dimensional phase diagram above is equivalent to the projection of the three-dimensional phase diagram in the x3 direction, onto the x1x2 plane.

clear
clc
close all
%演示1
h=2e-2;
x0=0:h:40;
N=length(x0);
[y1,~]=ODE_RK4_hyh(x0,h,[0.5;0.5],1);
figure()
plot(x0,y1(1,:),'color',[1,0,0])
figure()
plot(y1(1,:),y1(2,:),'color',[1,0,0])
%演示2
[y2,~]=ODE_RK4_hyh(x0,h,[0.5;0.5;0],2);
figure()
plot(x0,y2(1,:),'color',[1,0,0])
figure()%三维立体
plot3(y2(1,:),y2(2,:),y2(3,:),'color',[0,0,0])
xlabel('x1');ylabel('x2');zlabel('x3');
hold on
box on
plot3(y2(1,:),y2(2,:),y2(3,:)*0-1,'color',[1,0,0])
%引入理论结果:
x=x0;
y_theory=5/78*cos(2*x)+25/78*sin(2*x)+...
    exp(-0.15*x).*(6647/15249*cos(sqrt(391)/20*x)-59*sqrt(391)/15249*sin(sqrt(391)/20*x));
figure()
plot(x0,y1(1,:),x,y_theory);legend('数值计算','理论解')

%后置函数
function [F,Output]=Fdydx(x,y,Input)
%形式为Y'=F(x,Y)的方程,参见数值分析求解常系数微分方程相关知识
%高次用列向量表示,F=[dy(1);dy(2)];y(1)为函数,y(2)为函数导数
if Input==1
dy1=y(2);
dy2=-y(1)-0.3*y(2)-sin(2*x);
F=[dy1;dy2];
elseif Input==2
dy1=y(2);
dy2=-y(1)-0.3*y(2)-y(3);
dy3=2*cos(2*x);
F=[dy1;dy2;dy3];
end
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

But note that this intersection of trajectories does not imply nonlinearity, in fact, the above system can be considered linear. This is a typical forced vibration with damping and gives the corresponding solution:
y ( t ) = 5 78 ( 5 sin ⁡ ( 2 t ) + cos ⁡ ( 2 t ) ) + e − 3 t 20 6647 cos ⁡ ( 391 t 20 ) − 59 391 sin ⁡ ( 391 t 20 ) 15249 y(t)=\frac{5}{78} (5 \sin (2t)+\cos (2t))\\ +e^ {-\frac{3t}{20}}\frac{ 6647 \cos \left(\frac{\sqrt{391} t}{20}\right)-59 \sqrt{391} \sin \left(\frac {\sqrt{391} t}{20}\right) }{15249}y(t)=785(5sin ( 2t ) _+cos ( 2t ) ) _+e203 t152496647cos(20391 t)59391 sin(20391 t)
The corresponding derivatives and trajectory equations can also be calculated using formulas (I use Mathematica).

5 Characteristics of nonlinear phase diagram

The following features appear only in nonlinear phase diagrams.

5.1 Multiple Balance Points

One was introduced earlier in Chapter 3. Here is another simple pendulum equation:
θ ¨ + sin ⁡ θ = 0 \ddot{\theta}+\sin{\theta}=0i¨+sini=0
Draw the phase diagram as:
Please add a picture description
You can see that this phase diagram consists of many concentric circles and saddle points.

3Blue1Brown has made a very beautiful visualization before to explain the connection between this phase diagram and differential equations. If you are interested, you can take a look:
https://www.bilibili.com/video/BV1tb411G72z

5.2 Limit cycle

The limit cycle will only appear in a two-dimensional nonlinear system. It is shown in the phase diagram that its convergence position is not a certain point, but a ring.
Give an example of the Van der Pol equation:
[ xx ˙ ] ′ = [ x ˙ − x − ϵ ( 1 − x 2 ) x ˙ ] \left[ \begin{array}{c} x\\ \dot{x} \\ \end{array} \right] ^{'} = \left[ \begin{array}{c} \dot{x} \\ -x -\epsilon(1-x^2)\dot{x} \\ \end{array} \right][xx˙]=[x˙xϵ ( 1x2)x˙]
ϵ= 0.3 \epsilon=0.3ϵ=When 0 . 3 , a limit cycle will appear on the phase diagram:
Please add a picture description
there is only one equilibrium point in the whole space, which is the divergent spiral point inside the limit cycle. In order to intuitively understand the characteristics of the limit cycle, different initial conditions are selected, and the equation is solved in the time domain, and the following results are obtained: at
Please add a picture description
points outside the limit cycle, a convergent waveform is initially shown, but then the amplitude remains constant. At points inside the limit cycle, the waveform initially exhibits divergence, but then the amplitude also remains stable. Both of them are attracted by the limit circle in space, and they are in the circle movement that goes round and round.

Please add a picture description
If some coefficients in the equation change (for example, ε in the above equation changes from negative to positive), it will cause the entire phase space to change. This change will change the nature of the equilibrium point, leading to changes in the properties of the entire system, and we call the system bifurcated at this position. For example, the ε of the Van der Pol equation changes from negative to positive, and the equilibrium point changes from stable to divergent, resulting in a stable position in space changing from a point to a moving limit cycle.

The drawing codes for the pendulum equation and the Van der Pol equation are as follows:

clear
clc
close all
%1单摆模型
[x1,x2]=meshgrid(-6:0.05:6,-2:0.05:2);%初始化网格
u=zeros(size(x1));v=u;w=u;
for k=1:numel(x1)
    %计算网格上每一个点的上的方向
    F=Fdydx(0,[x1(k);x2(k)],1);
    u(k)=F(1);
    v(k)=F(2);
end
figure()
h=streamslice(x1,x2,u,v);
ylim([-2,2]);
%2极限环
[x1,x2]=meshgrid(-4:0.02:4,-4:0.02:4);%初始化网格
u=zeros(size(x1));v=u;w=u;
for k=1:numel(x1)
    %计算网格上每一个点的上的方向
    F=Fdydx(0,[x1(k);x2(k)],2);
    u(k)=F(1);
    v(k)=F(2);
end
figure()
h=streamslice(x1,x2,u,v);
ylim([-4,4]);

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

5.3 Chaos

The chaotic phenomenon is manifested in the two-dimensional phase diagram, which looks like a mess and lacks regularity. Because it involves the intersection of trajectories, the necessary dimension must be greater than 2 dimensions. Therefore, the chaotic phenomenon must be produced in the three-dimensional or higher dimension.

To analyze chaos and bifurcation, you need to use Poincarai section and bifurcation diagram, which will be discussed in the next article.

5.4 Others

If the vibration data measured by the test is analyzed with a phase diagram, the vibration characteristics can be seen more intuitively.
Please add a picture description

If the vibration phase diagram is close to a circle or an ellipse, such as the first diagram, it proves that the system has good linear characteristics, and it can be considered to simplify the system from the perspective of linear equations.
If the vibration phase diagram is a non-circular figure, such as the second figure, its nonlinearity needs to be considered. If the vibration can be maintained at a relatively stable amplitude and frequency even if it is disturbed, the system model can be established from a two-dimensional limit cycle.
If the vibration trajectory crosses, such as the third figure, it can be analyzed from the perspectives of high-dimensional equations and period-doubling bifurcations.
If the vibration appears chaotic and has some regularity, it can be analyzed from the perspective of chaos.

Since the phase diagram involves deriving the signal to obtain dy, if the noise of the system is too large, the effect of the phase diagram will be relatively poor. Because the derivation value of high-frequency noise is greater than the value of derivation of low-frequency signal (sin(5x) derivation is 5cos(5x), which is 5 times of sin(x)). Therefore, when encountering a system with large noise, it is recommended to perform filtering first, and then draw the phase diagram.

For example, the figure below is the same signal, the upper part is the original signal with noise, and the lower part is the filtered signal. It can be seen that without filtering, even small noises can seriously disturb the shape of the phase diagram.
Please add a picture description
The code for the demonstration above is as follows:

clear
clc
close all
[t,y]=ode45(@Fdydx,0:0.01:20,[2;0]);
%模拟加噪声的信号
y1=y(:,1)+0.02*randn(size(y(:,1)));

%1直接求导,绘制相图
dy1=diffhyh(y1,1)/(t(2)-t(1));
figure()
plot(y1,dy1)
ylim([-6,6])
figure()
plot(t,y1)
%2滤波后求导,绘制相图
[b,a]=butter(6,0.04*2,'low');
y2=filtfilt(b,a,y1);
dy2=diffhyh(y2,1)/(t(2)-t(1));
figure()
plot(y2,dy2)
ylim([-6,6])
figure()
plot(t,y2)
function [F]=Fdydx(x,y)
%形式为Y'=F(x,Y)的方程,参见数值分析求解常系数微分方程相关知识
%高次用列向量表示,F=[dy(1);dy(2)];y(1)为函数,y(2)为函数导数
dy1=y(2)+0.01*randn();
dy2=-y(1)+0.9*(1-y(1)^2)*y(2)+0.01*randn()+0.01*sin(4*x);%这里直接在系统中加噪声
F=[dy1;dy2];
end
function Fdiff=diffhyh(F,dim)
%采用2阶中心差分,边缘采用一阶向前或向后差分(边缘没有搞迎风差分,精度要求不高)
%dim,差分的维度方向,dim=1对应着矩阵向下方向的差分,dim=2对应的向右
diffF1=diff(F,1,dim);
if dim==1%向下
    Fdiff=([zeros(1,size(F,2));diffF1]+[diffF1;zeros(1,size(F,2))])/2;
    Fdiff(1,:)=diffF1(1,:);
    Fdiff(end,:)=diffF1(end,:);
elseif dim==2%向右
    Fdiff=([zeros(size(F,1),1),diffF1]+[diffF1,zeros(size(F,1),1)])/2;
    Fdiff(:,1)=diffF1(:,1);
    Fdiff(:,end)=diffF1(:,end);
end
end

Some commonly used simple filtering methods can be found in this blog:
Several common signal smoothing and denoising methods https://blog.csdn.net/weixin_42943114/article/details/107693068

6 Representation of simple discrete iterative systems

In addition to the nonlinear linearity of the above differential equations, some discrete systems also appear nonlinear.
For example
[ xn + 1 yn + 1 ] = [ sin ⁡ ( 1 ∗ xn + 1 ) + cos ⁡ ( 2 ∗ yn + 1 ) sin ⁡ ( 2 ∗ xn + 1 ) − cos ⁡ ( 1 ∗ yn + 1 ) ] \left[ \begin{array}{c} x_{n+1}\\ y_{n+1}\\ \end{array} \right] = \left[ \begin{array}{c} \sin( 1*x_{n+1})+\cos(2*y_{n+1}) \\ \sin(2*x_{n+1})-\cos(1*y_{n+1}) \ \ \end{array} \right][xn+1yn+1]=[sin(1xn+1)+cos(2yn+1)sin(2xn+1)cos(1yn+1)]
After many iterations, the following image can be obtained:
Please add a picture description
the chaotic and disordered but faintly regular features are exactly the phenomenon of chaos.

In the next chapter, we will start with the bifurcation and chaos of discrete systems, and introduce the concept of bifurcation graphs. Due to space limitations, related content will be opened in another article, so stay tuned.

The drawing code for the above figure:

y0=[0.5;0.5];
N=1e6;
y=zeros(size(y0,1),N);
y(:,1)=y0;
for k=1:N-1
    yk1=y(:,k);
    yk2=[sin(1*yk1(1))+cos(2*yk1(2));
        sin(2*yk1(1))-cos(1*yk1(2))];
    y(:,k+1)=yk2;
end
scatter(y(1,:),y(2,:),3,'Marker','.','MarkerEdgeColor','k','MarkerEdgeAlpha',0.1)

Guess you like

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