How do I plot the Hamiltonian (phase plot) of a 2d system
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Ayush
2024-4-4
编辑:Ayush
2024-4-4
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!