利用MATLAB绘制相轨迹图,辅助稳定性分析
close all;clc;clear;
figure(1);set(0,"defaultfigurecolor",'w')
% 相轨迹图
% x1(t)和x2(t)在扰动x(0)下随时间的相对变化
for theta=[0:20]*pi/10
%定义初始值(扰动)数组
x0=3*[cos(theta);sin(theta)];
% 求解的时间区间
t_spn=(0:0.1:8)';
option = odeset('RelTol',1e-8,'AbsTol',[1e-8;1e-8]);
% RelTol为相对精度,一维数据,AbsTol相对精度,要给符合状态变量的维数。
[t,x]=ode45(@func,t_spn,x0,option);
% x1(t),x2(t)在时间区间t_spn的变化量
plot(x(:,1),x(:,2),'linewidth',1.5);hold on
%增加轨迹方向箭头
quiver(x(:,1),x(:,2),gradient(x(:,1)),gradient(x(:,2)),'linewidth',1.0);hold on
end
xlabel("x1(t)");ylabel("x1(t)");title("phase portrait");
set(