Need help on Phase Diagram

9 ビュー (過去 30 日間)
Atikur
Atikur 2024 年 10 月 21 日
コメント済み: Atikur 2024 年 10 月 30 日
I am new on Matlab. For my undergrad thesis I need to show a phase diagram.
I did this part.
% discrete_model_one_variable
% x(t) = a*x(t-1)
%======================================================
a = 0.92;
b = 0.021;
x = zeros(1,100);
x(1) = 0.36;
for t = 2:100
x(t) = a*x(t-1)+ b;
end
plot(1:100, x)
But I need a phase diagram. For refernece I am attaching a screenshot what I want.
Can you please guide me how can I get the phase diagram?

採用された回答

Rahul
Rahul 2024 年 10 月 21 日
編集済み: Rahul 2024 年 10 月 21 日
Hi @Atikur,
Assuming you are trying to plot a phase diagram of the given single variable ‘x’ as a discrete function, along with a 45-degree reference line on the same figure, you can plot delayed signal ‘x(t-1)’ ranging from ‘t’ = (1, 99) and the original signal ‘x(t)’ in ‘t’ range of (2, 100).
Here's an updated version of your code that will generate a phase diagram:
% discrete_model_one_variable
% x(t) = a*x(t-1)
%======================================================
a = 0.92;
b = 0.021;
x = zeros(1, 100);
x(1) = 0.36;
% Iterate over time
for t = 2:100
x(t) = a * x(t-1) + b;
end
% Manually add a point near the origin
% x = [0, x]; % Add an artificial point (x = 0) for visual extrapolation
% Plot phase diagram x(t) vs x(t-1)
figure;
plot(x(1:end-1), x(2:end), 'k-', 'LineWidth', 1.5); % Plot x(t) against x(t-1)
hold on;
% Plot the 45-degree line (x(t) = x(t-1))
plot([0, max(x)], [0, max(x)], 'k--', 'LineWidth', 1); % 45-degree line
xlabel('x(t-1)');
ylabel('x(t)');
legend({'Phase Diagram'; 'Reference 45 deg line'})
title('Phase Diagram of Discrete Model with Extrapolation');
axis equal;
grid on;
  • The line plot plot(x(1:99), x(2:100), 'k-', 'LineWidth', 1.5) plots x(t) against x(t-1), which creates the phase diagram.
  • The line plot plot([min(x), max(x)], [min(x), max(x)], 'k--', 'LineWidth', 1) adds the 45-degree line (which represents where x(t) = x(t-1)), from the origin to the max value of 'x(t)'.
I've set the plot to use solid lines ('k-') for the phase diagram and dashed lines ('k--') for the 45-degree line, with appropriate ‘linewidth values to make the graph clearer.
For more information regarding functions and parameters mentioned above, refer to the following documentation links:
  3 件のコメント
Rahul
Rahul 2024 年 10 月 30 日
Hi @Atikur, I'm unsure of what you are referring to as "directions of the phase diagram", can you describe it further?
Atikur
Atikur 2024 年 10 月 30 日
The arrow sign to show on which direction its moving?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by