i encounter an error while trying to plot the following contour
x=0:0.1:4;
x1=-pi:0.001*pi:pi;
y1=(100*sqrt(2*pi)./sqrt(x.*2*pi)).*cos(x1/2).*(1.-sin(x1/2.).*sin(3.*x1/2.));
y2=(100*sqrt(2*pi)./sqrt(x.*2*pi)).*cos(x1/2).*(1.+sin(x1/2.).*sin(3.*x1/2.));
y3=(100*sqrt(2*pi)./sqrt(x.*2*pi)).*cos(x1/2).*sin(x1/2.).*sin(3.*x1/2.);
y4=(1/2).*((y1-y2)^2+y1^2+y2^2+6.*y3^2);
z=abs(sqrt(y4));
[x,x1]=meshgrid(x,x1);
% contour(x,x1,z)
contour(real(z))

 Respuesta aceptada

Walter Roberson
Walter Roberson el 1 de Mzo. de 2022
x = (0:0.1:4).';
x1=-pi:0.001*pi:pi;
y1=(100*sqrt(2*pi)./sqrt(x.*2*pi)).*cos(x1/2).*(1.-sin(x1/2.).*sin(3.*x1/2.));
y2=(100*sqrt(2*pi)./sqrt(x.*2*pi)).*cos(x1/2).*(1.+sin(x1/2.).*sin(3.*x1/2.));
y3=(100*sqrt(2*pi)./sqrt(x.*2*pi)).*cos(x1/2).*sin(x1/2.).*sin(3.*x1/2.);
y4 = (1/2).*((y1-y2).^2+y1.^2+y2.^2+6.*y3);
z = sqrt(y4);
[x,y]=meshgrid(x1,x);
% contour(x,x1,z)
contour(x, y, real(z))

5 comentarios

x = (0:0.1:4).';
x1=-pi:0.001*pi:pi;
x2=x.*cos(x1);
x3=x.*sin(x1);
y1=(100*sqrt(2*pi)./sqrt(x.*2*pi)).*cos(x1/2).*(1.-sin(x1/2.).*sin(3.*x1/2.));
y2=(100*sqrt(2*pi)./sqrt(x.*2*pi)).*cos(x1/2).*(1.+sin(x1/2.).*sin(3.*x1/2.));
y3=(100*sqrt(2*pi)./sqrt(x.*2*pi)).*cos(x1/2).*sin(x1/2.).*sin(3.*x1/2.);
y4 = (1/2).*((y1-y2).^2+y1.^2+y2.^2+6.*y3.^2);
z = sqrt(y4);
[x,y]=meshgrid(x2,x3);
Error using repmat
Requested 82041x82041 (50.1GB) array exceeds maximum array size preference (30.9GB). This might cause MATLAB to become unresponsive.

Error in meshgrid (line 61)
xx = repmat(xrow,size(ycol));
% contour(x2,x3,z)
contour(x, y, real(z),'ShowText','on')
what is the error in this code
i want to plot contours in x, y not r and Theta
Walter Roberson
Walter Roberson el 1 de Mzo. de 2022
Editada: Walter Roberson el 29 de Abr. de 2025
x = (0:0.1:4).';
x1=-pi:0.001*pi:pi;
x2=x.*cos(x1);
x3=x.*sin(x1);
whos
Name Size Bytes Class Attributes x 41x1 328 double x1 1x2001 16008 double x2 41x2001 656328 double x3 41x2001 656328 double
Notice your x2 and x3 are 41 x 2001, not vectors. You are combining a vector of length 41 with a vector of length 2001. In order to get a vector result, you would need to reduce along a dimension (such as min or sum) to get either 41 x 1 or 1 x 2001.
[x,y]=meshgrid(x2,x3);
There you are asking to use the 41x2001 array x2 in combination with each 41x2001 x3 value, which is 82041 x 82041 requested, which is too big for your system.
i want to plot contours in x, y not r and Theta
x1 is plausibly an angle, maybe even Theta; why not name it Theta instead of x1 ?
x is... we don't know? Is that your r?
khaled Abdelghafar
khaled Abdelghafar el 1 de Mzo. de 2022
yes r is x
theta is x1
khaled Abdelghafar
khaled Abdelghafar el 1 de Mzo. de 2022
i would changed to r and theta
the question how i plot the contour in x,y not r and thata
how could i do it
Walter Roberson
Walter Roberson el 1 de Mzo. de 2022
You do not need to construct x2 and x3 for that contribution.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Contour Plots en Centro de ayuda y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by