Effacer les filtres
Effacer les filtres

Plot 3D figure

2 vues (au cours des 30 derniers jours)
Tina Hsiao
Tina Hsiao le 11 Nov 2021
Commenté : Walter Roberson le 12 Nov 2021
Hello, I would like to plot this fugure (ro, Z, I), my code as below, could you please give me a help? Thanks a lot.
clear all; close all; clc
for n = 1:1:100
i = sqrt(-1);
a = 0.62;
NA = 0.29;
wL = 772e-3; % micro meter
R = linspace (-0.4,0.4,100);
ro = ((2*pi)/wL)*NA.*R;
Z = linspace(-1,1,100);
mu = ((2*pi)/wL)*NA^2*Z;
fun1 = @(r)r.*exp(-r.^2).* besselj(ro(n),r) .*exp(-(1.*i.*mu(n).*r.^2)./2);
q1 = integral(fun1,0,1);
q2 = integral(fun1,0,a);
E(n) = (2/(1-exp(-1)))*q1- 2*(2/(1-exp(-1)))*q2; % electric field
I(n) = abs(E(n)).^2; % intensity
end
figure(2)
plot(R, I)

Réponse acceptée

Walter Roberson
Walter Roberson le 11 Nov 2021
The scale factor between and Z or R values is not obvious. It is also not obvious why you used the ranges you did: the sample plot suggests that they should be reversed. However, I had to use those ranges to get any plot of note -- and you can see it is not the expected plot. The output was essentially unchanged with Z -- which suggests that possibly Z is the wrong scale.
a = 0.62;
NA = 0.29;
wL = 772e-3; % micro meter
num_R = 100;
num_Z = 101;
Zvals = linspace(-5,5,num_Z)/1e2;
Rvals = linspace(-40,40,num_R)/1e2;
for Ridx = 1 : num_R
R = Rvals(Ridx);
ro = ((2*pi)/wL)*NA.*R;
for Zidx = 1 : num_Z
Z = Zvals(Zidx);
mu = ((2*pi)/wL)*NA^2*Z;
fun1 = @(r)r .* exp(-r.^2) .* besselj(ro,r) .* exp(-(1.*i.*mu.*r.^2)./2);
q1 = integral(fun1,0,1);
q2 = integral(fun1,0,a);
E(Ridx, Zidx) = (2/(1-exp(-1)))*q1 - 2*(2/(1-exp(-1)))*q2; % electric field
end
end
I = abs(E).^2; % intensity
figure(2)
surf(Zvals, Rvals, I, 'edgecolor', 'none')
  2 commentaires
Tina Hsiao
Tina Hsiao le 12 Nov 2021
Thanks a lot. It works.
clear all; close all; clc
NA = 0.29;
wL = 772e-3; % micro meter
num_Z = 100;
num_R = 100;
Zvals= linspace(-40,40,num_Z);
Rvals = linspace(-5,5,num_R);
for Zidx = 1 : num_Z
Z = (Zvals(Zidx));
mu = ((2*pi)/wL).*NA^2.*Z;
for Ridx = 1 : num_R
R = (Rvals(Ridx));
ro = ((2*pi)/wL)*NA.*R;
fun1 = @(r)r.* exp(-r.^2) .* besselj(0,ro*r).* exp(-(1.*i.*mu.*r.^2)./2);
fun2 = @(a)a.* exp(-a.^2) .* besselj(0,ro*a).* exp(-(1.*i.*mu.*a.^2)./2);
q1 = integral(fun1,0,1);
q2 = integral(fun2,0,0.62);
E(Ridx, Zidx) = (2/(1-exp(-1))).*q1 - 2*(2/(1-exp(-1))).*q2; % electric field
end
end
phase = atan2(imag(E),real(E));
I = abs(E).^2; % intensity
figure(2)
surf( Rvals, Zvals, I/max(max(I)), 'edgecolor', 'none')
Walter Roberson
Walter Roberson le 12 Nov 2021
Looks good, but what do you do with phase after you calculate it?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by