i have x and y which are matrices
i perform operations to get U which is a coulmn vector how do i plot it agaisnt x,y which are matices. the erro i get is that z must be a matrix not scalor or vector
x=-(ngrid/2:ngrid/2-1)*0.2
[X,Y] = meshgrid(x,x)
u%outputs coulmn vectors
my output U from my workspace is a coulu vector of 1x2001

7 commentaires

Cris LaPierre
Cris LaPierre le 28 Mai 2021
How does U relate to x and y?
Tlotlo Oepeng
Tlotlo Oepeng le 28 Mai 2021
Modifié(e) : Tlotlo Oepeng le 28 Mai 2021
u is a wave travelling on the xy plane, after a series of analytical computations i get an output coordnatres of u
Walter Roberson
Walter Roberson le 28 Mai 2021
u is complex-valued . If you plot real(u) against imag(u) it will fill an ellipse that has a ratio of about 10 : 6.4
In order to plot in three dimensions, you would need to be able to relate individual X and Y values to individual uCopy values.
Tlotlo Oepeng
Tlotlo Oepeng le 28 Mai 2021
ussually we use mesh(x,y,abs(U).^2) to plot in this case it gives error
'U must be matrix"
heres the code
%% -- Initialize variabels --
delta = 0.4; % linear-loss coefficient
epsilon = 2.2; % cubic-gain coefficient
mu = 1; % quintic-loss parameter
v = 0.1; % accounts for the quintic self-defocusing quantic nonlinearity
beta = 0.5; % diffussivity term
D = 1; % group-velocity dispersion
gamma = 0; % accounts for the dispersion of the linear loss...
%% -- Define of Parameters --
ngrid = 2001; % number of grid
dt = 0.1; % change of time t
tmax = 200; % the maximum of time t
dx = 0.2; % step size in x
dy = 0.2; % step size in y
L = 50; % lenght of logitudinal space
ind = (-ngrid/2:ngrid/2-1); % Indices
t = 0:dt:tmax; % temporal Grid
kt = (2*pi/tmax)*[(0:ngrid/2) (-ngrid/2:-1)]; % temporal Grid in new domain using fftshift(so that wavw numbers correspond to
%variables..)
x = ind*dx; % Grid point along x
y = ind*dy; % Grid point along y
kx = (2*pi/L)*[(0:ngrid/2) (-ngrid/2:-1)]; % Grid point along x in new domain using fft
ky = (2*pi/L)*[(0:ngrid/2) (-ngrid/2:-1)];
[X,Y] = meshgrid(x,x)% Grid point along y in new domain using fft
%% -- ansatz--
U = exp(-0.5.*x.^2-0.5.*y.^2-0.5.*t.^2);
%% -- Function Handles for RK4 Scheme--
fU = @(U,z) (-delta+(i+epsilon).*(abs(U).^2).*U+(mu-i*v).*(abs(U).^4).*U);
%% -- Initial Conditions --
z(1) = 0;
%% -- Step Size --
dz = 0.1; % change of z
h = dz/2; % step size in z
zfinal = 100; % final of z
%% -- Update Loop --
for i = 1:ceil(zfinal/h)
% update time
z(i+1) = z(i) + h;
% update R & J
k1 = fU( z(i) , U(i) ); % first slope
k2 = fU( z(i)+h/2 , U(i)+h/2*k1 ); % second slope
k3 = fU( z(i)+h/2 , U(i)+h/2*k2 ); % third slope
k4 = fU( z(i)+h , U(i)+h*k3 ); % fourth slope
U(i+1) = U(i) + h/6*(k1+2*k2+2*k3+k4);
end
%% -- Fourier Transform --
for z=1:zfinal
u = U;
c = fftshift(fft(u)); % apply Fourier transform
c = exp(-h*((0.5*i+beta)*(kx.^2+ky.^2)+(0.5*i*D-gamma)*kt.^2)).*c; % multiply by e^D
u = ifft(fftshift(c)); % inverse Fourier
end
%% -- Plot --
figure (1);
mesh (x,y,abs(u').^2);
U = exp(-0.5.*x.^2-0.5.*y.^2-0.5.*t.^2);
You need to rewrite U in terms of X and Y instead of x and y . But X and Y are 2D and probably not the same size as t, so you would need to reshape t into the third dimension, or
[X, Y, T] = meshgrid(x, x, t);
U = exp(-0.5.*X.^2-0.5.*Y.^2-0.5.*T.^2);
But now U will be 3D and you need to summarize it down to 2D in order to use a surface plot.
k1 = fU( z(i) , U(i) ); % first slope
That whole section would need to be rewritten in terms of U being 3D.
Tlotlo Oepeng
Tlotlo Oepeng le 29 Mai 2021
thank you ill try to di that
how do i accept answer?

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 29 Mai 2021
[Copied from comment]
U = exp(-0.5.*x.^2-0.5.*y.^2-0.5.*t.^2);
You need to rewrite U in terms of X and Y instead of x and y . But X and Y are 2D and probably not the same size as t, so you would need to reshape t into the third dimension, or
[X, Y, T] = meshgrid(x, x, t);
U = exp(-0.5.*X.^2-0.5.*Y.^2-0.5.*T.^2);
But now U will be 3D and you need to summarize it down to 2D in order to use a surface plot.
k1 = fU( z(i) , U(i) ); % first slope
That whole section would need to be rewritten in terms of U being 3D.

Plus de réponses (0)

Catégories

En savoir plus sur Data Distribution Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by