Drawing phase plane diagram of a system of 3 coupled odes - MATLAB

9 views (last 30 days)
I have a system of 3 coupled odes and this is how I solve the system.
Tend = 100;
Nt = 100;
% Define RHS functions
RHS = @(t,x)RHS(t,x,param);
x0 = [0.004, 0.05, 0.1]; %Initial condition
t = linspace(0,Tend,Nt); %TSPAN
% Options with event function
[t, A] = ode45(RHS, t, x0);
I'd like to plot the phase plane diagram with the vector field for the solution of this model. I used quiver3 to create arrows for the system as follows:
N=20; %number of arrows along each dimension
%Next: Compute N evenly spaced points along each axis.
%Next: Make vectors of length N^3 that contain the x,y,z locations of all the arrows.
[X,Y,Z]=meshgrid(xvals,yvals,zvals); %creates NxNxN arrays
%Next: Make X,Y,Z row vectors, since quiver3() won't accept NxNxN array.
U=zeros(1,N^3); V=U; W=U; %pre-allocate arrays U,V,W
for i=1:N^3
%Next: Compute the direction components [U,V,W] for each arrow.
U(i)=deriv(1); V(i)=deriv(2); W(i)=deriv(3);
quiver3(X,Y,Z,U,V,W); %plot black arrows
This is the output of this code.
But I donot know how to plot the solution in this diagram as a surface or as trajectories to see the flow using arrows. Any help is much appreciated.

Accepted Answer

Sam Chak
Sam Chak on 21 Mar 2022
I think you should be able to plot the trajectory solution using plot3 after retaining the 3D diagram (quiver3):
hold on
plot3(A(:,1), A(:,2), A(:,3))
hold on
plot3(sol(:,1), sol(:,2), sol(:,3))
  1 Comment
UserCJ on 21 Mar 2022
Thanks @Sam Chak
I accidentally used "plot" instead of "plot3". Thanks for your suggestion.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by