Phase Portrait of ODE system
34 次查看(过去 30 天)
显示 更早的评论
I need to generat the phase portrait of the ode system given, where r,p,c and b are given constants
dv/dt=rv-pvx
dx/dt=cv-bx
Below matlab code is what I have gotten so far
However, how do I implement ode45 functione here?
I would like to use ode45 function, but was not sure how to do so.
If some one could guide me through how to use ode45 function to generate the phase portrait, it will be much appreciated.
% Part IIa. Base Case
% Phase Portrait
clc
clear
close all
%
%
r=2.5;
p=2;
c=0.1;
b=0.1;
%
[x,v]=meshgrid(0:1:5, 0:1:5);
dx=r.*v-p.*v.*x;
dv=c.*v-b.*x;
streamslice(x,v,dx,dv,'filled');
quiver(x,v,dx,dv);
0 个评论
回答(2 个)
Alan Stevens
2022-5-15
Do you mean something like this:
% Part IIa. Base Case
% Phase Portrait
%
%
r=2.5;
p=2;
c=0.1;
b=0.1;
%
% [x,v]=meshgrid(0:1:5, 0:1:5);
% dx=r.*v-p.*v.*x;
% dv=c.*v-b.*x;
% streamslice(x,v,dx,dv,'filled');
% quiver(x,v,dx,dv);
% Set time interval as you desire (arbitrary values used here)
tspan = [0 50];
% Set initial conditions as you desire (arbitrary values used here)
X0 = [0.2 0]; % [x0 v0]
[t, X] = ode45(@(t,X) rate(t,X,r,p,c,b),tspan,X0);
x = X(:,1); v = X(:,2);
plot(x,v),grid
xlabel('x'),ylabel('y')
function dXdt = rate(~,X,r,p,c,b)
x = X(1); v = X(2);
dXdt = [r*v-p*v*x;
c*v-b*x];
end
0 个评论
Steven Lord
2022-5-15
You could use ode45 with the 'OutputFcn' option set to @odephas2 using odeset, as shown in this Answers post.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!