如何绘制范德波尔振子的方向场?

How to draw the direction field of van der pol oscillator?

我正在尝试获取此 wiki 页面上显示的方向场和相图:

Van der Pol oscillator in wikipedia

我的代码:

options = odeset('MaxStep',0.5);
temp = inputdlg('Enter mu value');
mu = str2double(temp{1,1});
[t,y] = ode45(@(t,y) vdp1_1(t,y,mu),[0 10],[2; 0],options);
plot(y(:,1),y(:,2));
hold on
quiver(y(:,1), y(:,2), gradient(y(:,1)), gradient(y(:,2) ))
hold off

function dydt = vdp1_1(t,y,mu)
    dydt = zeros(2,1);
    dydt(1) = y(2);
    dydt(2) = [mu * (1-y(1)^2)*y(2)-y(1)];
end

当前输出:

期望的输出: 如 wiki 页面图

所示,如何在此之上获得方向场

谢谢,
戈皮

您需要计算要显示箭头的每个点的矢量场。然后你用 quiver 绘制它。例如。

[Xs,Ys]=meshgrid(-5:5,-5:5); % Will define the positions where we want to plot

Us=Ys; % From your equations, these are the values of the field at each point
Vs=mu*(1-Xs.^2).*Ys-Xs;

quiver(Xs,Ys,Us,Vs) % Should plot the field you want, just add the trajectory on top