필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Zixuan
Zixuan 2022년 10월 5일
댓글: Sam Chak 2023년 9월 13일
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

답변 (1개)

Yash Sharma
Yash Sharma 2023년 9월 13일
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
Sam Chak
Sam Chak 2023년 9월 13일
@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;

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Assembly에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by