How to plot contour plot of a function?

1 次查看(过去 30 天)
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 个评论
Star Strider
Star Strider 2022-8-8
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')
.

请先登录,再进行评论。

回答(1 个)

Cris LaPierre
Cris LaPierre 2022-8-8
编辑:Cris LaPierre 2022-8-8
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

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by