Need help on Phase Diagram

13 visualizaciones (últimos 30 días)
Atikur
Atikur el 21 de Oct. de 2024
Comentada: Atikur el 30 de Oct. de 2024
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?

Respuesta aceptada

Rahul
Rahul el 21 de Oct. de 2024
Editada: Rahul el 21 de Oct. de 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 comentarios
Rahul
Rahul el 30 de Oct. de 2024
Hi @Atikur, I'm unsure of what you are referring to as "directions of the phase diagram", can you describe it further?
Atikur
Atikur el 30 de Oct. de 2024
The arrow sign to show on which direction its moving?

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by