vinita
vinita

Reputation: 95

Vector field in matlab

I am trying to solve this particular problem in matlab

"Consider the system dr/dt = r*(l - r^2 ) + mu*r cos (theta)

d(theta)/dt = 1

When mu = o , there's a stable limit cycle at r =1 , Show that a closed orbit still exists for ,mu > 0, as long as mu is sufficiently small."

i am able to draw a close limit cycle, but unable to draw vector field for x vs y graph.

here is my code..

function file->
function dy = tst(t,y)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
dy = zeros(2,1);
dy(1) = y(1)*(1-y(1)*y(1))+1.5*y(1)*cos(y(2));
dy(2) = 1;
end

script file->

[t,r] = ode45(@tst,[0, 40],[1,0]);
x = r(:,1).*cos(r(:,2)); 
y = r(:,1).*sin(r(:,2));
figure(1)
plot(x,y);

hold on

[R,T] = meshgrid(r(:,1),r(:,2));

X = R.*cos(T);

Y = R.*sin(T);

quiver(R,T,X,Y);

I thing i am doing this in wrong way, what is the correct way to draw vector field?? the problem is in script file.

Upvotes: 3

Views: 981

Answers (1)

Rasman
Rasman

Reputation: 5359

the idea is to take the differential of the parameters:

quiver(x(1:end-1),y(1:end-1),diff(x)./diff(t),diff(y)./diff(t))

enter image description here

Upvotes: 1

Related Questions