Need help on Phase Diagram

26 visualizzazioni (ultimi 30 giorni)
Atikur
Atikur il 21 Ott 2024
Commentato: Atikur il 30 Ott 2024 alle 6:53
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?

Risposta accettata

Rahul
Rahul il 21 Ott 2024
Modificato: Rahul il 21 Ott 2024
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 Commenti
Rahul
Rahul il 30 Ott 2024 alle 5:46
Hi @Atikur, I'm unsure of what you are referring to as "directions of the phase diagram", can you describe it further?
Atikur
Atikur il 30 Ott 2024 alle 6:53
The arrow sign to show on which direction its moving?

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by