Effacer les filtres
Effacer les filtres

How do I plot the Hamiltonian (phase plot) of a 2d system

9 vues (au cours des 30 derniers jours)
savitha muthanna
savitha muthanna le 10 Sep 2021
Modifié(e) : Ayush le 4 Avr 2024
Hi
I have the Hamiltonian H(p,q). Both p and q are two dimensional arrays of size say (2,N). How do I plot q vs p? (p is derivative of q, but that I think is not important).
Thank you
Savitha

Réponses (1)

Ayush
Ayush le 4 Avr 2024
Modifié(e) : Ayush le 4 Avr 2024
Hi,
It seems you want to plot 2D arrays, where (p) and (q) are both two-dimensional arrays of size (2, N), implying you have two sets of data points to plot against each other. To do so, refer to an example implementation below for a better understanding:
% Number of data points
N = 100;
% Generate sample data for p and q
% Assuming p and q vary linearly for demonstration
% p = [p1; p2] and q = [q1; q2] where p1, p2, q1, q2 are 1xN arrays
p = [linspace(0, 10, N); linspace(5, 15, N)];
q = [linspace(0, 20, N); linspace(10, 30, N)];
% Plotting
figure; % Opens a new figure window
% Plot for first set of variables
subplot(1,2,1); % Subplot 1
plot(p(1,:), q(1,:), 'r-'); % Plots q1 vs p1 with red line
xlabel('p1');
ylabel('q1');
title('Plot of q1 vs p1');
grid on; % Adds grid for better visualization
% Plot for second set of variables
subplot(1,2,2); % Subplot 2
plot(p(2,:), q(2,:), 'b-'); % Plots q2 vs p2 with blue line
xlabel('p2');
ylabel('q2');
title('Plot of q2 vs p2');
grid on;

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by