Matlab tool to plot 3d phase portrait

I have the following system of differential equations
x' = -alpha0 * x + beta0 * x * y;
y' = alpha1 * y - beta1 * x * y;
z' = -alpha2 * (z - 5.5)^3 - beta2 * x * y;
I wanted to take a look at the phase portrait of this system for various values of the coefficients. Is there an inbuilt matlab tool that can do that?

 Accepted Answer

If you want to use multiple slider widgets for alpha and beta to visualize the interactive 3D phase portrait, then you need to use the Graphical User Interface Design Environment or the App designer to create your desired graphical user interface (GUI).
help GUIDE
Graphical user interface design environment MATLAB Version 24.1 (R2024a) 19-Nov-2023 GUIDE functions. guide - Open the GUI Design Environment. Documentation for matlab/guide doc guide

More Answers (1)

Use odeset to set the OutputFcn option to @odephas3. See the ballode or orbitode example files for a demonstration of how to use the OutputFcn option, though I believe those use @odeplot and @odephas2 instead of @odephas3.

3 Comments

I am sorry but I don't understand, can you provide links to the tools that you are mentioning? I wanted to know if there is an interactive tool for it. I followed this example and wrote the code manually this way:
%% Phase plane
clc;clear all;
[x1,y1,z1] = meshgrid(0:0.2:2,0:0.2:2,0:0.2:2);
u = zeros(size(x1));
v = zeros(size(y1));
w = zeros(size(z1));
t=0;
for i = 1:numel(x1)
Yprime = rhs(t,[x1(i); y1(i); z1(i)]);
u(i) = Yprime(1);
v(i) = Yprime(2);
w(i) = Yprime(3);
end
quiver3(x1,y1,z1,u,v,w); figure(gcf)
function f = rhs(t,y)
alpha0 = 1;
beta0 = 1;
alpha1 = 1;
beta1 = 1;
alpha2 = 1;
beta2 = 1;
f = zeros(size(y));
f(1) = -alpha0*y(1) + beta0*y(1)*y(2);
f(2) = alpha1*y(2) - beta1*y(1)*y(2);
f(3) = -alpha2*(y(3) - 5.5)^3 - beta2*y(1)*y(2);
end
@Steven Lord suggested calling '@odephas3' to generate the 3D phase plot. Is this what you were looking for? The 'quiver3' function is used for plotting a 3D vector field, which can be challenging for humans to visualize when projected on a static 2D plane. However, on your MATLAB machine, you can manually rotate the view using your mouse.
initX = [0 0 0
0 0 1
1 0 0
1 0 1
1 1 0
1 1 1];
tspan = [0 10];
X0 = initX(3,:); % test different initial values
opts = odeset('OutputFcn', @odephas3); % <-- insert this
[t, X] = ode45(@ode, tspan, X0, opts);
%% Differential Equations
function dX = ode(t, X)
dX = zeros(3, 1);
x = X(1);
y = X(2);
z = X(3);
alpha0 = 1;
beta0 = 1;
alpha1 = 1;
beta1 = 1;
alpha2 = 1;
beta2 = 1;
dX(1) = -alpha0 * x + beta0 * x * y;
dX(2) = alpha1 * y - beta1 * x * y;
dX(3) = -alpha2 * (z - 5.5)^3 - beta2 * x * y;
end
I see. However, I just wanted to see how the solutions behave via the phase portrait, not plot the actual solutions by solving it using ode45. As far as plotting the solutions are concerned, I have separately used Euler's method to solve the ode, as one cannot specify a particular time step in ode45. I am just plotting that solution using plot3, but I will check this out too. My original doubt however, is whether there exists any interactive tool, a widget of sorts, through which we can change the coefficients and obtain various phase portraits.

Sign in to comment.

Categories

Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Products

Release

R2024a

Community Treasure Hunt

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

Start Hunting!