How to plot contour plot of a function?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Star Strider
le 8 Août 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')
.
Réponses (1)
Cris LaPierre
le 8 Août 2022
Modifié(e) : Cris LaPierre
le 8 Août 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 commentaires
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!