How can plot with this specific option design? and if possible be better?
Ältere Kommentare anzeigen
i want plot my phase portrait with this option and better of this if have any design please upload it
%% LGH Phase Portrait (Unperturbed) - Eq.(38) of the paper
% dU/dxi = phi
% dphi/dxi = (alpha^2*U - beta*U^3)/(1 - eps^2)
% First integral (Hamiltonian) Eq.(39) used for level curves.
clear; clc; close all;
%% Parameters (change these)
alpha = 1; % alpha (paper uses alpha as parameter)
beta = 1; % beta
epsi = 0.5; % epsilon (NOTE: avoid epsi^2 = 1)
den = (1 - epsi^2);
if abs(den) < 1e-12
error('Choose epsilon such that 1 - epsilon^2 ~= 0');
end
%% Phase-plane grid
Umin = -3; Umax = 3;
Pmin = -3; Pmax = 3; % P stands for phi
n = 35;
[U, P] = meshgrid(linspace(Umin,Umax,n), linspace(Pmin,Pmax,n));
dU = P;
dP = (alpha^2.*U - beta.*U.^3)/den;
%% Plot vector field (quiver) + streamlines
figure('Color','w'); hold on; box on;
quiver(U, P, dU, dP, 'AutoScale','on');
xlabel('U(\xi)'); ylabel('\phi(\xi)');
title('LGH Phase Portrait (Unperturbed)');
% Streamlines (optional but nice)
startU = linspace(Umin,Umax,10);
startP = linspace(Pmin,Pmax,10);
[sU, sP] = meshgrid(startU, startP);
streamline(U, P, dU, dP, sU(:), sP(:));
%% Equilibrium points from the paper
% E1=(0,0), E2=(sqrt(alpha/beta),0), E3=(-sqrt(alpha/beta),0) (for beta>0)
plot(0,0,'ko','MarkerFaceColor','k','MarkerSize',6);
if beta > 0 && alpha/beta > 0
ueq = sqrt(alpha/beta);
plot( ueq, 0,'ko','MarkerFaceColor','k','MarkerSize',6);
plot(-ueq, 0,'ko','MarkerFaceColor','k','MarkerSize',6);
end
%% Hamiltonian level curves (Eq. 39) to mimic the paper portraits
% H(U,phi) = phi^2/2 + beta*U^4/(4(1-eps^2)) - alpha^2*U^2/(2(1-eps^2)) + alpha^4/(4*beta*(1-eps^2)) = h
% (The constant shift does not change the shape; still we include it.)
H = 0.5*P.^2 + (beta.*U.^4)./(4*den) - (alpha^2.*U.^2)./(2*den) + (alpha^4)./(4*beta*den);
% Choose energy levels (you can edit these)
levels = [-2 -1 -0.5 0 0.5 1 2];
contour(U, P, H, levels, 'LineWidth', 1.2);
axis([Umin Umax Pmin Pmax]);
grid on;
hold off;
%% Example trajectories using ode45
% Provide some initial conditions and integrate forward/backward in xi
figure('Color','w'); hold on; box on;
contour(U, P, H, levels, 'LineWidth', 1.2);
xlabel('U(\xi)'); ylabel('\phi(\xi)');
title('Trajectories on Hamiltonian Level Curves');
f = @(xi,y) [ y(2);
(alpha^2*y(1) - beta*y(1)^3)/den ];
xiSpanF = [0 50];
xiSpanB = [0 -50];
ICs = [ -2 0.5;
-1 1.5;
1 1.0;
2 -0.5 ];
for k = 1:size(ICs,1)
y0 = ICs(k,:)';
[~,Yf] = ode45(f, xiSpanF, y0);
[~,Yb] = ode45(f, xiSpanB, y0);
plot(Yf(:,1), Yf(:,2), 'LineWidth', 1.5);
plot(Yb(:,1), Yb(:,2), 'LineWidth', 1.5);
end
plot(0,0,'ko','MarkerFaceColor','k','MarkerSize',6);
if beta > 0 && alpha/beta > 0
ueq = sqrt(alpha/beta);
plot( ueq, 0,'ko','MarkerFaceColor','k','MarkerSize',6);
plot(-ueq, 0,'ko','MarkerFaceColor','k','MarkerSize',6);
end
axis([Umin Umax Pmin Pmax]);
grid on;
hold off;


3 Kommentare
dpb
am 27 Jan. 2026
..."with this option..."
You neglected to tell us what "specific option" is...
If you nean to replicate the posted figure from the paper, it looks as though all that would be would be to use
subplot(1,3,i)
for i=1:3, creating each in turn.
salim
am 27 Jan. 2026
Star Strider
am 27 Jan. 2026
Isn't it already a phase portrait? (Am I missing something?)
Antworten (0)
Kategorien
Mehr zu Vector Fields finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

