如何绘制van der pol振子的方向场?

时间:2017-03-23 06:46:44

标签: matlab field ode

我正在尝试获取此维基页面上显示的方向字段和相位图像:

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

当前输出: Actual output

期望的输出: 如何在wiki页面图

中显示方向字段

Desired output

谢谢,
戈皮

1 个答案:

答案 0 :(得分:1)

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

[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