How to plot contour plot of a function?

1 visualización (últimos 30 días)
Athira T Das
Athira T Das el 8 de Ag. de 2022
Comentada: Star Strider el 8 de Ag. de 2022
I have a function I and need to plot this function as a contour plot, like
Anyone please help, where x and y ranges from -0.1 to 0.1
clc; clear all; close all;
syms x y
lambda = 1060*10^-9;
M =1;
z=100;
k=2*pi/lambda;
b=0.1;
wo=0.02;
delta=(1i*k)/(2*z);
A = ((k.^2)-(4.*z.^2.*delta));
B = ((1i.*k.*b)./(2.*z.*wo.*delta));
C = ((b.^2)./(4.*wo.^2.*delta));
f1=(k/(2*z)).^2;
f2=(1/(2.*1i.*sqrt(delta))).^M;
f3=exp((A.*x.^2)+(B.*x)+C);
f4=exp((A.*y.^2)+(B.*y)+C);
I=f1.*f2.*f3.*f4
I = 
  1 comentario
Star Strider
Star Strider el 8 de Ag. de 2022
I am not certain what the problem is, however even with a relatively high mesh density, there is no detail that would suggest something similar to the posted image.
syms x y
lambda = 1060E-9;
M =1;
z=100;
k=2*pi/lambda;
b=0.1;
wo=0.02;
delta=(1i*k)/(2*z);
A = ((k.^2)-(4.*z.^2.*delta));
B = ((1i.*k.*b)./(2.*z.*wo.*delta));
C = ((b.^2)./(4.*wo.^2.*delta));
f1=(k/(2*z)).^2;
f2=(1/(2.*1i.*sqrt(delta))).^M;
f3=exp((A.*x.^2)+(B.*x)+C);
f4=exp((A.*y.^2)+(B.*y)+C);
I(x,y)=f1.*f2.*f3.*f4 % Create 'I' As A Funciton Of '(x,y)'
I(x, y) = 
figure
fcontour(real(I), [-1 1 -1 1]*5E-6, 'Fill','on', 'MeshDensity',150)
colormap(turbo)
axis('equal')
figure
fsurf(real(I), [-1 1 -1 1]*5E-6, 'MeshDensity',150)
colormap(turbo)
% axis('equal')
.

Iniciar sesión para comentar.

Respuestas (1)

Cris LaPierre
Cris LaPierre el 8 de Ag. de 2022
Editada: Cris LaPierre el 8 de Ag. de 2022
I would use meshgrid to create the arrays x and y, and then use those to calculate I without symbolic variables.
However, in doing so, I is inf everywhere except (0,0). You may want to double check your equations.
[x,y] = meshgrid(linspace(-0.1,0.1,21));
lambda = 1060*10^-9;
M =1;
z=100;
k=2*pi/lambda;
b=0.1;
wo=0.02;
delta=(1i*k)/(2*z);
A = ((k.^2)-(4.*z.^2.*delta));
B = ((1i.*k.*b)./(2.*z.*wo.*delta));
C = ((b.^2)./(4.*wo.^2.*delta));
f1=(k/(2*z)).^2;
f2=(1/(2.*1i.*sqrt(delta))).^M;
f3=exp((A.*x.^2)+(B.*x)+C);
f4=exp((A.*y.^2)+(B.*y)+C);
I=f1.*f2.*f3.*f4
I =
1.0e+06 * Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi -Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi -Inf - Infi -Inf + Infi Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi -Inf - Infi Inf - Infi Inf + Infi -Inf - Infi -Inf + Infi Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf + Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi Inf + Infi -Inf - Infi -Inf + Infi Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi -Inf - Infi Inf - Infi Inf + Infi -Inf - Infi -Inf + Infi Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi -Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi Inf + Infi Inf - Infi -Inf - Infi -Inf - Infi Inf - Infi Inf + Infi -Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf + Infi -Inf + Infi -Inf - Infi Inf + Infi Inf - Infi -Inf - Infi -Inf - Infi Inf - Infi Inf + Infi -Inf - Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi -Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi -Inf - Infi -Inf + Infi Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf + Infi Inf - Infi -Inf - Infi -1.8047 - 1.8032i -Inf - Infi Inf - Infi Inf + Infi -Inf - Infi -Inf + Infi Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi -Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi -Inf - Infi Inf + Infi Inf - Infi -Inf - Infi -Inf - Infi Inf - Infi Inf + Infi -Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf + Infi -Inf + Infi -Inf - Infi Inf + Infi Inf - Infi -Inf - Infi -Inf - Infi Inf - Infi Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi -Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi -Inf - Infi -Inf + Infi Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi -Inf - Infi Inf - Infi Inf + Infi -Inf - Infi -Inf + Infi Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf + Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi Inf + Infi -Inf - Infi -Inf + Infi Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi -Inf - Infi Inf - Infi Inf + Infi -Inf - Infi -Inf + Infi Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi -Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi -Inf - Infi -Inf + Infi Inf + Infi -Inf + Infi -Inf - Infi Inf - Infi -Inf + Infi Inf + Infi Inf - Infi Inf - Infi Inf + Infi -Inf + Infi Inf - Infi
contourf(real(I))
Warning: Contour not rendered for constant ZData

Categorías

Más información sobre Contour Plots en Help Center 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