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

雨燕双飞 提交于 2020-01-03 02:08:25

问题


I am trying to get the direction field and phase portrait shown on this wiki page:

Van der Pol oscillator in wikipedia

My code:

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

Current output:

Desired Output: How to get the direction field on top of this as shown in the wiki page figure

Thanks,
Gopi


回答1:


You need to calculate the vector field at every point you want an arrow to be shown. And then you plot this with quiver. For example.

[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


来源:https://stackoverflow.com/questions/42969046/how-to-draw-the-direction-field-of-van-der-pol-oscillator

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!