Phase Portrait of ODE system
99 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Alan Stevens
on 15 May 2022
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 Comments
Steven Lord
on 15 May 2022
You could use ode45 with the 'OutputFcn' option set to @odephas2 using odeset, as shown in this Answers post.
0 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!