How to plot contour plot of a function?
1 view (last 30 days)
Show older comments
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
1 Comment
Star Strider
on 8 Aug 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)'
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')
.
Answers (1)
Cris LaPierre
on 8 Aug 2022
Edited: Cris LaPierre
on 8 Aug 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
contourf(real(I))
0 Comments
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!