How to draw a polar coordinate ODE system's phase portrait and trajectory?

19 visualizaciones (últimos 30 días)
Zixuan
Zixuan el 5 de Oct. de 2022
Comentada: Sam Chak el 13 de Sept. de 2023
For a linear system dotx=Ax ,with complex eigenvalues.
If it's written in polar coordinate,then it will be : dot r= \alpha *r ; dot \theta = \beta,
The initial condition will be like : r(t)=r_0 * exp ( \alpha * t) ; \theta(t)=\theta_0+\beta*t
How to draw it's phase portrait and trajectory? For there are 4 unknown segments in the system.
I tried to use quiver function to solve, but not successful.
Wish to receive a proper code and explainnation about it. Thanks everyone

Respuestas (1)

Yash Sharma
Yash Sharma el 13 de Sept. de 2023
Hi Zixuan,
I understand that you want to plot phase portrait and trajectory of a linear system of equations with complex eigen values
Here is an example code on how you can achieve the same.
% Define the parameters of the system
alpha = 0.5; % Parameter for r dynamics
beta = 0.1; % Parameter for theta dynamics
% Define the time span for simulation
tspan = 0:0.1:10;
% Define the initial conditions
r0 = 1; % Initial r value
theta0 = 0; % Initial theta value
% Define the ODE system in polar coordinates
odefun = @(t, y) [alpha * y(1); beta];
% Solve the ODE system
[t, y] = ode45(odefun, tspan, [r0; theta0]);
% Extract the r and theta values
r = y(:, 1);
theta = y(:, 2);
% Convert theta to radians
theta_rad = deg2rad(theta);
% Compute the x and y coordinates
x = r .* cos(theta_rad);
y = r .* sin(theta_rad);
% Plot the phase portrait
figure;
quiver(x, y, cos(theta_rad), sin(theta_rad));
xlabel('x');
ylabel('y');
title('Phase Portrait');
axis equal;
% Plot the trajectory
figure;
plot(x, y);
xlabel('x');
ylabel('y');
title('Trajectory');
axis equal;
You can adjust the parameters and initial conditions according to your specific system, and further customize the plots as needed.
Please find links to below documentation which I believe will help you for further reference.
  1 comentario
Sam Chak
Sam Chak el 13 de Sept. de 2023
@Yash Sharma, are you sure that you understand that Zixuan wants to plot the phase portrait and trajectory, similar to your example? If not, please fix the mathematics in your example.
% Define the parameters of the system
alpha = 0.5; % Parameter for r dynamics
beta = 0.1; % Parameter for theta dynamics
% Define the time span for simulation
tspan = 0:0.1:10;
% Define the initial conditions
r0 = 1; % Initial r value
theta0 = 0; % Initial theta value
% Define the ODE system in polar coordinates
odefun = @(t, y) [alpha * y(1); beta];
% Solve the ODE system
[t, y] = ode45(odefun, tspan, [r0; theta0]);
% Extract the r and theta values
r = y(:, 1);
theta = y(:, 2);
% Convert theta to radians
theta_rad = deg2rad(theta);
% Compute the x and y coordinates
x = r .* cos(theta_rad);
y = r .* sin(theta_rad);
% Plot the phase portrait
figure;
quiver(x, y, cos(theta_rad), sin(theta_rad));
xlabel('x');
ylabel('y');
title('Phase Portrait');
axis equal;
% Plot the trajectory
figure;
plot(x, y);
xlabel('x');
ylabel('y');
title('Trajectory');
axis equal;

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by