Not getting quiver to work on a 3 dimensional Non-linear system

2 次查看(过去 30 天)
Hi all, and thanks you in advance for any help. I will first post how my system looks, then I will post MWE of my Quiver/Phase plane script. My issue is that the direction arrows don't correlate with simulations. I simply can't find why. Could be a MATLAB or a mathematical misconception. The script is slightly ad-hoc and I apologies if it is hard to follow, though it is commented so that each step should be fairly obvious.
function dxdt = LSQodes(~,x,p)
%Setting variables
X = x(1);
Xm = x(2);
Xstar = x(3);
%setting parameters
k1 = p(1);
k2 = p(2);
alpha = p(3);
beta = p(4);
K = p(5);
B = 1;
R = 1;
%Creating the empty vector
dxdt=zeros(3,1);
%Adding the equations
dxdt(1)=beta*B*(Xstar/(K+Xstar))-alpha*R*(X/(K+X));
dxdt(2)=alpha*R*(X/(K+X))-k1*Xm+k2*Xstar;
dxdt(3)=-beta*B*(Xstar/(K+Xstar))+k1*Xm-k2*Xstar;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%NEW Script
function phase(p)%Takes a vector of 5 values
%Add empty figure
figure;
hold on;
%Vectors for different starting values
n=[0 10 20 30 40 60 80 100];
E=[100 80 60 40 30 20 10 0];
%Do as many simulations as starting values
i=length(n);
%Loop and plot simulations
while i>0,
[~,dX] = ode45(@(t,x) LSQodes(t,x,p),[0 200],[100, n(i), E(i)]);
plot(dX(:,2),dX(:,3),... %drawing x,y
'LineWidth',2);
plot(dX(1,2),dX(1,3),'bo',...% starting points
'MarkerSize',10);
plot(dX(end,2),dX(end,3),'ks',...% ending points
'MarkerSize',10);
i=i-1;
end;
%Creating even spaced matrixes with coordinates 0 to 50
x2 = linspace(0,100,15);
y2 = linspace(0,100,15);
[x3,y3] = meshgrid(x2,y2);
%Creating matrixes to hold the value of the derivative at t=0.
Xm = zeros(size(x3));
Xstar = zeros(size(x3));
%Adding the derivative of Xm and Xstar at t=0 (Yprime(1,2)&(1,3)) to the grid.
for Q = 1:numel(x3)
[~,dx] = ode45(@(t,x) LSQodes(t,x,[p 1 1]),[0 1],[100, x3(Q), y3(Q)]);
Xm(Q) = dx(1,2);
Xstar(Q) = dx(1,3);
end
%Scaling the size of the arrows in the phase field
for Z = 1:numel(x3)
Vmod = sqrt(Xm(Z)^2 + Xstar(Z)^2);
Xm(Z) = Xm(Z)/Vmod;
Xstar(Z) = Xstar(Z)/Vmod;
end
%Calling quiver to plot the arrows
quiver(x3,y3,Xm,Xstar);
xlabel('Xm');
ylabel('Xstar');
title('Phase field with simulations at different initial values');
axis tight equal;
grid;
hold off;
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Digital Filter Analysis 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by