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

조회 수: 3 (최근 30일)
savitha muthanna
savitha muthanna 2021년 9월 10일
편집: Ayush 2024년 4월 4일
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

답변 (1개)

Ayush
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;

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by