How do I plot the Hamiltonian (phase plot) of a 2d system
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
Ayush
el 4 de Abr. de 2024
Editada: Ayush
el 4 de Abr. de 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;
0 comentarios
Ver también
Categorías
Más información sobre Line Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!